MCPcopy Create free account
hub / github.com/apache/arrow / chr_int64

Function chr_int64

cpp/src/gandiva/precompiled/string_ops.cc:1423–1475  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

1421// Raises an error if A is not a valid code point, i.e. it is negative, greater
1422// than 0x10FFFF, or falls within the UTF-16 surrogate range 0xD800-0xDFFF.
1423FORCE_INLINE
1424const char* chr_int64(gdv_int64 context, gdv_int64 in, gdv_int32* out_len) {
1425 if (in < 0 || in > 0x10FFFF || (in >= 0xD800 && in <= 0xDFFF)) {
1426 char err_msg[128];
1427 snprintf(err_msg, sizeof(err_msg),
1428 "Input %" PRId64
1429 " is not a valid Unicode code point in the range 0 to 1114111, excluding "
1430 "the surrogate range 0xD800–0xDFFF",
1431 in);
1432 gdv_fn_context_set_error_msg(context, err_msg);
1433 *out_len = 0;
1434 return "";
1435 }
1436
1437 if (in <= 0x7F) {
1438 *out_len = 1;
1439 } else if (in <= 0x7FF) {
1440 *out_len = 2;
1441 } else if (in <= 0xFFFF) {
1442 *out_len = 3;
1443 } else {
1444 *out_len = 4;
1445 }
1446
1447 char* ret = reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context, *out_len));
1448 if (ret == nullptr) {
1449 gdv_fn_context_set_error_msg(context, "Could not allocate memory for output string");
1450 *out_len = 0;
1451 return "";
1452 }
1453
1454 switch (*out_len) {
1455 case 1:
1456 ret[0] = static_cast<char>(in);
1457 break;
1458 case 2:
1459 ret[0] = static_cast<char>(0xC0 | (in >> 6));
1460 ret[1] = static_cast<char>(0x80 | (in & 0x3F));
1461 break;
1462 case 3:
1463 ret[0] = static_cast<char>(0xE0 | (in >> 12));
1464 ret[1] = static_cast<char>(0x80 | ((in >> 6) & 0x3F));
1465 ret[2] = static_cast<char>(0x80 | (in & 0x3F));
1466 break;
1467 case 4:
1468 ret[0] = static_cast<char>(0xF0 | (in >> 18));
1469 ret[1] = static_cast<char>(0x80 | ((in >> 12) & 0x3F));
1470 ret[2] = static_cast<char>(0x80 | ((in >> 6) & 0x3F));
1471 ret[3] = static_cast<char>(0x80 | (in & 0x3F));
1472 break;
1473 }
1474 return ret;
1475}
1476
1477// Returns the UTF-8 encoding of the Unicode code point A. See chr_int64.
1478FORCE_INLINE

Callers 2

chr_int32Function · 0.85
TESTFunction · 0.85

Calls 2

Tested by 1

TESTFunction · 0.68