-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supporting lists of values for anything-but-prefix and anything-but-suffix #143
Conversation
values.add((matchType != MatchType.ANYTHING_BUT_SUFFIX ? "\"" : "") + | ||
text + | ||
(matchType != MatchType.ANYTHING_BUT_PREFIX ? "\"" : "")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thinking long-term, this is an easy place to introduce new bugs with multiple conditions in the same place. Possible to extract this into a method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. It would work for any match type, but for now, I only have these two egregious conditionals calling the new helper.
break; | ||
default: | ||
barf(parser, "Inside anything-but/equals-ignore-case list, number|start|null|boolean is not supported."); | ||
if (matchType == MatchType.ANYTHING_BUT_IGNORE_CASE) { | ||
barf(parser, "Inside anything-but/equals-ignore-case list, number|start|null|boolean is not supported."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be more helpful for debugging if we change this to "Inside anything-but/equals-ignore-case, " + token +" is not supported"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, but this would require changing outward-facing error messages for existing types, which I'd prefer not to do without a strong reason. Also, one benefit to the existing message is it says why the token is not supported. If we just print the token there, it might not be obvious it is of the wrong type.
public static AnythingButValuesSet anythingButPrefix(final Set<String> anythingButs) { | ||
return new AnythingButValuesSet(MatchType.ANYTHING_BUT_PREFIX, anythingButs); | ||
} | ||
|
||
public static AnythingButValuesSet anythingButSuffix(final String suffix) { | ||
return new AnythingButValuesSet(MatchType.ANYTHING_BUT_SUFFIX, | ||
Collections.singleton(new StringBuilder(suffix).reverse().toString())); | ||
} | ||
|
||
public static AnythingButValuesSet anythingButSuffix(final Set<String> anythingButs) { | ||
return new AnythingButValuesSet(MatchType.ANYTHING_BUT_SUFFIX, | ||
anythingButs.stream().map(s -> new StringBuilder(s).reverse().toString()).collect(Collectors.toSet())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these need to be mentioned in README ? in the patterns API section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That section was quite out of date. I've brought it up to date.
Description of changes:
Supporting lists of values for anything-but-prefix and anything-but-suffix. Just like for anything-but-equals-ignore-case.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.