Changeset: 716959cb9b27 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/716959cb9b27
Modified Files:
        clients/Tests/MAL-signatures-hge.test
        clients/Tests/MAL-signatures.test
        monetdb5/modules/mal/pcre.c
Branch: Jan2022
Log Message:

pcre.replace_first should replace only the *first* match, not all matches.


diffs (49 lines):

diff --git a/clients/Tests/MAL-signatures-hge.test 
b/clients/Tests/MAL-signatures-hge.test
--- a/clients/Tests/MAL-signatures-hge.test
+++ b/clients/Tests/MAL-signatures-hge.test
@@ -62370,7 +62370,7 @@ Replace _all_ matches of "pattern" in "o
 pcre
 replace_first
 command pcre.replace_first(X_0:str, X_1:str, X_2:str, X_3:str):str 
-PCREreplace_wrap;
+PCREreplacefirst_wrap;
 Replace _the first_ match of "pattern" in "origin_str" with 
"replacement".@Parameter "flags" accept these flags: 'i', 'm', 's', and 
'x'.@'e': if present, an empty string is considered to be a valid match@'i': if 
present, the match operates in case-insensitive mode.@Otherwise, in 
case-sensitive mode.@'m': if present, the match operates in multi-line 
mode.@'s': if present, the match operates in "dot-all"@The specifications of 
the flags can be found in "man pcreapi"@The flag letters may be repeated.@No 
other letters than 'e', 'i', 'm', 's' and 'x' are allowed in "flags".@Returns 
the replaced string, or if no matches found, the original string.
 pcre
 sql2pcre
diff --git a/clients/Tests/MAL-signatures.test 
b/clients/Tests/MAL-signatures.test
--- a/clients/Tests/MAL-signatures.test
+++ b/clients/Tests/MAL-signatures.test
@@ -45870,7 +45870,7 @@ Replace _all_ matches of "pattern" in "o
 pcre
 replace_first
 command pcre.replace_first(X_0:str, X_1:str, X_2:str, X_3:str):str 
-PCREreplace_wrap;
+PCREreplacefirst_wrap;
 Replace _the first_ match of "pattern" in "origin_str" with 
"replacement".@Parameter "flags" accept these flags: 'i', 'm', 's', and 
'x'.@'e': if present, an empty string is considered to be a valid match@'i': if 
present, the match operates in case-insensitive mode.@Otherwise, in 
case-sensitive mode.@'m': if present, the match operates in multi-line 
mode.@'s': if present, the match operates in "dot-all"@The specifications of 
the flags can be found in "man pcreapi"@The flag letters may be repeated.@No 
other letters than 'e', 'i', 'm', 's' and 'x' are allowed in "flags".@Returns 
the replaced string, or if no matches found, the original string.
 pcre
 sql2pcre
diff --git a/monetdb5/modules/mal/pcre.c b/monetdb5/modules/mal/pcre.c
--- a/monetdb5/modules/mal/pcre.c
+++ b/monetdb5/modules/mal/pcre.c
@@ -1164,6 +1164,12 @@ PCREreplace_wrap(str *res, const str *or
 }
 
 static str
+PCREreplacefirst_wrap(str *res, const str *or, const str *pat, const str 
*repl, const str *flags)
+{
+       return pcre_replace(res, *or, *pat, *repl, *flags, false);
+}
+
+static str
 PCREreplace_bat_wrap(bat *res, const bat *bid, const str *pat, const str 
*repl, const str *flags)
 {
        BAT *b, *bn = NULL;
@@ -2328,7 +2334,7 @@ mel_func pcre_init_funcs[] = {
  command("pcre", "imatch", PCREimatch, false, "Caseless Perl Compatible 
Regular Expression pattern matching against a string", args(1,3, 
arg("",bit),arg("s",str),arg("pat",str))),
  command("pcre", "patindex", PCREpatindex, false, "Location of the first POSIX 
pattern matching against a string", args(1,3, 
arg("",int),arg("pat",str),arg("s",str))),
  command("pcre", "replace", PCREreplace_wrap, false, "Replace _all_ matches of 
\"pattern\" in \"origin_str\" with \"replacement\".\nParameter \"flags\" accept 
these flags: 'i', 'm', 's', and 'x'.\n'e': if present, an empty string is 
considered to be a valid match\n'i': if present, the match operates in 
case-insensitive mode.\nOtherwise, in case-sensitive mode.\n'm': if present, 
the match operates in multi-line mode.\n's': if present, the match operates in 
\"dot-all\"\nThe specifications of the flags can be found in \"man 
pcreapi\"\nThe flag letters may be repeated.\nNo other letters than 'e', 'i', 
'm', 's' and 'x' are allowed in \"flags\".\nReturns the replaced string, or if 
no matches found, the original string.", args(1,5, 
arg("",str),arg("origin",str),arg("pat",str),arg("repl",str),arg("flags",str))),
- command("pcre", "replace_first", PCREreplace_wrap, false, "Replace _the 
first_ match of \"pattern\" in \"origin_str\" with \"replacement\".\nParameter 
\"flags\" accept these flags: 'i', 'm', 's', and 'x'.\n'e': if present, an 
empty string is considered to be a valid match\n'i': if present, the match 
operates in case-insensitive mode.\nOtherwise, in case-sensitive mode.\n'm': if 
present, the match operates in multi-line mode.\n's': if present, the match 
operates in \"dot-all\"\nThe specifications of the flags can be found in \"man 
pcreapi\"\nThe flag letters may be repeated.\nNo other letters than 'e', 'i', 
'm', 's' and 'x' are allowed in \"flags\".\nReturns the replaced string, or if 
no matches found, the original string.", args(1,5, 
arg("",str),arg("origin",str),arg("pat",str),arg("repl",str),arg("flags",str))),
+ command("pcre", "replace_first", PCREreplacefirst_wrap, false, "Replace _the 
first_ match of \"pattern\" in \"origin_str\" with \"replacement\".\nParameter 
\"flags\" accept these flags: 'i', 'm', 's', and 'x'.\n'e': if present, an 
empty string is considered to be a valid match\n'i': if present, the match 
operates in case-insensitive mode.\nOtherwise, in case-sensitive mode.\n'm': if 
present, the match operates in multi-line mode.\n's': if present, the match 
operates in \"dot-all\"\nThe specifications of the flags can be found in \"man 
pcreapi\"\nThe flag letters may be repeated.\nNo other letters than 'e', 'i', 
'm', 's' and 'x' are allowed in \"flags\".\nReturns the replaced string, or if 
no matches found, the original string.", args(1,5, 
arg("",str),arg("origin",str),arg("pat",str),arg("repl",str),arg("flags",str))),
  command("pcre", "pcre_quote", PCREquote, false, "Return a PCRE pattern string 
that matches the argument exactly.", args(1,2, arg("",str),arg("s",str))),
  command("pcre", "sql2pcre", PCREsql2pcre, false, "Convert a SQL like pattern 
with the given escape character into a PCRE pattern.", args(1,3, 
arg("",str),arg("pat",str),arg("esc",str))),
  command("pcre", "prelude", pcre_init, false, "Initialize pcre", args(1,1, 
arg("",void))),
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to