Home | History | Annotate | Download | only in re2

Lines Matching defs:RE2

1 // Copyright 2003-2009 The RE2 Authors.  All Rights Reserved.
8 // C++ interface to the re2 regular-expression library.
9 // RE2 supports Perl-style regular expressions (with extensions like
15 // This module uses the re2 library and hence supports
20 // See http://code.google.com/p/re2/wiki/Syntax for the syntax
21 // supported by RE2, and a comparison with PCRE and PERL regexps.
40 // CHECK(RE2::FullMatch("hello", "h.*o"));
43 // CHECK(!RE2::FullMatch("hello", "e"));
49 // The RE2::Latin1 option causes them to be interpreted as Latin-1.
52 // CHECK(RE2::FullMatch(utf8_string, RE2(utf8_pattern)));
53 // CHECK(RE2::FullMatch(latin1_string, RE2(latin1_pattern, RE2::Latin1)));
63 // CHECK(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", &s, &i));
66 // CHECK(!RE2::FullMatch("ruby", "(.*)", &i));
69 // CHECK(!RE2::FullMatch("ruby:1234", "\\w+:\\d+", &s));
72 // CHECK(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", &s));
75 // CHECK(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", NULL, &i));
78 // CHECK(!RE2::FullMatch("ruby:1234567891234", "\\w+:(\\d+)", &i));
92 // CHECK(RE2::PartialMatch("hello", "ell"));
96 // CHECK(RE2::PartialMatch("x*100 + 20", "(\\d+)", &number));
102 // RE2 makes it easy to use any string as a regular expression, without
105 // If speed is of the essence, you can create a pre-compiled "RE2"
110 // RE2 pattern("h.*o");
112 // if (RE2::FullMatch(str, pattern)) ...;
129 // while (RE2::Consume(&input, "(\\w+) = (\\d+)\n", &var, &value)) {
143 // RE2::FindAndConsume(&input, "(\\w+)", &word)
155 // const RE2::Arg* args[10];
157 // // ... populate args with pointers to RE2::Arg values ...
158 // // ... set n to the number of RE2::Arg objects ...
159 // bool match = RE2::FullMatchN(input, pattern, args, n);
163 // bool match = RE2::FullMatch(input, pattern,
178 // CHECK(RE2::FullMatch("100 40 0100 0x40", "(.*) (.*) (.*) (.*)",
179 // RE2::Octal(&a), RE2::Hex(&b), RE2::CRadix(&c), RE2::CRadix(&d));
186 #include "re2/stringpiece.h"
187 #include "re2/variadic_function.h"
189 namespace re2 {
213 // pre-compiled regular expression. An "RE2" object is safe for
215 class RE2 {
250 // Option class to the RE2 constructor.
262 RE2(const char* pattern);
263 RE2(const string& pattern);
265 RE2(const StringPiece& pattern);
266 RE2(const StringPiece& pattern, const Options& option);
267 ~RE2();
269 // Returns whether RE2 was created properly.
272 // The string specification for this RE2. E.g.
273 // RE2 re("ab*c?d+");
277 // If RE2 could not be created properly, returns an error string.
281 // If RE2 could not be created properly, returns an error code.
282 // Else returns RE2::NoError (== 0).
285 // If RE2 could not be created properly, returns the offending
296 re2::Regexp* Regexp() const { return entire_regexp_; }
304 // You can pass in a "const char*" or a "string" or a "RE2" for "pattern".
327 // RE2::FullMatch("abc", "[a-z]+(\\d+)?", &number);
328 static bool FullMatchN(const StringPiece& text, const RE2& re,
331 bool, const StringPiece&, const RE2&, Arg, RE2::FullMatchN> FullMatch;
335 static bool PartialMatchN(const StringPiece& text, const RE2& re, // 3..16 args
338 bool, const StringPiece&, const RE2&, Arg, RE2::PartialMatchN> PartialMatch;
343 static bool ConsumeN(StringPiece* input, const RE2& pattern, // 3..16 args
346 bool, StringPiece*, const RE2&, Arg, RE2::ConsumeN> Consume;
352 static bool FindAndConsumeN(StringPiece* input, const RE2& pattern,
355 bool, StringPiece*, const RE2&, Arg, RE2::FindAndConsumeN> FindAndConsume;
364 // CHECK(RE2::Replace(&s, "b+", "d"));
371 const RE2& pattern,
378 // CHECK(RE2::GlobalReplace(&s, "b+", "d"));
388 const RE2& pattern,
398 const RE2& pattern,
458 // I.e. matching RE2("(foo)|(bar)baz") on "barbazbla" will return true,
512 // max_mem (see below) approx. max memory footprint of RE2
530 // In RE2, those limits would translate to about 240 KB per Prog
531 // and perhaps 2.5 MB per DFA (DFA state sizes vary by regexp; RE2 does a
533 // Each RE2 has two Progs (one forward, one reverse), and each Prog
545 // The RE2 memory budget is statically divided between the two
552 // If this happens too often, RE2 falls back on the NFA implementation.
702 re2::Prog* ReverseProg() const;
709 re2::Regexp* entire_regexp_; // parsed regular expression
710 re2::Regexp* suffix_regexp_; // parsed regular expression, prefix removed
711 re2::Prog* prog_; // compiled program for regexp
712 mutable re2::Prog* rprog_; // reverse program for regexp
726 //DISALLOW_EVIL_CONSTRUCTORS(RE2);
727 RE2(const RE2&);
728 void operator=(const RE2&);
746 class RE2::Arg {
748 // Empty constructor so we can declare arrays of RE2::Arg
824 inline RE2::Arg::Arg() : arg_(NULL), parser_(parse_null) { }
825 inline RE2::Arg::Arg(void* p) : arg_(p), parser_(parse_null) { }
827 inline bool RE2::Arg::Parse(const char* str, int n) const {
833 inline RE2::Arg RE2::Hex(type* ptr) { \
834 return RE2::Arg(ptr, RE2::Arg::parse_ ## name ## _hex); } \
835 inline RE2::Arg RE2::Octal(type* ptr) { \
836 return RE2::Arg(ptr, RE2::Arg::parse_ ## name ## _octal); } \
837 inline RE2::Arg RE2::CRadix(type* ptr) { \
838 return RE2::Arg(ptr, RE2::Arg::parse_ ## name ## _cradix); }
851 } // namespace re2
853 using re2::RE2;