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

RegexBuilder Options Port: Enable Overrides for RaBuilder #132

Merged
merged 10 commits into from
Oct 23, 2024

Conversation

jonperry-dev
Copy link
Contributor

Case Insensitive Builder Feature Port

This is a small add-in to allow for options to be passed in as boolean values and mutate the Config through the RegexBuilder. This is primarily to align with the standard Regex crate for their own RegexBuilder.

Changes

  • Added a field to the RegexOptions to keep a state of regex_automata::utils::syntax::Config internally to disseminate the proper flag overrides
  • Added public method to Regexbuilder called case_insensitive
    - This will allow for forcing of a flag if not present in the raw str
  • Added a call to the RaRegexBuilder which will consume this option using .syntax( ... )
  • Added tests into lib.rs to make sure the override works as intended

Examples

Currently, we can write in flags into the raw string like this:

use fancy_regex::RegexBuilder;

let re = r"(?i)FOO BAR";
let regex = RegexBuilder::new(re).build()?;
assert!(regex.is_match("foo bar").unwrap_or_default());

This change is to enable builder functionality like this:

use fancy_regex::RegexBuilder;

let re = r"FOO BAR";
let regex = RegexBuilder::new(re)
	.case_insensitive(true)
	.build()?;
assert!(regex.is_match("foo bar").unwrap_or_default());

Notes

Currently, fancy-regex doesn't support flags such as (?-i) and that is likely something we should enable in the future. The correlation of that type of flag to this feature add ties to the builder case_insensitive setter method. This method should override any raw input data.

src/compile.rs Show resolved Hide resolved
src/compile.rs Show resolved Hide resolved
@jonperry-dev
Copy link
Contributor Author

@robinst I'm not sure if that coverage failure with line 505 is an issue? I'm not entirely sure what its looking for there.

@robinst
Copy link
Contributor

robinst commented Oct 23, 2024

@robinst I'm not sure if that coverage failure with line 505 is an issue? I'm not entirely sure what its looking for there.

Seems like tarpaulin (the tool we use for coverage) doesn't analyze that correctly. (Maybe bumping the version would help, not sure.)

@robinst robinst merged commit 689a845 into fancy-regex:main Oct 23, 2024
8 of 9 checks passed
@robinst
Copy link
Contributor

robinst commented Oct 23, 2024

Thanks, merged!

@robinst
Copy link
Contributor

robinst commented Oct 24, 2024

Released in 0.14.0: https://github.com/fancy-regex/fancy-regex/blob/main/CHANGELOG.md#0140---2024-10-24

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