MCPcopy Create free account
hub / github.com/StereoKit/StereoKit / utf8_encode

Function utf8_encode

StereoKitC/libraries/unicode.cpp:112–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110///////////////////////////////////////////
111
112int32_t utf8_encode(char *out, char32_t utf) {
113 if (utf <= 0x7F) {
114 // Plain ASCII
115 out[0] = (char) utf;
116 return 1;
117 } else if (utf <= 0x07FF) {
118 // 2-byte unicode
119 out[0] = (char) (((utf >> 6) & 0x1F) | 0xC0);
120 out[1] = (char) (((utf >> 0) & 0x3F) | 0x80);
121 return 2;
122 } else if (utf <= 0xFFFF) {
123 // 3-byte unicode
124 out[0] = (char) (((utf >> 12) & 0x0F) | 0xE0);
125 out[1] = (char) (((utf >> 6) & 0x3F) | 0x80);
126 out[2] = (char) (((utf >> 0) & 0x3F) | 0x80);
127 return 3;
128 } else if (utf <= 0x10FFFF) {
129 // 4-byte unicode
130 out[0] = (char) (((utf >> 18) & 0x07) | 0xF0);
131 out[1] = (char) (((utf >> 12) & 0x3F) | 0x80);
132 out[2] = (char) (((utf >> 6) & 0x3F) | 0x80);
133 out[3] = (char) (((utf >> 0) & 0x3F) | 0x80);
134 return 4;
135 }
136 return 0;
137}
138
139///////////////////////////////////////////
140

Callers 2

utf8_encode_appendFunction · 0.85
utf_insert_charFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected