Changeset: 924d61516c92 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/924d61516c92
Modified Files:
monetdb5/modules/atoms/str.c
sql/test/sys-schema/Tests/webExamplesStringFunctions.test
Branch: default
Log Message:
Remove 'asciify' test and improve 'asciify' return msg in case of error.
diffs (75 lines):
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
@@ -65,6 +65,7 @@
#include <string.h>
#ifdef HAVE_ICONV
#include <iconv.h>
+#include <locale.h>
#endif
#include "mal_interpreter.h"
@@ -5046,37 +5047,40 @@ static str
STRasciify(str *r, const str *s)
{
#ifdef HAVE_ICONV
- /* Handle NULL and return early */
+
if (strNil(*s)) {
if ((*r = GDKstrdup(str_nil)) == NULL)
throw(MAL, "str.asciify", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
else
return MAL_SUCCEED;
}
+
iconv_t cd;
const str f = "UTF-8", t = "ASCII//TRANSLIT";
str in = *s, out;
- size_t in_len = strlen(in), out_len = in_len * 4; /* oversized as
a single utf8 char could change into multiple
-
ascii char */
- /* man iconv; /TRANSLIT */
+ size_t in_len = strlen(in), out_len = in_len * 4; /* oversized as a
single utf8 char could change into multiple ascii char */
+
if ((cd = iconv_open(t, f)) == (iconv_t) (-1))
- throw(MAL, "str.asciify", "ICONV: cannot convert from (%s) to
(%s).", f,
- t);
+ throw(MAL, "str.asciify", "ICONV: cannot convert from (%s) to
(%s).", f, t);
+
if ((*r = out = GDKmalloc(out_len)) == NULL) {
iconv_close(cd);
throw(MAL, "str.asciify", SQLSTATE(HY013) MAL_MALLOC_FAIL);
}
+
str o = out;
+
if (iconv(cd, &in, &in_len, &o, &out_len) == (size_t) -1) {
GDKfree(out);
*r = NULL;
iconv_close(cd);
- throw(MAL, "str.asciify",
- "ICONV: string conversion failed from (%s) to (%s)",
f, t);
+ throw(MAL, "str.asciify", "Conversion failed, possibly due to
system locale %s.", setlocale(0, NULL));
}
+
*o = '\0';
iconv_close(cd);
return MAL_SUCCEED;
+
#else
throw(MAL, "str.asciify", "ICONV library not available.");
#endif
diff --git a/sql/test/sys-schema/Tests/webExamplesStringFunctions.test
b/sql/test/sys-schema/Tests/webExamplesStringFunctions.test
--- a/sql/test/sys-schema/Tests/webExamplesStringFunctions.test
+++ b/sql/test/sys-schema/Tests/webExamplesStringFunctions.test
@@ -16,11 +16,6 @@ select ascii(R'€')
----
8364
-query T
-select asciify(R'a € sign')
-----
-a EUR sign
-
query I
select char_length(R'2€')
----
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]