diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2022-02-14 15:04:16 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2022-02-14 15:04:16 +0200 |
commit | d19691de189227ef1976cb8104cdc55830fdb347 (patch) | |
tree | 966ee2fd2a41aaa861d29d77386e0db08aa5c76c /src | |
parent | 2a5e0219e70dfd1f266c9697c2fc00f3b332e49f (diff) |
Moved a function to the_Foundation
Diffstat (limited to 'src')
-rw-r--r-- | src/gmutil.c | 37 | ||||
-rw-r--r-- | src/gmutil.h | 5 |
2 files changed, 0 insertions, 42 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 | ||
933 | int 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 | } | ||
diff --git a/src/gmutil.h b/src/gmutil.h index 9217b0e3..c9d7baae 100644 --- a/src/gmutil.h +++ b/src/gmutil.h | |||
@@ -151,8 +151,3 @@ const iString * findContainerArchive_Path (const iString *path); | |||
151 | 151 | ||
152 | 152 | ||
153 | const iString * feedEntryOpenCommand_String (const iString *url, int newTab); /* checks fragment */ | 153 | const iString * feedEntryOpenCommand_String (const iString *url, int newTab); /* checks fragment */ |
154 | |||
155 | /* TODO: Consider adding this to the_Foundation. */ | ||
156 | int replaceRegExp_String (iString *, const iRegExp *regexp, const char *replacement, | ||
157 | void (*matchHandler)(void *, const iRegExpMatch *), | ||
158 | void *context); | ||