Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb_re2::Regexp Class Reference
Collaboration diagram for duckdb_re2::Regexp:

Classes

class  Walker
class  ParseState

Public Types

enum  ParseFlags {
  NoParseFlags = 0 , FoldCase = 1<<0 , Literal = 1<<1 , ClassNL = 1<<2 ,
  DotNL = 1<<3 , MatchNL = ClassNL | DotNL , OneLine = 1<<4 , Latin1 = 1<<5 ,
  NonGreedy = 1<<6 , PerlClasses = 1<<7 , PerlB = 1<<8 , PerlX = 1<<9 ,
  UnicodeGroups = 1<<10 , NeverNL = 1<<11 , NeverCapture = 1<<12 , LikePerl ,
  WasDollar = 1<<13 , AllParseFlags = (1<<14)-1
}

Public Member Functions

RegexpOp op ()
int nsub ()
bool simple ()
ParseFlags parse_flags ()
int Ref ()
Regexp ** sub ()
int min ()
int max ()
Rune rune ()
CharClass * cc ()
int cap ()
const std::string * name ()
Rune * runes ()
int nrunes ()
int match_id ()
Regexp * Incref ()
void Decref ()
Regexp * Simplify ()
int NumCaptures ()
std::map< std::string, int > * NamedCaptures ()
std::map< int, std::string > * CaptureNames ()
std::string ToString ()
std::string Dump ()
Prog * CompileToProg (int64_t max_mem)
Prog * CompileToReverseProg (int64_t max_mem)
bool MimicsPCRE ()
void NullWalk ()
bool RequiredPrefix (std::string *prefix, bool *foldcase, Regexp **suffix)
bool RequiredPrefixForAccel (std::string *prefix, bool *foldcase)

Static Public Member Functions

static Regexp * Parse (const StringPiece &s, ParseFlags flags, RegexpStatus *status)
static bool SimplifyRegexp (const StringPiece &src, ParseFlags flags, std::string *dst, RegexpStatus *status)
static Regexp * Plus (Regexp *sub, ParseFlags flags)
static Regexp * Star (Regexp *sub, ParseFlags flags)
static Regexp * Quest (Regexp *sub, ParseFlags flags)
static Regexp * Concat (Regexp **subs, int nsubs, ParseFlags flags)
static Regexp * Alternate (Regexp **subs, int nsubs, ParseFlags flags)
static Regexp * Capture (Regexp *sub, ParseFlags flags, int cap)
static Regexp * Repeat (Regexp *sub, ParseFlags flags, int min, int max)
static Regexp * NewLiteral (Rune rune, ParseFlags flags)
static Regexp * NewCharClass (CharClass *cc, ParseFlags flags)
static Regexp * LiteralString (Rune *runes, int nrunes, ParseFlags flags)
static Regexp * HaveMatch (int match_id, ParseFlags flags)
static Regexp * AlternateNoFactor (Regexp **subs, int nsubs, ParseFlags flags)
static void FUZZING_ONLY_set_maximum_repeat_count (int i)

Private Member Functions

 Regexp (RegexpOp op, ParseFlags parse_flags)
void Destroy ()
bool QuickDestroy ()
bool ComputeSimple ()
void AllocSub (int n)
void AddRuneToString (Rune r)
void Swap (Regexp *that)
 Regexp (const Regexp &)=delete
Regexp & operator= (const Regexp &)=delete

Static Private Member Functions

static Regexp * StarPlusOrQuest (RegexpOp op, Regexp *sub, ParseFlags flags)
static Regexp * ConcatOrAlternate (RegexpOp op, Regexp **subs, int nsubs, ParseFlags flags, bool can_factor)
static Rune * LeadingString (Regexp *re, int *nrune, ParseFlags *flags)
static void RemoveLeadingString (Regexp *re, int n)
static Regexp * LeadingRegexp (Regexp *re)
static Regexp * RemoveLeadingRegexp (Regexp *re)
static int FactorAlternation (Regexp **sub, int nsub, ParseFlags flags)
static bool Equal (Regexp *a, Regexp *b)

Private Attributes

uint8_t op_
uint8_t simple_
uint16_t parse_flags_
uint16_t ref_
uint16_t nsub_
union { 
   Regexp **   submany_ 
   Regexp *   subone_ 
}; 
Regexp * down_
union { 
   struct { 
      int   max_ 
      int   min_ 
   }   repeat
   struct { 
      int   cap_ 
      std::string *   name_ 
   }   capture
   struct { 
      int   nrunes_ 
      Rune *   runes_ 
   }   literal_string
   struct { 
      CharClass *   cc_ 
      CharClassBuilder *   ccb_ 
   }   char_class
   Rune   rune_ 
   int   match_id_ 
   void *   the_union_ [2] 
} arguments

Static Private Attributes

static const uint16_t kMaxRef = 0xffff
static const uint16_t kMaxNsub = 0xffff

Friends

class CoalesceWalker
class SimplifyWalker
class NumCapturesWalker
class ParseState
class FactorAlternationImpl
bool ParseCharClass (StringPiece *s, Regexp **out_re, RegexpStatus *status)
bool RegexpEqualTestingOnly (Regexp *, Regexp *)

Member Enumeration Documentation

◆ ParseFlags

enum duckdb_re2::Regexp::ParseFlags
322486 {
322487 NoParseFlags = 0,
322488 FoldCase = 1<<0, // Fold case during matching (case-insensitive).
322489 Literal = 1<<1, // Treat s as literal string instead of a regexp.
322490 ClassNL = 1<<2, // Allow char classes like [^a-z] and \D and \s
322491 // and [[:space:]] to match newline.
322492 DotNL = 1<<3, // Allow . to match newline.
322493 MatchNL = ClassNL | DotNL,
322494 OneLine = 1<<4, // Treat ^ and $ as only matching at beginning and
322495 // end of text, not around embedded newlines.
322496 // (Perl's default)
322497 Latin1 = 1<<5, // Regexp and text are in Latin1, not UTF-8.
322498 NonGreedy = 1<<6, // Repetition operators are non-greedy by default.
322499 PerlClasses = 1<<7, // Allow Perl character classes like \d.
322500 PerlB = 1<<8, // Allow Perl's \b and \B.
322501 PerlX = 1<<9, // Perl extensions:
322502 // non-capturing parens - (?: )
322503 // non-greedy operators - *? +? ?? {}?
322504 // flag edits - (?i) (?-i) (?i: )
322505 // i - FoldCase
322506 // m - !OneLine
322507 // s - DotNL
322508 // U - NonGreedy
322509 // line ends: \A \z
322510 // \Q and \E to disable/enable metacharacters
322511 // (?P<name>expr) for named captures
322512 // \C to match any single byte
322513 UnicodeGroups = 1<<10, // Allow \p{Han} for Unicode Han group
322514 // and \P{Han} for its negation.
322515 NeverNL = 1<<11, // Never match NL, even if the regexp mentions
322516 // it explicitly.
322517 NeverCapture = 1<<12, // Parse all parens as non-capturing.
322518
322519 // As close to Perl as we can get.
322520 LikePerl = ClassNL | OneLine | PerlClasses | PerlB | PerlX |
322521 UnicodeGroups,
322522
322523 // Internal use only.
322524 WasDollar = 1<<13, // on kRegexpEndText: was $ in regexp text
322525 AllParseFlags = (1<<14)-1,
322526 };

