kou commented on code in PR #50137:
URL: https://github.com/apache/arrow/pull/50137#discussion_r3763837009
##########
cpp/src/gandiva/precompiled/string_ops.cc:
##########
@@ -1412,40 +1412,69 @@ gdv_int32 ascii_utf8(const char* data, gdv_int32
data_len) {
return static_cast<gdv_int32>(static_cast<signed char>(data[0]));
}
-// Returns the ASCII character having the binary equivalent to A.
-// If A is larger than 256 the result is equivalent to chr(A % 256).
+// Returns the UTF-8 encoding of the Unicode code point A.
+// Raises an error if A is not a valid code point, i.e. it is negative, greater
+// than 0x10FFFF, or falls within the UTF-16 surrogate range 0xD800-0xDFFF.
FORCE_INLINE
-const char* chr_int32(gdv_int64 context, gdv_int32 in, gdv_int32* out_len) {
- in = in % 256;
- *out_len = 1;
-
- char* ret = reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context,
*out_len));
- if (ret == nullptr) {
- gdv_fn_context_set_error_msg(context, "Could not allocate memory for
output string");
+const char* chr_int64(gdv_int64 context, gdv_int64 in, gdv_int32* out_len) {
+ if (in < 0 || in > 0x10FFFF || (in >= 0xD800 && in <= 0xDFFF)) {
+ const char* fmt =
+ "Input %" PRId64 " is not a valid Unicode code point in the range 0 to
1114111";
+ int size = static_cast<int>(strlen(fmt)) + 32;
+ char* error = reinterpret_cast<char*>(malloc(size));
Review Comment:
Can we use a stack by `const char[128]` or something?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]