=> 11e7a3bdbb4b40ea4417518dac9eba7ad55748d3
[1mdiff --git a/include/the_Foundation/string.h b/include/the_Foundation/string.h[m [1mindex e158fe2..a09cf1c 100644[m [1m--- a/include/the_Foundation/string.h[m [1m+++ b/include/the_Foundation/string.h[m [36m@@ -85,6 +85,10 @@[m [miDeclareType(StringList)[m iDeclareType(StringComparison)[m iDeclareType(MultibyteChar)[m iDeclareType(Stream)[m [32m+[m[32m#if defined (iHaveRegExp)[m [32m+[m[32m iDeclareType(RegExp)[m [32m+[m[32m iDeclareType(RegExpMatch)[m [32m+[m[32m#endif[m [m struct Impl_StringComparison {[m int (*cmp) (const char *, const char *);[m [36m@@ -264,6 +268,28 @@[m [miString * trimmed_String (const iString *);[m void replace_String (iString *, const char *src, const char *dst);[m void normalize_String (iString *); /* NFC */[m [m [32m+[m[32m#if defined (iHaveRegExp)[m [32m+[m[32m/**[m [32m+[m[32m * Replace all matches of a regular expression in the string.[m [32m+[m[32m *[m [32m+[m[32m * @param regexp Regular expression to search for.[m [32m+[m[32m * @param replacement String to substitute at each match. Use the `\1` syntax to refer[m [32m+[m[32m * to a capture group. `\0` refers to the entire match.[m [32m+[m[32m * Backslashes must be escaped: `\\`. Must not be NULL.[m [32m+[m[32m * @param matchHandler In addition to replacing with @a replacement, call this callback[m [32m+[m[32m * for each match. Do not modify the String in the callback.[m [32m+[m[32m * Can be NULL.[m [32m+[m[32m * @param context User-provided pointer to pass as the first argument of[m [32m+[m[32m * @a matchHandler[m [32m+[m[32m *[m [32m+[m[32m * @return Number of replaced matches.[m [32m+[m[32m */[m [32m+[m[32mint replaceRegExp_String (iString *, const iRegExp *regexp,[m [32m+[m[32m const char *replacement,[m [32m+[m[32m void (*matchHandler)(void *, const iRegExpMatch *),[m [32m+[m[32m void *context);[m [32m+[m[32m#endif[m [32m+[m int toInt_String (const iString *);[m float toFloat_String (const iString *);[m double toDouble_String (const iString *);[m [1mdiff --git a/src/string.c b/src/string.c[m [1mindex fc7a377..7db513e 100644[m [1m--- a/src/string.c[m [1m+++ b/src/string.c[m [36m@@ -30,6 +30,10 @@[m [mSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.[m #include "the_Foundation/range.h"[m #include "the_Foundation/stdthreads.h"[m [m [32m+[m[32m#if defined (iHaveRegExp)[m [32m+[m[32m# include "the_Foundation/regexp.h"[m [32m+[m[32m#endif[m [32m+[m #include[m #include [m #include [m [36m@@ -374,6 +378,46 @@[m [mvoid replace_String(iString *d, const char *src, const char *dst) {[m }[m }[m [m [32m+[m[32m#if defined (iHaveRegExp)[m [32m+[m[32mint replaceRegExp_String(iString *d, const iRegExp *regexp, const char *replacement,[m [32m+[m[32m void (*matchHandler)(void *, const iRegExpMatch *),[m [32m+[m[32m void *context) {[m [32m+[m[32m iRegExpMatch m;[m [32m+[m[32m iString result;[m [32m+[m[32m int numMatches = 0;[m [32m+[m[32m const char *pos = constBegin_String(d);[m [32m+[m[32m init_RegExpMatch(&m);[m [32m+[m[32m init_String(&result);[m [32m+[m[32m while (matchString_RegExp(regexp, d, &m)) {[m [32m+[m[32m appendRange_String(&result, (iRangecc){ pos, begin_RegExpMatch(&m) });[m [32m+[m[32m /* Replace any capture group back-references. */[m [32m+[m[32m for (const char *ch = replacement; *ch; ch++) {[m [32m+[m[32m if (*ch == '\\') {[m [32m+[m[32m ch++;[m [32m+[m[32m if (*ch == '\\') {[m [32m+[m[32m appendCStr_String(&result, "\\");[m [32m+[m[32m }[m [32m+[m[32m else if (*ch >= '0' && *ch <= '9') {[m [32m+[m[32m appendRange_String(&result, capturedRange_RegExpMatch(&m, *ch - '0'));[m [32m+[m[32m }[m [32m+[m[32m }[m [32m+[m[32m else {[m [32m+[m[32m appendData_Block(&result.chars, ch, 1);[m [32m+[m[32m }[m [32m+[m[32m }[m [32m+[m[32m if (matchHandler) {[m [32m+[m[32m matchHandler(context, &m);[m [32m+[m[32m }[m [32m+[m[32m pos = end_RegExpMatch(&m);[m [32m+[m[32m numMatches++;[m [32m+[m[32m }[m [32m+[m[32m appendRange_String(&result, (iRangecc){ pos, constEnd_String(d) });[m [32m+[m[32m set_String(d, &result);[m [32m+[m[32m deinit_String(&result);[m [32m+[m[32m return numMatches;[m [32m+[m[32m}[m [32m+[m[32m#endif[m [32m+[m void normalize_String(iString *d) {[m size_t len = 0;[m uint8_t *nfc =[m [36m@@ -498,7 +542,7 @@[m [miString *urlEncode_String(const iString *d) {[m }[m [m iString *maybeUrlEncodeExclude_String(const iString *d, const char *excluded) {[m [31m- /* TODO: Return NULL if nothing to encode. */ [m [32m+[m[32m /* TODO: Return NULL if nothing to encode. */[m iString *encoded = new_String();[m /* Note: Any UTF-8 code points are encoded as multiple %NN sequences. */[m for (const char *i = constBegin_String(d), *end = constEnd_String(d); i != end; ++i) {[m [36m@@ -514,7 +558,7 @@[m [miString *maybeUrlEncodeExclude_String(const iString *d, const char *excluded) {[m appendCStrN_String(encoded, escaped, 3);[m }[m }[m [31m- return encoded; [m [32m+[m[32m return encoded;[m }[m [m static int fromHex_(char ch) {[m [36m@@ -547,7 +591,7 @@[m [miString *maybeUrlDecodeExclude_String(const iString *d, const char *excluded) {[m }[m appendData_Block(&decoded->chars, i, 1);[m }[m [31m- return decoded; [m [32m+[m[32m return decoded;[m }[m [m iString *urlDecodeExclude_String(const iString *d, const char *excluded) {[m
text/gemini; charset=utf-8
This content has been proxied by September (ba2dc).