MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / str_MatchRegex

Function str_MatchRegex

src/util/strutil.c:149–189  ·  view source on GitHub ↗

Utility function to check if the string matches the regex pattern.

Source from the content-addressed store, hash-verified

147// Utility function to check if the string matches
148// the regex pattern.
149bool str_MatchRegex
150(
151 const char* regex, // regex pattern to match with
152 const char* str // string to match
153) {
154 const int len = strlen(str);
155 regex_t *reg;
156 OnigErrorInfo einfo;
157 OnigRegion *region = onig_region_new();
158
159 bool match = true;
160
161 int rv = onig_new(&reg, (const UChar *)regex,
162 (const UChar *)(regex + strlen(regex)), ONIG_OPTION_DEFAULT,
163 ONIG_ENCODING_UTF8, ONIG_SYNTAX_JAVA, &einfo);
164 if(unlikely(rv != ONIG_NORMAL)) {
165 ASSERT(rv == ONIG_NORMAL);
166 onig_free(reg);
167 onig_region_free(region, 1);
168 return false;
169 }
170
171 rv = onig_search(reg, (const UChar*)str, (UChar* )(str + len),
172 (const UChar* )str, (const UChar* )(str + len),
173 region, ONIG_OPTION_NONE);
174 if (rv < ONIG_MISMATCH) {
175 ASSERT(rv >= ONIG_MISMATCH);
176 onig_free(reg);
177 onig_region_free(region, 1);
178 return false;
179 }
180
181 if (rv == ONIG_MISMATCH || region->beg[0] != 0 || region->end[0] != len) {
182 match = false;
183 }
184
185 onig_free(reg);
186 onig_region_free(region, 1);
187
188 return match;
189}

Callers 2

Constraint_ParseFunction · 0.85
Graph_ConstraintFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected