void OrderedOfString_changeStrings (OrderedOfString me, wchar_t *search, wchar_t *replace, int maximumNumberOfReplaces, long *nmatches, long *nstringmatches, int use_regexp) { regexp *compiled_search = NULL; try { const wchar_t *compileMsg; wchar_t *r; if (search == NULL) { Melder_throw ("Missing search string."); } if (replace == NULL) { Melder_throw ("Missing replace string."); } if (use_regexp) { compiled_search = CompileRE ( (regularExp_CHAR *) search, &compileMsg, 0); if (compiled_search == NULL) { Melder_throw (compileMsg); } } for (long i = 1; i <= my size; i++) { SimpleString ss = (SimpleString) my item[i]; long nmatches_sub; if (use_regexp) { r = str_replace_regexp (ss -> string, compiled_search, replace, maximumNumberOfReplaces, &nmatches_sub); } else r = str_replace_literal (ss -> string, search, replace, maximumNumberOfReplaces, &nmatches_sub); // Change without error: Melder_free (ss -> string); ss -> string = r; if (nmatches_sub > 0) { *nmatches += nmatches_sub; (*nstringmatches) ++; } } if (use_regexp) { free (compiled_search); } } catch (MelderError) { if (use_regexp) { free (compiled_search); } Melder_throw ("Replace not completed."); } }
void OrderedOfString_changeStrings (OrderedOfString me, char32 *search, char32 *replace, int maximumNumberOfReplaces, long *nmatches, long *nstringmatches, int use_regexp) { regexp *compiled_search = nullptr; try { if (! search) { Melder_throw (U"Missing search string."); } if (! replace) { Melder_throw (U"Missing replace string."); } if (use_regexp) { compiled_search = CompileRE_throwable (search, 0); } for (long i = 1; i <= my size; i++) { SimpleString ss = (SimpleString) my item[i]; long nmatches_sub; char32 *r = use_regexp ? str_replace_regexp (ss -> string, compiled_search, replace, maximumNumberOfReplaces, &nmatches_sub) : str_replace_literal (ss -> string, search, replace, maximumNumberOfReplaces, &nmatches_sub); // Change without error: Melder_free (ss -> string); ss -> string = r; if (nmatches_sub > 0) { *nmatches += nmatches_sub; (*nstringmatches) ++; } } if (use_regexp) { free (compiled_search); } } catch (MelderError) { if (use_regexp) { free (compiled_search); } Melder_throw (U"Replace not completed."); } }