Constructor & Destructor Documentation

◆ Regexp()

duckdb_re2::Regexp::Regexp ( RegexpOp op,
ParseFlags parse_flags )
explicitprivate
472974 : op_(static_cast<uint8_t>(op)),
472975 simple_(false),
472976 parse_flags_(static_cast<uint16_t>(parse_flags)),
472977 ref_(1),
472978 nsub_(0),
472979 down_(NULL) {
472980 subone_ = NULL;
472981 memset(arguments.the_union_, 0, sizeof arguments.the_union_);
472982}
::uint8_t uint8_t
::uint16_t uint16_t

◆ ~Regexp()

duckdb_re2::Regexp::~Regexp ( )
private
472989 {
472990 if (nsub_ > 0)
472991 LOG(DFATAL) << "Regexp not destroyed.";
472992
472993 switch (op_) {
472994 default:
472995 break;
472996 case kRegexpCapture:
472997 delete arguments.capture.name_;
472998 break;
472999 case kRegexpLiteralString:
473000 delete[] arguments.literal_string.runes_;
473001 break;
473002 case kRegexpCharClass:
473003 if (arguments.char_class.cc_)
473004 arguments.char_class.cc_->Delete();
473005 delete arguments.char_class.ccb_;
473006 break;
473007 }
473008}

Member Function Documentation

◆ op()

RegexpOp duckdb_re2::Regexp::op ( )
inline
322529{ return static_cast<RegexpOp>(op_); }

◆ nsub()

int duckdb_re2::Regexp::nsub ( )
inline
322530{ return nsub_; }

◆ simple()

bool duckdb_re2::Regexp::simple ( )
inline
322531{ return simple_ != 0; }

◆ parse_flags()

ParseFlags duckdb_re2::Regexp::parse_flags ( )
inline
322532{ return static_cast<ParseFlags>(parse_flags_); }

◆ Ref()

int duckdb_re2::Regexp::Ref ( )
473035 {
473036 if (ref_ < kMaxRef)
473037 return ref_;
473038
473039 MutexLock l(ref_mutex());
473040 return (*ref_map())[this];
473041}

◆ sub()

Regexp ** duckdb_re2::Regexp::sub ( )
inline
322535 {
322536 if(nsub_ <= 1)
322537 return &subone_;
322538 else
322539 return submany_;
322540 }

◆ min()

int duckdb_re2::Regexp::min ( )
inline
322542{ DCHECK_EQ(op_, kRegexpRepeat); return arguments.repeat.min_; }

◆ max()

int duckdb_re2::Regexp::max ( )
inline
322543{ DCHECK_EQ(op_, kRegexpRepeat); return arguments.repeat.max_; }

◆ rune()

Rune duckdb_re2::Regexp::rune ( )
inline
322544{ DCHECK_EQ(op_, kRegexpLiteral); return arguments.rune_; }

◆ cc()

CharClass * duckdb_re2::Regexp::cc ( )
inline
322545{ DCHECK_EQ(op_, kRegexpCharClass); return arguments.char_class.cc_; }

◆ cap()

int duckdb_re2::Regexp::cap ( )
inline
322546{ DCHECK_EQ(op_, kRegexpCapture); return arguments.capture.cap_; }

◆ name()

const std::string * duckdb_re2::Regexp::name ( )
inline
322547{ DCHECK_EQ(op_, kRegexpCapture); return arguments.capture.name_; }

◆ runes()

Rune * duckdb_re2::Regexp::runes ( )
inline
322548{ DCHECK_EQ(op_, kRegexpLiteralString); return arguments.literal_string.runes_; }

◆ nrunes()

int duckdb_re2::Regexp::nrunes ( )
inline
322549{ DCHECK_EQ(op_, kRegexpLiteralString); return arguments.literal_string.nrunes_; }

◆ match_id()

int duckdb_re2::Regexp::match_id ( )
inline
322550{ DCHECK_EQ(op_, kRegexpHaveMatch); return arguments.match_id_; }

◆ Incref()

Regexp * duckdb_re2::Regexp::Incref ( )
473044 {
473045 if (ref_ >= kMaxRef-1) {
473046 static std::once_flag ref_once;
473047 std::call_once(ref_once, []() {
473048 (void) new (ref_storage) RefStorage;
473049 });
473050
473051 // Store ref count in overflow map.
473052 MutexLock l(ref_mutex());
473053 if (ref_ == kMaxRef) {
473054 // already overflowed
473055 (*ref_map())[this]++;
473056 } else {
473057 // overflowing now
473058 (*ref_map())[this] = kMaxRef;
473059 ref_ = kMaxRef;
473060 }
473061 return this;
473062 }
473063
473064 ref_++;
473065 return this;
473066}

◆ Decref()

void duckdb_re2::Regexp::Decref ( )
473069 {
473070 if (ref_ == kMaxRef) {
473071 // Ref count is stored in overflow map.
473072 MutexLock l(ref_mutex());
473073 int r = (*ref_map())[this] - 1;
473074 if (r < kMaxRef) {
473075 ref_ = static_cast<uint16_t>(r);
473076 ref_map()->erase(this);
473077 } else {
473078 (*ref_map())[this] = r;
473079 }
473080 return;
473081 }
473082 ref_--;
473083 if (ref_ == 0)
473084 Destroy();
473085}

◆ Parse()

