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

Add support for unicode properties in pattern, etc. #112

Merged
merged 1 commit into from
Dec 14, 2021

Conversation

nalundgaard
Copy link
Contributor

Resolves #104.

Adds support for unicode properties "pattern" and "patternProperties" by adding re_options to the jesse application environment and making all uses of re:run/2 consult it. This effectively changes the previously hard-coded unicode option to ucp, but allows restoring the previous behavior (for better performance) by setting re_options to [unicode] instead of [ucp].

@nalundgaard
Copy link
Contributor Author

I forgot about this for quite awhile, but noticed it in my queue today and took a stab. Please let me know if this will work.

Copy link
Collaborator

@seriyps seriyps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

%% {@link https://www.erlang.org/doc/man/re.html#compile-2. re:compile/2}
-spec re_options() -> list().
re_options() ->
application:get_env(jesse, re_options, [ucp]).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When ucp is enabled, shouldn't unicode be added explicitly as well? It's a bit not clear from the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right that you need both:

1> re:run(<<"fōô"/utf8>>, "^\\w+$", [{capture, none}, ucp, unicode]).
match
2> re:run(<<"fōô"/utf8>>, "^\\w+$", [{capture, none}, ucp]).
nomatch

I will update the default and docs.

Copy link
Collaborator

@seriyps seriyps Nov 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes me think that it might be nice to have at least some test that showcases this feature

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I will write some eunit tests for these new utility functions.

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! The last commit (388cfa6) should address your concerns and suggestions. Thanks!

Resolves for-GET#104.

Adds support for unicode properties "pattern" and "patternProperties" by adding `re_options` to the `jesse` application environment and making all uses of `re:run/2` consult it. This effectively changes the previously hard-coded `unicode` option to `ucp`, but allows restoring the previous behavior (for better performance) by setting  `re_options` to `[unicode]` instead of `[ucp]`.
@seriyps
Copy link
Collaborator

seriyps commented Nov 6, 2021

LGTM, thanks. Let's see if @andreineculau have any opinions

@seriyps
Copy link
Collaborator

seriyps commented Dec 10, 2021

I'll merge it on Tuesday 14th, if noone objects before that

@seriyps seriyps merged commit e3d10dd into for-GET:master Dec 14, 2021
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.

"pattern" and "patternProperties" do not support unicode properties
2 participants