48 fprintf(stderr,
"Runtime type error: REGEX_SEARCH expects (string, string)\n");
80 enum { MAX_CAP = 16 };
81 regmatch_t caps[MAX_CAP];
82 int ok = regexec(&rx,
str.s ?
str.s :
"", MAX_CAP, caps, 0) == 0;
91 int s = (int)caps[0].rm_so;
92 int e = (int)caps[0].rm_eo;
93 char *matchStr = NULL;
94 if (
str.s &&
s >= 0 && e >=
s) {
96 matchStr = (
char *)malloc((
size_t)
len + 1);
98 memcpy(matchStr,
str.s +
s, (
size_t)
len);
103 if (matchStr)
free(matchStr);
110 for (
int i = 1; i < MAX_CAP; ++i) {
111 if (caps[i].rm_so == -1 || caps[i].rm_eo == -1)
break;
114 if (groupCount > 0) {
117 for (
int i = 1; i <= groupCount; ++i) {
118 int gs = (int)caps[i].rm_so;
119 int ge = (int)caps[i].rm_eo;
121 if (
str.s && gs >= 0 && ge >= gs) {
123 gstr = (
char *)malloc((
size_t)gl + 1);
125 memcpy(gstr,
str.s + gs, (
size_t)gl);
130 if (gstr)
free(gstr);
133 for (
int i = 0; i < groupCount; ++i)
137 (void)
map_set(&outMap,
"groups", groupsArr);
int map_set(Value *vm, const char *key, Value v)
Insert or replace a key in the map.
Value make_map_empty(void)
Construct a new empty map Value.
Tagged union representing a Fun value.
Value make_string(const char *s)
Construct a string Value by duplicating the given C string.
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Value make_array_from_values(const Value *vals, int count)
Create an array Value by copying items from an input span.