Regexp * duckdb_re2::Regexp::Parse ( const StringPiece & s,
ParseFlags flags,
RegexpStatus * status )
static
468885 {
468886 // Make status non-NULL (easier on everyone else).
468887 RegexpStatus xstatus;
468888 if (status == NULL)
468889 status = &xstatus;
468890
468891 ParseState ps(global_flags, s, status);
468892 StringPiece t = s;
468893
468894 // Convert regexp to UTF-8 (easier on the rest of the parser).
468895 if (global_flags & Latin1) {
468896 std::string* tmp = new std::string;
468897 ConvertLatin1ToUTF8(t, tmp);
468898 status->set_tmp(tmp);
468899 t = *tmp;
468900 }
468901
468902 if (global_flags & Literal) {
468903 // Special parse loop for literal string.
468904 while (!t.empty()) {
468905 Rune r;
468906 if (StringPieceToRune(&r, &t, status) < 0)
468907 return NULL;
468908 if (!ps.PushLiteral(r))
468909 return NULL;
468910 }
468911 return ps.DoFinish();
468912 }
468913
468914 StringPiece lastunary = StringPiece();
468915 while (!t.empty()) {
468916 StringPiece isunary = StringPiece();
468917 switch (t[0]) {
468918 default: {
468919 Rune r;
468920 if (StringPieceToRune(&r, &t, status) < 0)
468921 return NULL;
468922 if (!ps.PushLiteral(r))
468923 return NULL;
468924 break;
468925 }
468926
468927 case '(':
468928 // "(?" introduces Perl escape.
468929 if ((ps.flags() & PerlX) && (t.size() >= 2 && t[1] == '?')) {
468930 // Flag changes and non-capturing groups.
468931 if (!ps.ParsePerlFlags(&t))
468932 return NULL;
468933 break;
468934 }
468935 if (ps.flags() & NeverCapture) {
468936 if (!ps.DoLeftParenNoCapture())
468937 return NULL;
468938 } else {
468939 if (!ps.DoLeftParen(StringPiece()))
468940 return NULL;
468941 }
468942 t.remove_prefix(1); // '('
468943 break;
468944
468945 case '|':
468946 if (!ps.DoVerticalBar())
468947 return NULL;
468948 t.remove_prefix(1); // '|'
468949 break;
468950
468951 case ')':
468952 if (!ps.DoRightParen())
468953 return NULL;
468954 t.remove_prefix(1); // ')'
468955 break;
468956
468957 case '^': // Beginning of line.
468958 if (!ps.PushCaret())
468959 return NULL;
468960 t.remove_prefix(1); // '^'
468961 break;
468962
468963 case '$': // End of line.
468964 if (!ps.PushDollar())
468965 return NULL;
468966 t.remove_prefix(1); // '$'
468967 break;
468968
468969 case '.': // Any character (possibly except newline).
468970 if (!ps.PushDot())
468971 return NULL;
468972 t.remove_prefix(1); // '.'
468973 break;
468974
468975 case '[': { // Character class.
468976 Regexp* re;
468977 if (!ps.ParseCharClass(&t, &re, status))
468978 return NULL;
468979 if (!ps.PushRegexp(re))
468980 return NULL;
468981 break;
468982 }
468983
468984 case '*': { // Zero or more.
468985 RegexpOp op;
468986 op = kRegexpStar;
468987 goto Rep;
468988 case '+': // One or more.
468989 op = kRegexpPlus;
468990 goto Rep;
468991 case '?': // Zero or one.
468992 op = kRegexpQuest;
468993 goto Rep;
468994 Rep:
468995 StringPiece opstr = t;
468996 bool nongreedy = false;
468997 t.remove_prefix(1); // '*' or '+' or '?'
468998 if (ps.flags() & PerlX) {
468999 if (!t.empty() && t[0] == '?') {
469000 nongreedy = true;
469001 t.remove_prefix(1); // '?'
469002 }
469003 if (!lastunary.empty()) {
469004 // In Perl it is not allowed to stack repetition operators:
469005 // a** is a syntax error, not a double-star.
469006 // (and a++ means something else entirely, which we don't support!)
469007 status->set_code(kRegexpRepeatOp);
469008 status->set_error_arg(StringPiece(
469009 lastunary.data(),
469010 static_cast<size_t>(t.data() - lastunary.data())));
469011 return NULL;
469012 }
469013 }
469014 opstr = StringPiece(opstr.data(),
469015 static_cast<size_t>(t.data() - opstr.data()));
469016 if (!ps.PushRepeatOp(op, opstr, nongreedy))
469017 return NULL;
469018 isunary = opstr;
469019 break;
469020 }
469021
469022 case '{': { // Counted repetition.
469023 int lo, hi;
469024 StringPiece opstr = t;
469025 if (!MaybeParseRepetition(&t, &lo, &hi)) {
469026 // Treat like a literal.
469027 if (!ps.PushLiteral('{'))
469028 return NULL;
469029 t.remove_prefix(1); // '{'
469030 break;
469031 }
469032 bool nongreedy = false;
469033 if (ps.flags() & PerlX) {
469034 if (!t.empty() && t[0] == '?') {
469035 nongreedy = true;
469036 t.remove_prefix(1); // '?'
469037 }
469038 if (!lastunary.empty()) {
469039 // Not allowed to stack repetition operators.
469040 status->set_code(kRegexpRepeatOp);
469041 status->set_error_arg(StringPiece(
469042 lastunary.data(),
469043 static_cast<size_t>(t.data() - lastunary.data())));
469044 return NULL;
469045 }
469046 }
469047 opstr = StringPiece(opstr.data(),
469048 static_cast<size_t>(t.data() - opstr.data()));
469049 if (!ps.PushRepetition(lo, hi, opstr, nongreedy))
469050 return NULL;
469051 isunary = opstr;
469052 break;
469053 }
469054
469055 case '\\': { // Escaped character or Perl sequence.
469056 // \b and \B: word boundary or not
469057 if ((ps.flags() & Regexp::PerlB) &&
469058 t.size() >= 2 && (t[1] == 'b' || t[1] == 'B')) {
469059 if (!ps.PushWordBoundary(t[1] == 'b'))
469060 return NULL;
469061 t.remove_prefix(2); // '\\', 'b'
469062 break;
469063 }
469064
469065 if ((ps.flags() & Regexp::PerlX) && t.size() >= 2) {
469066 if (t[1] == 'A') {
469067 if (!ps.PushSimpleOp(kRegexpBeginText))
469068 return NULL;
469069 t.remove_prefix(2); // '\\', 'A'
469070 break;
469071 }
469072 if (t[1] == 'z') {
469073 if (!ps.PushSimpleOp(kRegexpEndText))
469074 return NULL;
469075 t.remove_prefix(2); // '\\', 'z'
469076 break;
469077 }
469078 // Do not recognize \Z, because this library can't
469079 // implement the exact Perl/PCRE semantics.
469080 // (This library treats "(?-m)$" as \z, even though
469081 // in Perl and PCRE it is equivalent to \Z.)
469082
469083 if (t[1] == 'C') { // \C: any byte [sic]
469084 if (!ps.PushSimpleOp(kRegexpAnyByte))
469085 return NULL;
469086 t.remove_prefix(2); // '\\', 'C'
469087 break;
469088 }
469089
469090 if (t[1] == 'Q') { // \Q ... \E: the ... is always literals
469091 t.remove_prefix(2); // '\\', 'Q'
469092 while (!t.empty()) {
469093 if (t.size() >= 2 && t[0] == '\\' && t[1] == 'E') {
469094 t.remove_prefix(2); // '\\', 'E'
469095 break;
469096 }
469097 Rune r;
469098 if (StringPieceToRune(&r, &t, status) < 0)
469099 return NULL;
469100 if (!ps.PushLiteral(r))
469101 return NULL;
469102 }
469103 break;
469104 }
469105 }
469106
469107 if (t.size() >= 2 && (t[1] == 'p' || t[1] == 'P')) {
469108 Regexp* re = new Regexp(kRegexpCharClass, ps.flags() & ~FoldCase);
469109 re->arguments.char_class.ccb_ = new CharClassBuilder;
469110 switch (ParseUnicodeGroup(&t, ps.flags(), re->arguments.char_class.ccb_, status)) {
469111 case kParseOk:
469112 if (!ps.PushRegexp(re))
469113 return NULL;
469114 goto Break2;
469115 case kParseError:
469116 re->Decref();
469117 return NULL;
469118 case kParseNothing:
469119 re->Decref();
469120 break;
469121 }
469122 }
469123
469124 const UGroup *g = MaybeParsePerlCCEscape(&t, ps.flags());
469125 if (g != NULL) {
469126 Regexp* re = new Regexp(kRegexpCharClass, ps.flags() & ~FoldCase);
469127 re->arguments.char_class.ccb_ = new CharClassBuilder;
469128 AddUGroup(re->arguments.char_class.ccb_, g, g->sign, ps.flags());
469129 if (!ps.PushRegexp(re))
469130 return NULL;
469131 break;
469132 }
469133
469134 Rune r;
469135 if (!ParseEscape(&t, &r, status, ps.rune_max()))
469136 return NULL;
469137 if (!ps.PushLiteral(r))
469138 return NULL;
469139 break;
469140 }
469141 }
469142 Break2:
469143 lastunary = isunary;
469144 }
469145 return ps.DoFinish();
469146}
Definition duckdb.cpp:466738

