Changeset: bbfede0c3cb4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/bbfede0c3cb4
Modified Files:
clients/Tests/MAL-signatures-hge.test
clients/Tests/MAL-signatures.test
monetdb5/modules/atoms/str.c
Branch: txtsim
Log Message:
Improve startsWith, endsWith, contains(search) ~bat versions.
diffs (truncated from 343 to 300 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
@@ -50431,8 +50431,13 @@ Transform string from UTF8 to ASCII
str
endsWith
command str.endsWith(X_0:str, X_1:str):bit
-STRSuffix;
-Suffix check.
+STRendsWith;
+Check if string ends with substring.
+str
+endsWith
+pattern str.endsWith(X_0:str, X_1:str, X_2:bit):bit
+STRendsWith;
+Check if string ends with substring, case insensitive flag.
str
epilogue
command str.epilogue():void
@@ -50549,6 +50554,11 @@ command str.search(X_0:str, X_1:str):int
STRstrSearch;
Search for a substring. Returns@position, -1 if not found.
str
+search
+command str.search(X_0:str, X_1:str, X_2:bit):int
+STRstrSearch;
+Search for a substring, case insensitive flag. Returns@position, -1 if not
found.
+str
space
command str.space(X_0:int):str
STRspace;
@@ -50561,8 +50571,13 @@ Split string on delimiter. Returns@given
str
startsWith
command str.startsWith(X_0:str, X_1:str):bit
-STRPrefix;
-Prefix check.
+STRstartsWith;
+Check if string starts with substring.
+str
+startsWith
+command str.startsWith(X_0:str, X_1:str, X_2:bit):bit
+STRstartsWith;
+Check if string starts with substring, case insensitive flag.
str
str
command str.str(X_0:str):str
@@ -50611,12 +50626,12 @@ Extract the suffix of a given length
str
toLower
command str.toLower(X_0:str):str
-STRLower;
+STRlower;
Convert a string to lower case.
str
toUpper
command str.toUpper(X_0:str):str
-STRUpper;
+STRupper;
Convert a string to upper case.
str
trim
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
@@ -38756,8 +38756,13 @@ Transform string from UTF8 to ASCII
str
endsWith
command str.endsWith(X_0:str, X_1:str):bit
-STRSuffix;
-Suffix check.
+STRendsWith;
+Check if string ends with substring.
+str
+endsWith
+pattern str.endsWith(X_0:str, X_1:str, X_2:bit):bit
+STRendsWith;
+Check if string ends with substring, case insensitive flag.
str
epilogue
command str.epilogue():void
@@ -38874,6 +38879,11 @@ command str.search(X_0:str, X_1:str):int
STRstrSearch;
Search for a substring. Returns@position, -1 if not found.
str
+search
+command str.search(X_0:str, X_1:str, X_2:bit):int
+STRstrSearch;
+Search for a substring, case insensitive flag. Returns@position, -1 if not
found.
+str
space
command str.space(X_0:int):str
STRspace;
@@ -38885,9 +38895,14 @@ STRsplitpart;
Split string on delimiter. Returns@given field (counting from one.)
str
startsWith
-command str.startsWith(X_0:str, X_1:str):bit
-STRPrefix;
-Prefix check.
+pattern str.startsWith(X_0:str, X_1:str):bit
+STRstartsWith;
+Check if string starts with substring.
+str
+startsWith
+pattern str.startsWith(X_0:str, X_1:str, X_2:bit):bit
+STRstartsWith;
+Check if string starts with substring, case insensitive flag.
str
str
command str.str(X_0:str):str
@@ -38936,12 +38951,12 @@ Extract the suffix of a given length
str
toLower
command str.toLower(X_0:str):str
-STRLower;
+STRlower;
Convert a string to lower case.
str
toUpper
command str.toUpper(X_0:str):str
-STRUpper;
+STRupper;
Convert a string to upper case.
str
trim
diff --git a/monetdb5/modules/atoms/str.c b/monetdb5/modules/atoms/str.c
--- a/monetdb5/modules/atoms/str.c
+++ b/monetdb5/modules/atoms/str.c
@@ -66,6 +66,7 @@
#ifdef HAVE_ICONV
#include <iconv.h>
#endif
+#include "mal_interpreter.h"
/*
* UTF-8 Handling
@@ -3548,7 +3549,7 @@ str_lower(str *buf, size_t *buflen, cons
}
static str
-STRLower(str *res, const str *arg1)
+STRlower(str *res, const str *arg1)
{
str buf = NULL, msg = MAL_SUCCEED;
const char *s = *arg1;
@@ -3587,7 +3588,7 @@ str_upper(str *buf, size_t *buflen, cons
}
static str
-STRUpper(str *res, const str *arg1)
+STRupper(str *res, const str *arg1)
{
str buf = NULL, msg = MAL_SUCCEED;
const char *s = *arg1;
@@ -3627,37 +3628,25 @@ str_is_prefix(const char *s, const char
}
static str
-STRPrefix(bit *res, const str *arg1, const str *arg2)
-{
- const char *s = *arg1, *prefix = *arg2;
-
- *res = (strNil(s) || strNil(prefix)) ? bit_nil : str_is_prefix(s,
prefix);
- return MAL_SUCCEED;
-}
-
-static str
-STRiPrefix(bit *res, const str *arg1, const str *arg2, const bit *b)
+STRstartsWith(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
- const str s1 = *arg1, s2 = *arg2;
- str msg = MAL_SUCCEED;
- if (strNil(s1) || strNil(s2))
- *res = bit_nil;
- else {
- if (*b) {
- str s1_lower, s2_lower;
- if ((msg = STRLower(&s1_lower, &s1)) != MAL_SUCCEED)
- return msg;
- if ((msg = STRLower(&s2_lower, &s2)) != MAL_SUCCEED) {
- GDKfree(s1_lower);
- return msg;
- }
- *res = str_is_prefix(s1_lower, s2_lower);
- GDKfree(s1_lower);
- GDKfree(s2_lower);
- }
- else
- *res = str_is_prefix(s1, s2);
+ (void)cntxt;
+ (void)mb;
+ bit *res = getArgReference(stk, pci, 0);
+ const str *arg1 = getArgReference(stk, pci, 1);
+ const str *arg2 = getArgReference(stk, pci, 2);
+ bit cs = pci->argc == 4 && *getArgReference_bit(stk, pci, 3) ? true :
false;
+
+ str s = *arg1, prefix = *arg2;
+ str s_lower, prefix_lower, msg = MAL_SUCCEED;
+
+ if (cs) {
+ if ((msg = STRlower(&s, &s_lower)) != MAL_SUCCEED ||
+ (msg = STRlower(&prefix, &prefix_lower)) != MAL_SUCCEED)
+ goto bail;
}
+ *res = (strNil(s) || strNil(prefix)) ? bit_nil :str_is_prefix(s,
prefix) ;
+ bail:
return msg;
}
@@ -3674,37 +3663,25 @@ str_is_suffix(const char *s, const char
/* returns whether arg1 ends with arg2 */
static str
-STRSuffix(bit *res, const str *arg1, const str *arg2)
-{
- const char *s = *arg1, *suffix = *arg2;
-
- *res = (strNil(s) || strNil(suffix)) ? bit_nil : str_is_suffix(s,
suffix);
- return MAL_SUCCEED;
-}
-
-static str
-STRiSuffix(bit *res, const str *arg1, const str *arg2, const bit *b)
+STRendsWith(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
- const str s1 = *arg1, s2 = *arg2;
- str msg = MAL_SUCCEED;
- if (strNil(s1) || strNil(s2))
- *res = bit_nil;
- else {
- if (*b) {
- str s1_lower, s2_lower;
- if ((msg = STRLower(&s1_lower, &s1)) != MAL_SUCCEED)
- return msg;
- if ((msg = STRLower(&s2_lower, &s2)) != MAL_SUCCEED) {
- GDKfree(s1_lower);
- return msg;
- }
- *res = str_is_suffix(s1_lower, s2_lower);
- GDKfree(s1_lower);
- GDKfree(s2_lower);
- }
- else
- *res = str_is_suffix(s1, s2);
+ (void)cntxt;
+ (void)mb;
+ bit *res = getArgReference(stk, pci, 0);
+ const str *arg1 = getArgReference(stk, pci, 1);
+ const str *arg2 = getArgReference(stk, pci, 2);
+ bit cs = pci->argc == 4 && *getArgReference_bit(stk, pci, 3) ? true :
false;
+
+ str s = *arg1, suffix = *arg2;
+ str s_lower, suffix_lower, msg = MAL_SUCCEED;
+
+ if (cs) {
+ if ((msg = STRlower(&s, &s_lower)) != MAL_SUCCEED ||
+ (msg = STRlower(&suffix, &suffix_lower)) != MAL_SUCCEED)
+ goto bail;
}
+ *res = (strNil(s) || strNil(suffix)) ? bit_nil :str_is_suffix(s,
suffix) ;
+ bail:
return msg;
}
@@ -3720,37 +3697,25 @@ str_search(const char *s, const char *s2
/* find first occurrence of needle in haystack */
static str
-STRstrSearch(int *res, const str *haystack, const str *needle)
-{
- const char *s = *haystack, *s2 = *needle;
-
- *res = (strNil(s) || strNil(s2)) ? int_nil : str_search(s, s2);
- return MAL_SUCCEED;
-}
-
-static str
-STRstrISearch(int *res, const str *haystack, const str *needle, const bit *b)
+STRstrSearch(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
- const str h = *haystack, n = *needle;
- str msg = MAL_SUCCEED;
- if (strNil(h) || strNil(n))
- *res = bit_nil;
- else {
- if (*b) {
- str h_lower, n_lower;
- if ((msg = STRLower(&h_lower, &h)) != MAL_SUCCEED)
- return msg;
- if ((msg = STRLower(&n_lower, &n)) != MAL_SUCCEED) {
- GDKfree(h_lower);
- return msg;
- }
- *res = str_is_suffix(h_lower, n_lower);
- GDKfree(h_lower);
- GDKfree(n_lower);
- }
- else
- *res = str_search(h, n);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]