MCPcopy Create free account
hub / github.com/apache/cloudberry / unicode_to_utf8

Function unicode_to_utf8

src/common/wchar.c:501–528  ·  view source on GitHub ↗

* Map a Unicode code point to UTF-8. utf8string must have 4 bytes of * space allocated. */

Source from the content-addressed store, hash-verified

499 * space allocated.
500 */
501unsigned char *
502unicode_to_utf8(pg_wchar c, unsigned char *utf8string)
503{
504 if (c <= 0x7F)
505 {
506 utf8string[0] = c;
507 }
508 else if (c <= 0x7FF)
509 {
510 utf8string[0] = 0xC0 | ((c >> 6) & 0x1F);
511 utf8string[1] = 0x80 | (c & 0x3F);
512 }
513 else if (c <= 0xFFFF)
514 {
515 utf8string[0] = 0xE0 | ((c >> 12) & 0x0F);
516 utf8string[1] = 0x80 | ((c >> 6) & 0x3F);
517 utf8string[2] = 0x80 | (c & 0x3F);
518 }
519 else
520 {
521 utf8string[0] = 0xF0 | ((c >> 18) & 0x07);
522 utf8string[1] = 0x80 | ((c >> 12) & 0x3F);
523 utf8string[2] = 0x80 | ((c >> 6) & 0x3F);
524 utf8string[3] = 0x80 | (c & 0x3F);
525 }
526
527 return utf8string;
528}
529
530/*
531 * Trivial conversion from pg_wchar to UTF-8.

Callers 6

unicode_normalize_funcFunction · 0.85
pg_unicode_to_serverFunction · 0.85
json_lex_stringFunction · 0.85
pg_wchar2utf_with_lenFunction · 0.85
pg_saslprepFunction · 0.85
pg_unicode_to_serverFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected