Repository navigation
Implement Regex::source_and_options_equals
#1351
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,6 +101,7 @@ use crate::{error::Error, RegexBuilder}; | |
| pub struct Regex { | ||
| pub(crate) meta: meta::Regex, | ||
| pub(crate) pattern: Arc<str>, | ||
| pub(crate) syntaxc: Arc<regex_automata::util::syntax::Config>, | ||
| } | ||
|
|
||
| impl core::fmt::Display for Regex { | ||
|
|
@@ -1276,6 +1277,31 @@ impl Regex { | |
| &self.pattern | ||
| } | ||
|
|
||
| /// Compares the source strings and compile options of two regexes, | ||
|
dolezvo1 marked this conversation as resolved.
Outdated
|
||
| /// returning true iff both are equal. | ||
| /// Such result implies equivalence of the regexes, but the contrary | ||
| /// provides no information about their equivalence. | ||
| /// | ||
| /// # Example | ||
| /// | ||
| /// ``` | ||
| /// use regex::{Regex, RegexBuilder}; | ||
| /// | ||
| /// let r1 = Regex::new(r"a+").unwrap(); | ||
| /// let r2 = Regex::new(r"aa*").unwrap(); | ||
| /// assert!(!r1.source_and_options_equals(&r2)); | ||
| /// | ||
| /// let r3 = RegexBuilder::new(r"a+") | ||
| /// .case_insensitive(true) | ||
| /// .build() | ||
| /// .unwrap(); | ||
| /// assert!(!r1.source_and_options_equals(&r3)); | ||
| /// ``` | ||
| #[inline] | ||
| pub fn source_and_options_equals(&self, other: &Self) -> bool { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This naming will need work. I don't like how it is right now. But I don't have the spoons to come up with a better one at the moment.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you're right that the name could be improved, but I'm not quite sure how. The
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @BurntSushi Hello, did you happen to have any ideas about a better name? |
||
| self.pattern == other.pattern && self.syntaxc == other.syntaxc | ||
| } | ||
|
|
||
| /// Returns an iterator over the capture names in this regex. | ||
| /// | ||
| /// The iterator returned yields elements of type `Option<&str>`. That is, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.