summaryrefslogtreecommitdiff
path: root/src/gmutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gmutil.c')
-rw-r--r--src/gmutil.c37
1 files changed, 0 insertions, 37 deletions
diff --git a/src/gmutil.c b/src/gmutil.c
index 6c2271d7..0573aac1 100644
--- a/src/gmutil.c
+++ b/src/gmutil.c
@@ -930,40 +930,3 @@ const iGmError *get_GmError(enum iGmStatusCode code) {
930 return &errors_[0].err; /* unknown */ 930 return &errors_[0].err; /* unknown */
931} 931}
932 932
933int replaceRegExp_String(iString *d, const iRegExp *regexp, const char *replacement,
934 void (*matchHandler)(void *, const iRegExpMatch *),
935 void *context) {
936 iRegExpMatch m;
937 iString result;
938 int numMatches = 0;
939 const char *pos = constBegin_String(d);
940 init_RegExpMatch(&m);
941 init_String(&result);
942 while (matchString_RegExp(regexp, d, &m)) {
943 appendRange_String(&result, (iRangecc){ pos, begin_RegExpMatch(&m) });
944 /* Replace any capture group back-references. */
945 for (const char *ch = replacement; *ch; ch++) {
946 if (*ch == '\\') {
947 ch++;
948 if (*ch == '\\') {
949 appendCStr_String(&result, "\\");
950 }
951 else if (*ch >= '0' && *ch <= '9') {
952 appendRange_String(&result, capturedRange_RegExpMatch(&m, *ch - '0'));
953 }
954 }
955 else {
956 appendData_Block(&result.chars, ch, 1);
957 }
958 }
959 if (matchHandler) {
960 matchHandler(context, &m);
961 }
962 pos = end_RegExpMatch(&m);
963 numMatches++;
964 }
965 appendRange_String(&result, (iRangecc){ pos, constEnd_String(d) });
966 set_String(d, &result);
967 deinit_String(&result);
968 return numMatches;
969}