MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / DumpRegexpAppending

Function DumpRegexpAppending

extern/re2/re2/testing/dump.cc:57–151  ·  view source on GitHub ↗

Create string representation of regexp with explicit structure. Nothing pretty, just for testing.

Source from the content-addressed store, hash-verified

55// Create string representation of regexp with explicit structure.
56// Nothing pretty, just for testing.
57static void DumpRegexpAppending(Regexp* re, std::string* s) {
58 if (re->op() < 0 || re->op() >= arraysize(kOpcodeNames)) {
59 *s += StringPrintf("op%d", re->op());
60 } else {
61 switch (re->op()) {
62 default:
63 break;
64 case kRegexpStar:
65 case kRegexpPlus:
66 case kRegexpQuest:
67 case kRegexpRepeat:
68 if (re->parse_flags() & Regexp::NonGreedy)
69 s->append("n");
70 break;
71 }
72 s->append(kOpcodeNames[re->op()]);
73 if (re->op() == kRegexpLiteral && (re->parse_flags() & Regexp::FoldCase)) {
74 Rune r = re->rune();
75 if ('a' <= r && r <= 'z')
76 s->append("fold");
77 }
78 if (re->op() == kRegexpLiteralString && (re->parse_flags() & Regexp::FoldCase)) {
79 for (int i = 0; i < re->nrunes(); i++) {
80 Rune r = re->runes()[i];
81 if ('a' <= r && r <= 'z') {
82 s->append("fold");
83 break;
84 }
85 }
86 }
87 }
88 s->append("{");
89 switch (re->op()) {
90 default:
91 break;
92 case kRegexpEndText:
93 if (!(re->parse_flags() & Regexp::WasDollar)) {
94 s->append("\\z");
95 }
96 break;
97 case kRegexpLiteral: {
98 Rune r = re->rune();
99 char buf[UTFmax+1];
100 buf[runetochar(buf, &r)] = 0;
101 s->append(buf);
102 break;
103 }
104 case kRegexpLiteralString:
105 for (int i = 0; i < re->nrunes(); i++) {
106 Rune r = re->runes()[i];
107 char buf[UTFmax+1];
108 buf[runetochar(buf, &r)] = 0;
109 s->append(buf);
110 }
111 break;
112 case kRegexpConcat:
113 case kRegexpAlternate:
114 for (int i = 0; i < re->nsub(); i++)

Callers 1

DumpMethod · 0.85

Calls 15

StringPrintfFunction · 0.85
runetocharFunction · 0.85
parse_flagsMethod · 0.80
runeMethod · 0.80
nrunesMethod · 0.80
runesMethod · 0.80
nsubMethod · 0.80
minMethod · 0.80
maxMethod · 0.80
opMethod · 0.45
appendMethod · 0.45
subMethod · 0.45

Tested by

no test coverage detected