◆ Simplify()

Regexp * duckdb_re2::Regexp::Simplify ( )
474410 {
474411 CoalesceWalker cw;
474412 Regexp* cre = cw.Walk(this, NULL);
474413 if (cre == NULL)
474414 return NULL;
474415 if (cw.stopped_early()) {
474416 cre->Decref();
474417 return NULL;
474418 }
474419 SimplifyWalker sw;
474420 Regexp* sre = sw.Walk(cre, NULL);
474421 cre->Decref();
474422 if (sre == NULL)
474423 return NULL;
474424 if (sw.stopped_early()) {
474425 sre->Decref();
474426 return NULL;
474427 }
474428 return sre;
474429}

◆ SimplifyRegexp()

bool duckdb_re2::Regexp::SimplifyRegexp ( const StringPiece & src,
ParseFlags flags,
std::string * dst,
RegexpStatus * status )
static
474257 {
474258 Regexp* re = Parse(src, flags, status);
474259 if (re == NULL)
474260 return false;
474261 Regexp* sre = re->Simplify();
474262 re->Decref();
474263 if (sre == NULL) {
474264 if (status) {
474265 status->set_code(kRegexpInternalError);
474266 status->set_error_arg(src);
474267 }
474268 return false;
474269 }
474270 *dst = sre->ToString();
474271 sre->Decref();
474272 return true;
474273}

◆ NumCaptures()

int duckdb_re2::Regexp::NumCaptures ( )
473514 {
473515 NumCapturesWalker w;
473516 w.Walk(this, 0);
473517 return w.ncapture();
473518}

◆ NamedCaptures()

std::map< std::string, int > * duckdb_re2::Regexp::NamedCaptures ( )
473561 {
473562 NamedCapturesWalker w;
473563 w.Walk(this, 0);
473564 return w.TakeMap();
473565}

◆ CaptureNames()

std::map< int, std::string > * duckdb_re2::Regexp::CaptureNames ( )
473605 {
473606 CaptureNamesWalker w;
473607 w.Walk(this, 0);
473608 return w.TakeMap();
473609}

◆ ToString()

std::string duckdb_re2::Regexp::ToString ( )
475036 {
475037 std::string t;
475038 ToStringWalker w(&t);
475039 w.WalkExponential(this, PrecToplevel, 100000);
475040 if (w.stopped_early())
475041 t += " [truncated]";
475042 return t;
475043}

◆ Plus()

Regexp * duckdb_re2::Regexp::Plus ( Regexp * sub,
ParseFlags flags )
static
473176 {
473177 return StarPlusOrQuest(kRegexpPlus, sub, flags);
473178}

◆ Star()

Regexp * duckdb_re2::Regexp::Star ( Regexp * sub,
ParseFlags flags )
static
473180 {
473181 return StarPlusOrQuest(kRegexpStar, sub, flags);
473182}

◆ Quest()

Regexp * duckdb_re2::Regexp::Quest ( Regexp * sub,
ParseFlags flags )
static
473184 {
473185 return StarPlusOrQuest(kRegexpQuest, sub, flags);
473186}

◆ Concat()

Regexp * duckdb_re2::Regexp::Concat ( Regexp ** subs,
int nsubs,
ParseFlags flags )
static
473236 {
473237 return ConcatOrAlternate(kRegexpConcat, sub, nsub, flags, false);
473238}

◆ Alternate()

Regexp * duckdb_re2::Regexp::Alternate ( Regexp ** subs,
int nsubs,
ParseFlags flags )
static
473240 {
473241 return ConcatOrAlternate(kRegexpAlternate, sub, nsub, flags, true);
473242}

◆ Capture()

Regexp * duckdb_re2::Regexp::Capture ( Regexp * sub,
ParseFlags flags,
int cap )
static
473248 {
473249 Regexp* re = new Regexp(kRegexpCapture, flags);
473250 re->AllocSub(1);
473251 re->sub()[0] = sub;
473252 re->arguments.capture.cap_ = cap;
473253 return re;
473254}

◆ Repeat()

Regexp * duckdb_re2::Regexp::Repeat ( Regexp * sub,
ParseFlags flags,
int min,
int max )
static
473256 {
473257 Regexp* re = new Regexp(kRegexpRepeat, flags);
473258 re->AllocSub(1);
473259 re->sub()[0] = sub;
473260 re->arguments.repeat.min_ = min;
473261 re->arguments.repeat.max_ = max;
473262 return re;
473263}

◆ NewLiteral()

Regexp * duckdb_re2::Regexp::NewLiteral ( Rune rune,
ParseFlags flags )
static
473265 {
473266 Regexp* re = new Regexp(kRegexpLiteral, flags);
473267 re->arguments.rune_ = rune;
473268 return re;
473269}

◆ NewCharClass()

Regexp * duckdb_re2::Regexp::NewCharClass ( CharClass * cc,
ParseFlags flags )
static
473282 {
473283 Regexp* re = new Regexp(kRegexpCharClass, flags);
473284 re->arguments.char_class.cc_ = cc;
473285 return re;
473286}

◆ LiteralString()

Regexp * duckdb_re2::Regexp::LiteralString ( Rune * runes,
int nrunes,
ParseFlags flags )
static
473271 {
473272 if (nrunes <= 0)
473273 return new Regexp(kRegexpEmptyMatch, flags);
473274 if (nrunes == 1)
473275 return NewLiteral(runes[0], flags);
473276 Regexp* re = new Regexp(kRegexpLiteralString, flags);
473277 for (int i = 0; i < nrunes; i++)
473278 re->AddRuneToString(runes[i]);
473279 return re;
473280}

◆ HaveMatch()

Regexp * duckdb_re2::Regexp::HaveMatch ( int match_id,
ParseFlags flags )
static
473141 {
473142 Regexp* re = new Regexp(kRegexpHaveMatch, flags);
473143 re->arguments.match_id_ = match_id;
473144 return re;
473145}

◆ AlternateNoFactor()

Regexp * duckdb_re2::Regexp::AlternateNoFactor ( Regexp ** subs,
int nsubs,
ParseFlags flags )
static
473244 {
473245 return ConcatOrAlternate(kRegexpAlternate, sub, nsub, flags, false);
473246}

◆ CompileToProg()

Prog * duckdb_re2::Regexp::CompileToProg ( int64_t max_mem)
462063 {
462064 return Compiler::Compile(this, false, max_mem);
462065}

◆ CompileToReverseProg()

Prog * duckdb_re2::Regexp::CompileToReverseProg ( int64_t max_mem)
462067 {
462068 return Compiler::Compile(this, true, max_mem);
462069}

◆ MimicsPCRE()

bool duckdb_re2::Regexp::MimicsPCRE ( )
465138 {
465139 PCREWalker w;
465140 return w.Walk(this, true);
465141}

◆ RequiredPrefix()

bool duckdb_re2::Regexp::RequiredPrefix ( std::string * prefix,
bool * foldcase,
Regexp ** suffix )
473632 {
473633 prefix->clear();
473634 *foldcase = false;
473635 *suffix = NULL;
473636
473637 // No need for a walker: the regexp must be of the form
473638 // 1. some number of ^ anchors
473639 // 2. a literal char or string
473640 // 3. the rest
473641 if (op_ != kRegexpConcat)
473642 return false;
473643 int i = 0;
473644 while (i < nsub_ && sub()[i]->op_ == kRegexpBeginText)
473645 i++;
473646 if (i == 0 || i >= nsub_)
473647 return false;
473648 Regexp* re = sub()[i];
473649 if (re->op_ != kRegexpLiteral &&
473650 re->op_ != kRegexpLiteralString)
473651 return false;
473652 i++;
473653 if (i < nsub_) {
473654 for (int j = i; j < nsub_; j++)
473655 sub()[j]->Incref();
473656 *suffix = Concat(sub() + i, nsub_ - i, parse_flags());
473657 } else {
473658 *suffix = new Regexp(kRegexpEmptyMatch, parse_flags());
473659 }
473660
473661 bool latin1 = (re->parse_flags() & Latin1) != 0;
473662 Rune* runes = re->op_ == kRegexpLiteral ? &re->arguments.rune_ : re->arguments.literal_string.runes_;
473663 int nrunes = re->op_ == kRegexpLiteral ? 1 : re->arguments.literal_string.nrunes_;
473664 ConvertRunesToBytes(latin1, runes, nrunes, prefix);
473665 *foldcase = (re->parse_flags() & FoldCase) != 0;
473666 return true;
473667}

◆ RequiredPrefixForAccel()

bool duckdb_re2::Regexp::RequiredPrefixForAccel ( std::string * prefix,
bool * foldcase )
473672 {
473673 prefix->clear();
473674 *foldcase = false;
473675
473676 // No need for a walker: the regexp must either begin with or be
473677 // a literal char or string. We "see through" capturing groups,
473678 // but make no effort to glue multiple prefix fragments together.
473679 Regexp* re = op_ == kRegexpConcat && nsub_ > 0 ? sub()[0] : this;
473680 while (re->op_ == kRegexpCapture) {
473681 re = re->sub()[0];
473682 if (re->op_ == kRegexpConcat && re->nsub_ > 0)
473683 re = re->sub()[0];
473684 }
473685 if (re->op_ != kRegexpLiteral &&
473686 re->op_ != kRegexpLiteralString)
473687 return false;
473688
473689 bool latin1 = (re->parse_flags() & Latin1) != 0;
473690 Rune* runes = re->op_ == kRegexpLiteral ? &re->arguments.rune_ : re->arguments.literal_string.runes_;
473691 int nrunes = re->op_ == kRegexpLiteral ? 1 : re->arguments.literal_string.nrunes_;
473692 ConvertRunesToBytes(latin1, runes, nrunes, prefix);
473693 *foldcase = (re->parse_flags() & FoldCase) != 0;
473694 return true;
473695}

◆ FUZZING_ONLY_set_maximum_repeat_count()

void duckdb_re2::Regexp::FUZZING_ONLY_set_maximum_repeat_count ( int i)
static
466717 {
466718 maximum_repeat_count = i;
466719}

◆ Destroy()

void duckdb_re2::Regexp::Destroy ( )
private
473088 {
473089 if (QuickDestroy())
473090 return;
473091
473092 // Handle recursive Destroy with explicit stack
473093 // to avoid arbitrarily deep recursion on process stack [sigh].
473094 down_ = NULL;
473095 Regexp* stack = this;
473096 while (stack != NULL) {
473097 Regexp* re = stack;
473098 stack = re->down_;
473099 if (re->ref_ != 0)
473100 LOG(DFATAL) << "Bad reference count " << re->ref_;
473101 if (re->nsub_ > 0) {
473102 Regexp** subs = re->sub();
473103 for (int i = 0; i < re->nsub_; i++) {
473104 Regexp* sub = subs[i];
473105 if (sub == NULL)
473106 continue;
473107 if (sub->ref_ == kMaxRef)
473108 sub->Decref();
473109 else
473110 --sub->ref_;
473111 if (sub->ref_ == 0 && !sub->QuickDestroy()) {
473112 sub->down_ = stack;
473113 stack = sub;
473114 }
473115 }
473116 if (re->nsub_ > 1)
473117 delete[] subs;
473118 re->nsub_ = 0;
473119 }
473120 delete re;
473121 }
473122}

◆ QuickDestroy()

bool duckdb_re2::Regexp::QuickDestroy ( )
private
473012 {
473013 if (nsub_ == 0) {
473014 delete this;
473015 return true;
473016 }
473017 return false;
473018}

◆ ComputeSimple()

bool duckdb_re2::Regexp::ComputeSimple ( )
private
474277 {
474278 Regexp** subs;
474279 switch (op_) {
474280 case kRegexpNoMatch:
474281 case kRegexpEmptyMatch:
474282 case kRegexpLiteral:
474283 case kRegexpLiteralString:
474284 case kRegexpBeginLine:
474285 case kRegexpEndLine:
474286 case kRegexpBeginText:
474287 case kRegexpWordBoundary:
474288 case kRegexpNoWordBoundary:
474289 case kRegexpEndText:
474290 case kRegexpAnyChar:
474291 case kRegexpAnyByte:
474292 case kRegexpHaveMatch:
474293 return true;
474294 case kRegexpConcat:
474295 case kRegexpAlternate:
474296 // These are simple as long as the subpieces are simple.
474297 subs = sub();
474298 for (int i = 0; i < nsub_; i++)
474299 if (!subs[i]->simple())
474300 return false;
474301 return true;
474302 case kRegexpCharClass:
474303 // Simple as long as the char class is not empty, not full.
474304 if (arguments.char_class.ccb_ != NULL)
474305 return !arguments.char_class.ccb_->empty() && !arguments.char_class.ccb_->full();
474306 return !arguments.char_class.cc_->empty() && !arguments.char_class.cc_->full();
474307 case kRegexpCapture:
474308 subs = sub();
474309 return subs[0]->simple();
474310 case kRegexpStar:
474311 case kRegexpPlus:
474312 case kRegexpQuest:
474313 subs = sub();
474314 if (!subs[0]->simple())
474315 return false;
474316 switch (subs[0]->op_) {
474317 case kRegexpStar:
474318 case kRegexpPlus:
474319 case kRegexpQuest:
474320 case kRegexpEmptyMatch:
474321 case kRegexpNoMatch:
474322 return false;
474323 default:
474324 break;
474325 }
474326 return true;
474327 case kRegexpRepeat:
474328 return false;
474329 }
474330 LOG(DFATAL) << "Case not handled in ComputeSimple: " << op_;
474331 return false;
474332}

◆ StarPlusOrQuest()

Regexp * duckdb_re2::Regexp::StarPlusOrQuest ( RegexpOp op,
Regexp * sub,
ParseFlags flags )
staticprivate
473147 {
473148 // Squash **, ++ and ??.
473149 if (op == sub->op() && flags == sub->parse_flags())
473150 return sub;
473151
473152 // Squash *+, *?, +*, +?, ?* and ?+. They all squash to *, so because
473153 // op is Star/Plus/Quest, we just have to check that sub->op() is too.
473154 if ((sub->op() == kRegexpStar ||
473155 sub->op() == kRegexpPlus ||
473156 sub->op() == kRegexpQuest) &&
473157 flags == sub->parse_flags()) {
473158 // If sub is Star, no need to rewrite it.
473159 if (sub->op() == kRegexpStar)
473160 return sub;
473161
473162 // Rewrite sub to Star.
473163 Regexp* re = new Regexp(kRegexpStar, flags);
473164 re->AllocSub(1);
473165 re->sub()[0] = sub->sub()[0]->Incref();
473166 sub->Decref(); // We didn't consume the reference after all.
473167 return re;
473168 }
473169
473170 Regexp* re = new Regexp(op, flags);
473171 re->AllocSub(1);
473172 re->sub()[0] = sub;
473173 return re;
473174}

◆ ConcatOrAlternate()

Regexp * duckdb_re2::Regexp::ConcatOrAlternate ( RegexpOp op,
Regexp ** subs,
int nsubs,
ParseFlags flags,
bool can_factor )
staticprivate
473189 {
473190 if (nsub == 1)
473191 return sub[0];
473192
473193 if (nsub == 0) {
473194 if (op == kRegexpAlternate)
473195 return new Regexp(kRegexpNoMatch, flags);
473196 else
473197 return new Regexp(kRegexpEmptyMatch, flags);
473198 }
473199
473200 PODArray<Regexp*> subcopy;
473201 if (op == kRegexpAlternate && can_factor) {
473202 // Going to edit sub; make a copy so we don't step on caller.
473203 subcopy = PODArray<Regexp*>(nsub);
473204 memmove(subcopy.data(), sub, nsub * sizeof sub[0]);
473205 sub = subcopy.data();
473206 nsub = FactorAlternation(sub, nsub, flags);
473207 if (nsub == 1) {
473208 Regexp* re = sub[0];
473209 return re;
473210 }
473211 }
473212
473213 if (nsub > kMaxNsub) {
473214 // Too many subexpressions to fit in a single Regexp.
473215 // Make a two-level tree. Two levels gets us to 65535^2.
473216 int nbigsub = (nsub+kMaxNsub-1)/kMaxNsub;
473217 Regexp* re = new Regexp(op, flags);
473218 re->AllocSub(nbigsub);
473219 Regexp** subs = re->sub();
473220 for (int i = 0; i < nbigsub - 1; i++)
473221 subs[i] = ConcatOrAlternate(op, sub+i*kMaxNsub, kMaxNsub, flags, false);
473222 subs[nbigsub - 1] = ConcatOrAlternate(op, sub+(nbigsub-1)*kMaxNsub,
473223 nsub - (nbigsub-1)*kMaxNsub, flags,
473224 false);
473225 return re;
473226 }
473227
473228 Regexp* re = new Regexp(op, flags);
473229 re->AllocSub(nsub);
473230 Regexp** subs = re->sub();
473231 for (int i = 0; i < nsub; i++)
473232 subs[i] = sub[i];
473233 return re;
473234}

◆ LeadingString()

Rune * duckdb_re2::Regexp::LeadingString ( Regexp * re,
int * nrune,
Regexp::ParseFlags * flags )
staticprivate
467445 {
467446 while (re->op() == kRegexpConcat && re->nsub() > 0)
467447 re = re->sub()[0];
467448
467449 *flags = static_cast<Regexp::ParseFlags>(re->parse_flags_ & Regexp::FoldCase);
467450
467451 if (re->op() == kRegexpLiteral) {
467452 *nrune = 1;
467453 return &re->arguments.rune_;
467454 }
467455
467456 if (re->op() == kRegexpLiteralString) {
467457 *nrune = re->arguments.literal_string.nrunes_;
467458 return re->arguments.literal_string.runes_;
467459 }
467460
467461 *nrune = 0;
467462 return NULL;
467463}

◆ RemoveLeadingString()

void duckdb_re2::Regexp::RemoveLeadingString ( Regexp * re,
int n )
staticprivate
467467 {
467468 // Chase down concats to find first string.
467469 // For regexps generated by parser, nested concats are
467470 // flattened except when doing so would overflow the 16-bit
467471 // limit on the size of a concatenation, so we should never
467472 // see more than two here.
467473 Regexp* stk[4];
467474 size_t d = 0;
467475 while (re->op() == kRegexpConcat) {
467476 if (d < arraysize(stk))
467477 stk[d++] = re;
467478 re = re->sub()[0];
467479 }
467480
467481 // Remove leading string from re.
467482 if (re->op() == kRegexpLiteral) {
467483 re->arguments.rune_ = 0;
467484 re->op_ = kRegexpEmptyMatch;
467485 } else if (re->op() == kRegexpLiteralString) {
467486 if (n >= re->arguments.literal_string.nrunes_) {
467487 delete[] re->arguments.literal_string.runes_;
467488 re->arguments.literal_string.runes_ = NULL;
467489 re->arguments.literal_string.nrunes_ = 0;
467490 re->op_ = kRegexpEmptyMatch;
467491 } else if (n == re->arguments.literal_string.nrunes_ - 1) {
467492 Rune rune = re->arguments.literal_string.runes_[re->arguments.literal_string.nrunes_ - 1];
467493 delete[] re->arguments.literal_string.runes_;
467494 re->arguments.literal_string.runes_ = NULL;
467495 re->arguments.literal_string.nrunes_ = 0;
467496 re->arguments.rune_ = rune;
467497 re->op_ = kRegexpLiteral;
467498 } else {
467499 re->arguments.literal_string.nrunes_ -= n;
467500 memmove(re->arguments.literal_string.runes_, re->arguments.literal_string.runes_ + n, re->arguments.literal_string.nrunes_ * sizeof re->arguments.literal_string.runes_[0]);
467501 }
467502 }
467503
467504 // If re is now empty, concatenations might simplify too.
467505 while (d > 0) {
467506 re = stk[--d];
467507 Regexp** sub = re->sub();
467508 if (sub[0]->op() == kRegexpEmptyMatch) {
467509 sub[0]->Decref();
467510 sub[0] = NULL;
467511 // Delete first element of concat.
467512 switch (re->nsub()) {
467513 case 0:
467514 case 1:
467515 // Impossible.
467516 LOG(DFATAL) << "Concat of " << re->nsub();
467517 re->submany_ = NULL;
467518 re->op_ = kRegexpEmptyMatch;
467519 break;
467520
467521 case 2: {
467522 // Replace re with sub[1].
467523 Regexp* old = sub[1];
467524 sub[1] = NULL;
467525 re->Swap(old);
467526 old->Decref();
467527 break;
467528 }
467529
467530 default:
467531 // Slide down.
467532 re->nsub_--;
467533 memmove(sub, sub + 1, re->nsub_ * sizeof sub[0]);
467534 break;
467535 }
467536 }
467537 }
467538}

◆ LeadingRegexp()

Regexp * duckdb_re2::Regexp::LeadingRegexp ( Regexp * re)
staticprivate
467399 {
467400 if (re->op() == kRegexpEmptyMatch)
467401 return NULL;
467402 if (re->op() == kRegexpConcat && re->nsub() >= 2) {
467403 Regexp** sub = re->sub();
467404 if (sub[0]->op() == kRegexpEmptyMatch)
467405 return NULL;
467406 return sub[0];
467407 }
467408 return re;
467409}

◆ RemoveLeadingRegexp()

Regexp * duckdb_re2::Regexp::RemoveLeadingRegexp ( Regexp * re)
staticprivate
467415 {
467416 if (re->op() == kRegexpEmptyMatch)
467417 return re;
467418 if (re->op() == kRegexpConcat && re->nsub() >= 2) {
467419 Regexp** sub = re->sub();
467420 if (sub[0]->op() == kRegexpEmptyMatch)
467421 return re;
467422 sub[0]->Decref();
467423 sub[0] = NULL;
467424 if (re->nsub() == 2) {
467425 // Collapse concatenation to single regexp.
467426 Regexp* nre = sub[1];
467427 sub[1] = NULL;
467428 re->Decref();
467429 return nre;
467430 }
467431 // 3 or more -> 2 or more.
467432 re->nsub_--;
467433 memmove(sub, sub + 1, re->nsub_ * sizeof sub[0]);
467434 return re;
467435 }
467436 Regexp::ParseFlags pf = re->parse_flags();
467437 re->Decref();
467438 return new Regexp(kRegexpEmptyMatch, pf);
467439}

◆ FactorAlternation()

