-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37670fc
commit d5f14b3
Showing
21 changed files
with
394 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,8 @@ class LookupResult { | |
this.parts = parts; | ||
this.found = found; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
src/main/java/liqp/filters/date/fuzzy/extractors/FullMonthExtractor.java
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
src/main/java/liqp/filters/date/fuzzy/extractors/MonthDateExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package liqp.filters.date.fuzzy.extractors; | ||
|
||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import liqp.filters.date.fuzzy.Part; | ||
import liqp.filters.date.fuzzy.Part.RecognizedMonthNamePart; | ||
import liqp.filters.date.fuzzy.Part.RecognizedPart; | ||
import liqp.filters.date.fuzzy.PartExtractor; | ||
|
||
public class MonthDateExtractor implements PartExtractor { | ||
|
||
@Override | ||
public PartExtractorResult extract(String source, List<Part> parts, int i) { | ||
// closest right or closest left should be a month | ||
if (rightIsMonth(parts, i)) { | ||
return leftDateExtractor.extract(source, parts, i); | ||
} | ||
if (leftIsMonth(parts, i)) { | ||
return rightDateExtractor.extract(source, parts, i); | ||
} | ||
return new PartExtractorResult("MonthDateExtractor"); | ||
} | ||
|
||
private boolean leftIsMonth(List<Part> parts, int i) { | ||
int left = i - 1; | ||
while (left >= 0) { | ||
Part part = parts.get(left); | ||
if (part instanceof RecognizedMonthNamePart) { | ||
return true; | ||
} | ||
if (part instanceof RecognizedPart) { | ||
return false; | ||
} | ||
left--; | ||
} | ||
return false; | ||
} | ||
|
||
private boolean rightIsMonth(List<Part> parts, int i) { | ||
int right = i + 1; | ||
while (right < parts.size()) { | ||
Part part = parts.get(right); | ||
if (part instanceof RecognizedMonthNamePart) { | ||
return true; | ||
} | ||
if (part instanceof RecognizedPart) { | ||
return false; | ||
} | ||
right++; | ||
} | ||
return false; | ||
} | ||
|
||
|
||
private static final RegexPartExtractor leftDateExtractor = new MonthDatePartExtractor("MonthDayExtractor.left", "(?:^|.*?\\D)(?<day>0?[1-9]|[12][0-9]|3[01])\\D+?$"); | ||
private static final RegexPartExtractor rightDateExtractor = new MonthDatePartExtractor("MonthDayExtractor.right", "^\\D+?(?<day>0?[1-9]|[12][0-9]|3[01])(?:$|\\D.*?)"); | ||
private static class MonthDatePartExtractor extends RegexPartExtractor { | ||
|
||
public MonthDatePartExtractor(String name, String regex) { | ||
super(name, regex, null); | ||
} | ||
|
||
@Override | ||
public PartExtractorResult extract(String source, List<Part> parts, int i) { | ||
Matcher matcher = pattern.matcher(source); | ||
if (matcher.find()) { | ||
PartExtractorResult result = new PartExtractorResult(name); | ||
result.found = true; | ||
result.start = matcher.start("day"); | ||
result.end = matcher.end("day"); | ||
if (matcher.group("day").length() == 1) { | ||
result.formatterPatterns = newList("d", "dd"); | ||
} else { | ||
result.formatterPatterns = newList("dd", "d"); | ||
} | ||
return result; | ||
} | ||
return new PartExtractorResult(name); | ||
} | ||
} | ||
} |
Oops, something went wrong.