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

Function utf8_to_unicode

src/fe_utils/mbprint.c:52–72  ·  view source on GitHub ↗

* Convert a UTF-8 character to a Unicode code point. * This is a one-character version of pg_utf2wchar_with_len. * * No error checks here, c must point to a long-enough string. */

Source from the content-addressed store, hash-verified

50 * No error checks here, c must point to a long-enough string.
51 */
52static pg_wchar
53utf8_to_unicode(const unsigned char *c)
54{
55 if ((*c & 0x80) == 0)
56 return (pg_wchar) c[0];
57 else if ((*c & 0xe0) == 0xc0)
58 return (pg_wchar) (((c[0] & 0x1f) << 6) |
59 (c[1] & 0x3f));
60 else if ((*c & 0xf0) == 0xe0)
61 return (pg_wchar) (((c[0] & 0x0f) << 12) |
62 ((c[1] & 0x3f) << 6) |
63 (c[2] & 0x3f));
64 else if ((*c & 0xf8) == 0xf0)
65 return (pg_wchar) (((c[0] & 0x07) << 18) |
66 ((c[1] & 0x3f) << 12) |
67 ((c[2] & 0x3f) << 6) |
68 (c[3] & 0x3f));
69 else
70 /* that is an invalid code on purpose */
71 return 0xffffffff;
72}
73
74
75/*

Callers 1

pg_wcsformatFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected