// Flags for parsing. Can be ORed together.
enum ParseFlags {
- NoParseFlags = 0,
- FoldCase = 1<<0, // Fold case during matching (case-insensitive).
- Literal = 1<<1, // Treat s as literal string instead of a regexp.
- ClassNL = 1<<2, // Allow char classes like [^a-z] and \D and \s
- // and [[:space:]] to match newline.
- DotNL = 1<<3, // Allow . to match newline.
- MatchNL = ClassNL | DotNL,
- OneLine = 1<<4, // Treat ^ and $ as only matching at beginning and
- // end of text, not around embedded newlines.
- // (Perl's default)
- Latin1 = 1<<5, // Regexp and text are in Latin1, not UTF-8.
- NonGreedy = 1<<6, // Repetition operators are non-greedy by default.
- PerlClasses = 1<<7, // Allow Perl character classes like \d.
- PerlB = 1<<8, // Allow Perl's \b and \B.
- PerlX = 1<<9, // Perl extensions:
- // non-capturing parens - (?: )
- // non-greedy operators - *? +? ?? {}?
- // flag edits - (?i) (?-i) (?i: )
- // i - FoldCase
- // m - !OneLine
- // s - DotNL
- // U - NonGreedy
- // line ends: \A \z
- // \Q and \E to disable/enable metacharacters
- // (?P<name>expr) for named captures
- // \C to match any single byte
- UnicodeGroups = 1<<10, // Allow \p{Han} for Unicode Han group
- // and \P{Han} for its negation.
- NeverNL = 1<<11, // Never match NL, even if the regexp mentions
- // it explicitly.
- NeverCapture = 1<<12, // Parse all parens as non-capturing.
+ NoParseFlags = 0,
+ FoldCase = 1<<0, // Fold case during matching (case-insensitive).
+ Literal = 1<<1, // Treat s as literal string instead of a regexp.
+ ClassNL = 1<<2, // Allow char classes like [^a-z] and \D and \s
+ // and [[:space:]] to match newline.
+ DotNL = 1<<3, // Allow . to match newline.
+ MatchNL = ClassNL | DotNL,
+ OneLine = 1<<4, // Treat ^ and $ as only matching at beginning and
+ // end of text, not around embedded newlines.
+ // (Perl's default)
+ Latin1 = 1<<5, // Regexp and text are in Latin1, not UTF-8.
+ NonGreedy = 1<<6, // Repetition operators are non-greedy by default.
+ PerlClasses = 1<<7, // Allow Perl character classes like \d.
+ PerlB = 1<<8, // Allow Perl's \b and \B.
+ PerlX = 1<<9, // Perl extensions:
+ // non-capturing parens - (?: )
+ // non-greedy operators - *? +? ?? {}?
+ // flag edits - (?i) (?-i) (?i: )
+ // i - FoldCase
+ // m - !OneLine
+ // s - DotNL
+ // U - NonGreedy
+ // line ends: \A \z
+ // \Q and \E to disable/enable metacharacters
+ // (?P<name>expr) for named captures
+ // \C to match any single byte
+ UnicodeGroups = 1<<10, // Allow \p{Han} for Unicode Han group
+ // and \P{Han} for its negation.
+ NeverNL = 1<<11, // Never match NL, even if the regexp mentions
+ // it explicitly.
+ NeverCapture = 1<<12, // Parse all parens as non-capturing.
// As close to Perl as we can get.
- LikePerl = ClassNL | OneLine | PerlClasses | PerlB | PerlX |
- UnicodeGroups,
+ LikePerl = ClassNL | OneLine | PerlClasses | PerlB | PerlX |
+ UnicodeGroups,
// Internal use only.
- WasDollar = 1<<15, // on kRegexpEndText: was $ in regexp text
+ WasDollar = 1<<13, // on kRegexpEndText: was $ in regexp text
+ AllParseFlags = (1<<14)-1,
};
// Get. No set, Regexps are logically immutable once created.
CharClassBuilder& operator=(const CharClassBuilder&) = delete;
};
-// Tell g++ that bitwise ops on ParseFlags produce ParseFlags.
-inline Regexp::ParseFlags operator|(Regexp::ParseFlags a, Regexp::ParseFlags b)
-{
- return static_cast<Regexp::ParseFlags>(static_cast<int>(a) | static_cast<int>(b));
+// Bitwise ops on ParseFlags produce ParseFlags.
+inline Regexp::ParseFlags operator|(Regexp::ParseFlags a,
+ Regexp::ParseFlags b) {
+ return static_cast<Regexp::ParseFlags>(
+ static_cast<int>(a) | static_cast<int>(b));
}
-inline Regexp::ParseFlags operator^(Regexp::ParseFlags a, Regexp::ParseFlags b)
-{
- return static_cast<Regexp::ParseFlags>(static_cast<int>(a) ^ static_cast<int>(b));
+inline Regexp::ParseFlags operator^(Regexp::ParseFlags a,
+ Regexp::ParseFlags b) {
+ return static_cast<Regexp::ParseFlags>(
+ static_cast<int>(a) ^ static_cast<int>(b));
}
-inline Regexp::ParseFlags operator&(Regexp::ParseFlags a, Regexp::ParseFlags b)
-{
- return static_cast<Regexp::ParseFlags>(static_cast<int>(a) & static_cast<int>(b));
+inline Regexp::ParseFlags operator&(Regexp::ParseFlags a,
+ Regexp::ParseFlags b) {
+ return static_cast<Regexp::ParseFlags>(
+ static_cast<int>(a) & static_cast<int>(b));
}
-inline Regexp::ParseFlags operator~(Regexp::ParseFlags a)
-{
- return static_cast<Regexp::ParseFlags>(~static_cast<int>(a));
+inline Regexp::ParseFlags operator~(Regexp::ParseFlags a) {
+ // Attempting to produce a value out of enum's range has undefined behaviour.
+ return static_cast<Regexp::ParseFlags>(
+ ~static_cast<int>(a) & static_cast<int>(Regexp::AllParseFlags));
}
} // namespace re2
// A meta-quoted string, interpreted as a pattern, should always match
// the original unquoted string.
-static void TestQuoteMeta(string unquoted,
+static void TestQuoteMeta(const string& unquoted,
const RE2::Options& options = RE2::DefaultOptions) {
string quoted = RE2::QuoteMeta(unquoted);
RE2 re(quoted, options);
// A meta-quoted string, interpreted as a pattern, should always match
// the original unquoted string.
-static void NegativeTestQuoteMeta(string unquoted, string should_not_match,
- const RE2::Options& options = RE2::DefaultOptions) {
+static void NegativeTestQuoteMeta(
+ const string& unquoted, const string& should_not_match,
+ const RE2::Options& options = RE2::DefaultOptions) {
string quoted = RE2::QuoteMeta(unquoted);
RE2 re(quoted, options);
EXPECT_FALSE(RE2::FullMatch(should_not_match, re))