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

Function replace_regex_scan_cb

src/arithmetic/string_funcs/string_funcs.c:378–400  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

376} replace_regex_scan_cb_args;
377
378static int replace_regex_scan_cb(int n, int pos, OnigRegion *region, void *arg) {
379 replace_regex_scan_cb_args *args = (replace_regex_scan_cb_args *)arg;
380 const char *str = args->str;
381 assert(region->num_regs > 0);
382
383 // reallocate new str size
384 int str_copy_len = region->beg[0] - args->str_ind;
385 int str_size = args->res_len + str_copy_len + args->replacement_len + 1;
386 args->res = rm_realloc(args->res, str_size);
387
388 // copy the string between the last match and the current match
389 memcpy(args->res + args->res_len, str + args->str_ind, str_copy_len);
390 args->str_ind = region->end[0];
391 args->res_len += str_copy_len;
392
393 // copy the replacement string
394 memcpy(args->res + args->res_len, args->replacement, args->replacement_len);
395 args->res_len += args->replacement_len;
396
397 args->res[args->res_len] = '\0';
398
399 return 0;
400}
401
402// given a string and a regular expression,
403// return a string after replacing each regex match with a given replacement.

Callers

nothing calls this directly

Calls 1

rm_reallocFunction · 0.85

Tested by

no test coverage detected