Skip to content
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

Merged
merged 3 commits into from
Feb 29, 2024

Conversation

jonessha
Copy link
Contributor

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.

Comment on lines 609 to 611
values.add((matchType != MatchType.ANYTHING_BUT_SUFFIX ? "\"" : "") +
text +
(matchType != MatchType.ANYTHING_BUT_PREFIX ? "\"" : ""));
Copy link
Collaborator

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?

Copy link
Contributor Author

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.");
Copy link
Collaborator

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"

Copy link
Contributor Author

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.

Comment on lines +93 to +104
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()));
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@jonessha jonessha merged commit 3b90aa9 into main Feb 29, 2024
3 checks passed
@jonessha jonessha deleted the anything-but-sets branch February 29, 2024 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants