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"
24 #include "re2/stringpiece.h"
25 #include "re2/walker-inl.h"
33 parse_flags_(static_cast<
uint16_t>(parse_flags)),
38 memset(the_union_, 0,
sizeof the_union_);
48 LOG(DFATAL) <<
"Regexp not destroyed.";
95 ref_map =
new std::map<Regexp*, int>;
120 int r = (*ref_map)[
this] - 1;
125 (*ref_map)[
this] =
r;
143 while (
stack != NULL) {
147 LOG(DFATAL) <<
"Bad reference count " << re->ref_;
150 for (
int i = 0;
i < re->nsub_;
i++) {
236 ParseFlags
flags,
bool can_factor) {
247 PODArray<Regexp*> subcopy;
250 subcopy = PODArray<Regexp*>(
nsub);
251 memmove(subcopy.data(),
sub,
nsub *
sizeof sub[0]);
252 sub = subcopy.data();
265 re->AllocSub(nbigsub);
267 for (
int i = 0;
i < nbigsub - 1;
i++)
278 for (
int i = 0;
i <
nsub;
i++)
325 re->AddRuneToString(
runes[i]);
338 char tmp[
sizeof *
this];
339 void* vthis =
reinterpret_cast<void*
>(
this);
340 void* vthat =
reinterpret_cast<void*
>(that);
341 memmove(
tmp, vthis,
sizeof *
this);
342 memmove(vthis, vthat,
sizeof *
this);
343 memmove(vthat,
tmp,
sizeof *
this);
348 if (
a->op() !=
b->op())
369 return a->rune() ==
b->rune() &&
373 return a->nrunes() ==
b->nrunes() &&
375 memcmp(
a->runes(),
b->runes(),
376 a->nrunes() *
sizeof a->runes()[0]) == 0;
380 return a->nsub() ==
b->nsub();
389 a->min() ==
b->min() &&
390 a->max() ==
b->max();
393 return a->cap() ==
b->cap() &&
a->name() ==
b->name();
396 return a->match_id() ==
b->match_id();
401 return acc->
size() == bcc->
size() &&
408 LOG(DFATAL) <<
"Unexpected op in Regexp::Equal: " <<
a->op();
413 if (a == NULL ||
b == NULL)
439 std::vector<Regexp*> stk;
450 for (
int i = 0;
i <
a->nsub();
i++) {
479 size_t n = stk.size();
496 "invalid escape sequence",
497 "invalid character class",
498 "invalid character class range",
503 "no argument for repetition operator",
504 "invalid repetition size",
505 "bad repetition operator",
506 "invalid perl operator",
508 "invalid named capture group",
535 class NumCapturesWalker :
public Regexp::Walker<Ignored> {
548 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
549 LOG(DFATAL) <<
"NumCapturesWalker::ShortVisit called";
568 class NamedCapturesWalker :
public Regexp::Walker<Ignored> {
574 std::map<std::string, int>*
m =
map_;
583 map_ =
new std::map<std::string, int>;
589 (*map_)[*re->
name()] = re->
cap();
596 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
597 LOG(DFATAL) <<
"NamedCapturesWalker::ShortVisit called";
603 std::map<std::string, int>*
map_;
610 NamedCapturesWalker w;
616 class CaptureNamesWalker :
public Regexp::Walker<Ignored> {
622 std::map<int, std::string>*
m =
map_;
631 map_ =
new std::map<int, std::string>;
633 (*map_)[re->
cap()] = *re->
name();
640 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
641 LOG(DFATAL) <<
"CaptureNamesWalker::ShortVisit called";
647 std::map<int, std::string>*
map_;
654 CaptureNamesWalker w;
662 bytes->resize(nrunes);
663 for (
int i = 0;
i < nrunes;
i++)
664 (*
bytes)[
i] =
static_cast<char>(runes[
i]);
667 char* p = &(*bytes)[0];
668 for (
int i = 0;
i < nrunes;
i++)
671 bytes->shrink_to_fit();
694 if (i == 0 || i >=
nsub_)
702 for (
int j = i; j <
nsub_; j++)
709 bool latin1 = (re->parse_flags() &
Latin1) != 0;
713 *foldcase = (re->parse_flags() &
FoldCase) != 0;
762 if (lo <= 'z' && hi >=
'A') {
765 Rune lo1 = std::max<Rune>(lo,
'A');
766 Rune hi1 = std::min<Rune>(hi,
'Z');
768 upper_ |= ((1 << (hi1 - lo1 + 1)) - 1) << (lo1 -
'A');
770 lo1 = std::max<Rune>(lo,
'a');
771 hi1 = std::min<Rune>(hi,
'z');
773 lower_ |= ((1 << (hi1 - lo1 + 1)) - 1) << (lo1 -
'a');
778 if (
it !=
end() &&
it->lo <= lo && hi <=
it->hi)
820 ranges_.insert(RuneRange(lo, hi));
841 cc->ranges_.insert(RuneRange(
it->lo,
it->hi));
887 std::vector<RuneRange>
v;
902 v.push_back(RuneRange(nextlo,
it->lo - 1));
906 v.push_back(RuneRange(nextlo,
Runemax));
910 for (
size_t i = 0;
i <
v.size();
i++)
945 if (
it->lo == nextlo) {
948 cc->ranges_[
n++] = RuneRange(nextlo,
it->lo - 1);
953 cc->ranges_[
n++] = RuneRange(nextlo,
Runemax);
966 }
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
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[]
virtual Ignored PreVisit(Regexp *re, Ignored ignored, bool *stop)
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
bool RequiredPrefixForAccel(std::string *prefix, bool *foldcase)
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()
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()
void ConvertRunesToBytes(bool latin1, Rune *runes, int nrunes, std::string *bytes)
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
virtual Ignored PreVisit(Regexp *re, Ignored ignored, bool *stop)
friend class NumCapturesWalker
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)
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