[Tarantool-patches] [PATCH v1 14/21] sql: refactor UNICODE() function
imeevma at tarantool.org
imeevma at tarantool.org
Fri Oct 8 20:31:58 MSK 2021
Part of #4145
---
src/box/sql/func.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index fb7fd772e..5e12ef729 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1007,6 +1007,19 @@ func_version(struct sql_context *ctx, int argc, struct Mem *argv)
return mem_set_str0_static(ctx->pOut, (char *)tarantool_version());
}
+/** Implementation of the UNICODE() function. */
+static void
+func_unicode(struct sql_context *ctx, int argc, struct Mem *argv)
+{
+ assert(argc == 1);
+ (void)argc;
+ if (mem_is_null(&argv[0]))
+ return;
+ assert(mem_is_str(&argv[0]));
+ const char *str = tt_cstr(argv[0].z, argv[0].n);
+ mem_set_uint(ctx->pOut, sqlUtf8Read((const unsigned char **)&str));
+}
+
static const unsigned char *
mem_as_ustr(struct Mem *mem)
{
@@ -1426,19 +1439,6 @@ quoteFunc(struct sql_context *context, int argc, struct Mem *argv)
}
}
-/*
- * The unicode() function. Return the integer unicode code-point value
- * for the first character of the input string.
- */
-static void
-unicodeFunc(struct sql_context *context, int argc, struct Mem *argv)
-{
- const unsigned char *z = mem_as_ustr(&argv[0]);
- (void)argc;
- if (z && z[0])
- sql_result_uint(context, sqlUtf8Read(&z));
-}
-
/*
* The replace() function. Three arguments are all strings: call
* them A, B, and C. The result is also a string which is derived
@@ -1874,7 +1874,7 @@ static struct sql_func_definition definitions[] = {
FIELD_TYPE_VARBINARY, func_trim_bin, NULL},
{"TYPEOF", 1, {FIELD_TYPE_ANY}, FIELD_TYPE_STRING, func_typeof, NULL},
- {"UNICODE", 1, {FIELD_TYPE_STRING}, FIELD_TYPE_INTEGER, unicodeFunc,
+ {"UNICODE", 1, {FIELD_TYPE_STRING}, FIELD_TYPE_INTEGER, func_unicode,
NULL},
{"UNLIKELY", 1, {FIELD_TYPE_ANY}, FIELD_TYPE_BOOLEAN, sql_builtin_stub,
NULL},
--
2.25.1
More information about the Tarantool-patches
mailing list