Go to the documentation of this file.
8 #include "re2/regexp.h"
19 #include "util/util.h"
20 #include "util/logging.h"
21 #include "util/mutex.h"
23 #include "re2/stringpiece.h"
24 #include "re2/walker-inl.h"
32 parse_flags_(static_cast<
uint16_t>(parse_flags)),
47 LOG(DFATAL) <<
"Regexp not destroyed.";
94 ref_map =
new std::map<Regexp*, int>;
119 int r = (*ref_map)[
this] - 1;
124 (*ref_map)[
this] =
r;
142 while (
stack != NULL) {
146 LOG(DFATAL) <<
"Bad reference count " << re->
ref_;
149 for (
int i = 0;
i < re->
nsub_;
i++) {
267 for (
int i = 0;
i < nbigsub - 1;
i++)
341 char tmp[
sizeof *
this];
342 void* vthis =
reinterpret_cast<void*
>(
this);
343 void* vthat =
reinterpret_cast<void*
>(that);
344 memmove(
tmp, vthis,
sizeof *
this);
345 memmove(vthis, vthat,
sizeof *
this);
346 memmove(vthat,
tmp,
sizeof *
this);
351 if (
a->op() !=
b->op())
372 return a->rune() ==
b->rune() &&
376 return a->nrunes() ==
b->nrunes() &&
378 memcmp(
a->runes(),
b->runes(),
379 a->nrunes() *
sizeof a->runes()[0]) == 0;
383 return a->nsub() ==
b->nsub();
392 a->min() ==
b->min() &&
393 a->max() ==
b->max();
396 return a->cap() ==
b->cap() &&
a->name() ==
b->name();
399 return a->match_id() ==
b->match_id();
404 return acc->
size() == bcc->
size() &&
411 LOG(DFATAL) <<
"Unexpected op in Regexp::Equal: " <<
a->op();
416 if (
a == NULL ||
b == NULL)
442 std::vector<Regexp*> stk;
453 for (
int i = 0;
i <
a->nsub();
i++) {
482 size_t n = stk.size();
499 "invalid escape sequence",
500 "invalid character class",
501 "invalid character class range",
505 "no argument for repetition operator",
506 "invalid repetition size",
507 "bad repetition operator",
508 "invalid perl operator",
510 "invalid named capture group",
549 LOG(DFATAL) <<
"NumCapturesWalker::ShortVisit called";
573 std::map<std::string, int>*
m =
map_;
582 map_ =
new std::map<std::string, int>;
588 (*map_)[*re->
name()] = re->
cap();
595 LOG(DFATAL) <<
"NamedCapturesWalker::ShortVisit called";
600 std::map<std::string, int>*
map_;
619 std::map<int, std::string>*
m =
map_;
628 map_ =
new std::map<int, std::string>;
630 (*map_)[re->
cap()] = *re->
name();
637 LOG(DFATAL) <<
"CaptureNamesWalker::ShortVisit called";
642 std::map<int, std::string>*
map_;
687 for (
int j = 0; j < re->
nrunes_; j++)
693 char *p = &(*prefix)[0];
694 for (
int j = 0; j < re->
nrunes_; j++) {
697 *p++ =
static_cast<char>(
r);
719 for (
int j =
i; j <
nsub_; j++)
746 if (lo <= 'z' && hi >=
'A') {
749 Rune lo1 = std::max<Rune>(lo,
'A');
750 Rune hi1 = std::min<Rune>(hi,
'Z');
752 upper_ |= ((1 << (hi1 - lo1 + 1)) - 1) << (lo1 -
'A');
754 lo1 = std::max<Rune>(lo,
'a');
755 hi1 = std::min<Rune>(hi,
'z');
757 lower_ |= ((1 << (hi1 - lo1 + 1)) - 1) << (lo1 -
'a');
762 if (
it !=
end() &&
it->lo <= lo && hi <=
it->hi)
871 std::vector<RuneRange>
v;
894 for (
size_t i = 0;
i <
v.size();
i++)
929 if (
it->lo == nextlo) {
950 }
else if (
r < rr[
m].lo) {
CaptureNamesWalker & operator=(const CaptureNamesWalker &)=delete
bool AddRange(Rune lo, Rune hi)
RuneRangeSet::iterator iterator
return memset(p, 0, total)
static Regexp * Plus(Regexp *sub, ParseFlags flags)
#define DCHECK_LE(val1, val2)
static Regexp * Star(Regexp *sub, ParseFlags flags)
void AddRuneToString(Rune r)
static Regexp * Capture(Regexp *sub, ParseFlags flags, int cap)
static const uint32_t AlphaMask
Ignored PreVisit(Regexp *re, Ignored ignored, bool *stop)
static CharClass * New(int maxranges)
void AddCharClass(CharClassBuilder *cc)
static Regexp * Concat(Regexp **subs, int nsubs, ParseFlags flags)
bool RequiredPrefix(std::string *prefix, bool *foldcase, Regexp **suffix)
static const char * kErrorStrings[]
grpc_stream_refcount ref_
static Regexp * LiteralString(Rune *runes, int nrunes, ParseFlags flags)
void call_once(absl::once_flag &flag, Callable &&fn, Args &&... args)
virtual Ignored ShortVisit(Regexp *re, Ignored ignored)
void Copy(const RegexpStatus &status)
static const uint16_t kMaxNsub
int runetochar(char *str, const Rune *rune)
static Regexp * StarPlusOrQuest(RegexpOp op, Regexp *sub, ParseFlags flags)
static int FactorAlternation(Regexp **sub, int nsub, ParseFlags flags)
NamedCapturesWalker & operator=(const NamedCapturesWalker &)=delete
static Regexp * NewCharClass(CharClass *cc, ParseFlags flags)
static std::map< Regexp *, int > * ref_map
const std::string * name()
T Walk(Regexp *re, T top_arg)
virtual Ignored PreVisit(Regexp *re, Ignored ignored, bool *stop)
const_pointer data() const
static bool Equal(Regexp *a, Regexp *b)
static Regexp * ConcatOrAlternate(RegexpOp op, Regexp **subs, int nsubs, ParseFlags flags, bool can_factor)
std::map< std::string, int > * NamedCaptures()
unsigned char suffix[65536]
std::map< std::string, int > * TakeMap()
static const uint16_t kMaxRef
std::map< int, std::string > * TakeMap()
NumCapturesWalker & operator=(const NumCapturesWalker &)=delete
std::map< int, std::string > * map_
static Regexp * AlternateNoFactor(Regexp **subs, int nsubs, ParseFlags flags)
static Regexp * HaveMatch(int match_id, ParseFlags flags)
static const char prefix[]
#define DCHECK_GE(val1, val2)
std::map< std::string, int > * map_
RegexpStatusCode code() const
std::map< int, std::string > * CaptureNames()
static Regexp * NewLiteral(Rune rune, ParseFlags flags)
virtual Ignored ShortVisit(Regexp *re, Ignored ignored)
Ignored PreVisit(Regexp *re, Ignored ignored, bool *stop)
static bool TopEqual(Regexp *a, Regexp *b)
CharClassBuilder * Copy()
static std::string CodeText(RegexpStatusCode code)
#define DCHECK(condition)
CharClass * GetCharClass()
static Regexp * Quest(Regexp *sub, ParseFlags flags)
virtual Ignored ShortVisit(Regexp *re, Ignored ignored)
static Regexp * Alternate(Regexp **subs, int nsubs, ParseFlags flags)
Regexp(RegexpOp op, ParseFlags parse_flags)
static Regexp * Repeat(Regexp *sub, ParseFlags flags, int min, int max)
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:01