int duckdb_re2::Regexp::FactorAlternation ( Regexp ** sub,
int nsub,
ParseFlags flags )
staticprivate
467602 {
467603 std::vector<Frame> stk;
467604 stk.emplace_back(sub, nsub);
467605
467606 for (;;) {
467607 auto& sub = stk.back().sub;
467608 auto& nsub = stk.back().nsub;
467609 auto& round = stk.back().round;
467610 auto& splices = stk.back().splices;
467611 auto& spliceidx = stk.back().spliceidx;
467612
467613 if (splices.empty()) {
467614 // Advance to the next round of factoring. Note that this covers
467615 // the initialised state: when splices is empty and round is 0.
467616 round++;
467617 } else if (spliceidx < static_cast<int>(splices.size())) {
467618 // We have at least one more Splice to factor. Recurse logically.
467619 stk.emplace_back(splices[spliceidx].sub, splices[spliceidx].nsub);
467620 continue;
467621 } else {
467622 // We have no more Splices to factor. Apply them.
467623 auto iter = splices.begin();
467624 int out = 0;
467625 for (int i = 0; i < nsub; ) {
467626 // Copy until we reach where the next Splice begins.
467627 while (sub + i < iter->sub)
467628 sub[out++] = sub[i++];
467629 switch (round) {
467630 case 1:
467631 case 2: {
467632 // Assemble the Splice prefix and the suffixes.
467633 Regexp* re[2];
467634 re[0] = iter->prefix;
467635 re[1] = Regexp::AlternateNoFactor(iter->sub, iter->nsuffix, flags);
467636 sub[out++] = Regexp::Concat(re, 2, flags);
467637 i += iter->nsub;
467638 break;
467639 }
467640 case 3:
467641 // Just use the Splice prefix.
467642 sub[out++] = iter->prefix;
467643 i += iter->nsub;
467644 break;
467645 default:
467646 LOG(DFATAL) << "unknown round: " << round;
467647 break;
467648 }
467649 // If we are done, copy until the end of sub.
467650 if (++iter == splices.end()) {
467651 while (i < nsub)
467652 sub[out++] = sub[i++];
467653 }
467654 }
467655 splices.clear();
467656 nsub = out;
467657 // Advance to the next round of factoring.
467658 round++;
467659 }
467660
467661 switch (round) {
467662 case 1:
467663 FactorAlternationImpl::Round1(sub, nsub, flags, &splices);
467664 break;
467665 case 2:
467666 FactorAlternationImpl::Round2(sub, nsub, flags, &splices);
467667 break;
467668 case 3:
467669 FactorAlternationImpl::Round3(sub, nsub, flags, &splices);
467670 break;
467671 case 4:
467672 if (stk.size() == 1) {
467673 // We are at the top of the stack. Just return.
467674 return nsub;
467675 } else {
467676 // Pop the stack and set the number of suffixes.
467677 // (Note that references will be invalidated!)
467678 int nsuffix = nsub;
467679 stk.pop_back();
467680 stk.back().splices[stk.back().spliceidx].nsuffix = nsuffix;
467681 ++stk.back().spliceidx;
467682 continue;
467683 }
467684 default:
467685 LOG(DFATAL) << "unknown round: " << round;
467686 break;
467687 }
467688
467689 // Set spliceidx depending on whether we have Splices to factor.
467690 if (splices.empty() || round == 3) {
467691 spliceidx = static_cast<int>(splices.size());
467692 } else {
467693 spliceidx = 0;
467694 }
467695 }
467696}

◆ Equal()

bool duckdb_re2::Regexp::Equal ( Regexp * a,
Regexp * b )
staticprivate
473365 {
473366 if (a == NULL || b == NULL)
473367 return a == b;
473368
473369 if (!TopEqual(a, b))
473370 return false;
473371
473372 // Fast path:
473373 // return without allocating vector if there are no subregexps.
473374 switch (a->op()) {
473375 case kRegexpAlternate:
473376 case kRegexpConcat:
473377 case kRegexpStar:
473378 case kRegexpPlus:
473379 case kRegexpQuest:
473380 case kRegexpRepeat:
473381 case kRegexpCapture:
473382 break;
473383
473384 default:
473385 return true;
473386 }
473387
473388 // Committed to doing real work.
473389 // The stack (vector) has pairs of regexps waiting to
473390 // be compared. The regexps are only equal if
473391 // all the pairs end up being equal.
473392 std::vector<Regexp*> stk;
473393
473394 for (;;) {
473395 // Invariant: TopEqual(a, b) == true.
473396 Regexp* a2;
473397 Regexp* b2;
473398 switch (a->op()) {
473399 default:
473400 break;
473401 case kRegexpAlternate:
473402 case kRegexpConcat:
473403 for (int i = 0; i < a->nsub(); i++) {
473404 a2 = a->sub()[i];
473405 b2 = b->sub()[i];
473406 if (!TopEqual(a2, b2))
473407 return false;
473408 stk.push_back(a2);
473409 stk.push_back(b2);
473410 }
473411 break;
473412
473413 case kRegexpStar:
473414 case kRegexpPlus:
473415 case kRegexpQuest:
473416 case kRegexpRepeat:
473417 case kRegexpCapture:
473418 a2 = a->sub()[0];
473419 b2 = b->sub()[0];
473420 if (!TopEqual(a2, b2))
473421 return false;
473422 // Really:
473423 // stk.push_back(a2);
473424 // stk.push_back(b2);
473425 // break;
473426 // but faster to assign directly and loop.
473427 a = a2;
473428 b = b2;
473429 continue;
473430 }
473431
473432 size_t n = stk.size();
473433 if (n == 0)
473434 break;
473435
473436 DCHECK_GE(n, 2);
473437 a = stk[n-2];
473438 b = stk[n-1];
473439 stk.resize(n-2);
473440 }
473441
473442 return true;
473443}

◆ AllocSub()

void duckdb_re2::Regexp::AllocSub ( int n)
inlineprivate
322724 {
322725 DCHECK(n >= 0 && static_cast<uint16_t>(n) == n);
322726 if (n > 1)
322727 submany_ = new Regexp*[n];
322728 nsub_ = static_cast<uint16_t>(n);
322729 }

◆ AddRuneToString()

void duckdb_re2::Regexp::AddRuneToString ( Rune r)
private
473124 {
473125 DCHECK(op_ == kRegexpLiteralString);
473126 if (arguments.literal_string.nrunes_ == 0) {
473127 // start with 8
473128 arguments.literal_string.runes_ = new Rune[8];
473129 } else if (arguments.literal_string.nrunes_ >= 8 && (arguments.literal_string.nrunes_ & (arguments.literal_string.nrunes_ - 1)) == 0) {
473130 // double on powers of two
473131 Rune *old = arguments.literal_string.runes_;
473132 arguments.literal_string.runes_ = new Rune[arguments.literal_string.nrunes_ * 2];
473133 for (int i = 0; i < arguments.literal_string.nrunes_; i++)
473134 arguments.literal_string.runes_[i] = old[i];
473135 delete[] old;
473136 }
473137
473138 arguments.literal_string.runes_[arguments.literal_string.nrunes_++] = r;
473139}

◆ Swap()

void duckdb_re2::Regexp::Swap ( Regexp * that)
private
473288 {
473289 // Regexp is not trivially copyable, so we cannot freely copy it with
473290 // memmove(3), but swapping objects like so is safe for our purposes.
473291 char tmp[sizeof *this];
473292 void* vthis = reinterpret_cast<void*>(this);
473293 void* vthat = reinterpret_cast<void*>(that);
473294 memmove(tmp, vthis, sizeof *this);
473295 memmove(vthis, vthat, sizeof *this);
473296 memmove(vthat, tmp, sizeof *this);
473297}

The documentation for this class was generated from the following file: