MCPcopy Create free account
hub / github.com/ElementsProject/lightning / code_to_regex

Function code_to_regex

tools/check-bolt.c:137–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135}
136
137static char *code_to_regex(const char *code, size_t len, bool escape)
138{
139 char *pattern = tal_arr(NULL, char, len*2 + 1), *p;
140 size_t i;
141 bool after_nl = true;
142
143 /* We swallow '*' if first in line: block comments */
144 p = pattern;
145 for (i = 0; i < len; i++) {
146 /* ... matches anything. */
147 if (strstarts(code + i, "...")) {
148 *(p++) = '.';
149 *(p++) = '*';
150 i += 2;
151 continue;
152 }
153
154 switch (code[i]) {
155 case '\n':
156 after_nl = true;
157 *(p++) = code[i];
158 break;
159
160 case '*':
161 if (after_nl) {
162 after_nl = false;
163 continue;
164 }
165 /* Fall through. */
166 case '.':
167 case '$':
168 case '^':
169 case '[':
170 case ']':
171 case '{':
172 case '}':
173 case '(':
174 case ')':
175 case '+':
176 case '|':
177 if (escape)
178 *(p++) = '\\';
179 /* Fall through */
180 default:
181 *(p++) = code[i];
182 }
183 }
184 *p = '\0';
185 return canonicalize(pattern);
186}
187
188/* Moves *pos to start of line. */
189static unsigned linenum(const char *raw, const char **pos)

Callers 2

fail_mismatchFunction · 0.85
mainFunction · 0.85

Calls 1

canonicalizeFunction · 0.85

Tested by

no test coverage detected