MCPcopy Index your code
hub / github.com/JuliaStrings/utf8proc / utf8proc_encode_char

Function utf8proc_encode_char

utf8proc.c:177–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175}
176
177UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_encode_char(utf8proc_int32_t uc, utf8proc_uint8_t *dst) {
178 if (uc < 0x00) {
179 return 0;
180 } else if (uc < 0x80) {
181 dst[0] = (utf8proc_uint8_t) uc;
182 return 1;
183 } else if (uc < 0x800) {
184 dst[0] = (utf8proc_uint8_t)(0xC0 + (uc >> 6));
185 dst[1] = (utf8proc_uint8_t)(0x80 + (uc & 0x3F));
186 return 2;
187 // Note: we allow encoding 0xd800-0xdfff here, so as not to change
188 // the API, however, these are actually invalid in UTF-8
189 } else if (uc < 0x10000) {
190 dst[0] = (utf8proc_uint8_t)(0xE0 + (uc >> 12));
191 dst[1] = (utf8proc_uint8_t)(0x80 + ((uc >> 6) & 0x3F));
192 dst[2] = (utf8proc_uint8_t)(0x80 + (uc & 0x3F));
193 return 3;
194 } else if (uc < 0x110000) {
195 dst[0] = (utf8proc_uint8_t)(0xF0 + (uc >> 18));
196 dst[1] = (utf8proc_uint8_t)(0x80 + ((uc >> 12) & 0x3F));
197 dst[2] = (utf8proc_uint8_t)(0x80 + ((uc >> 6) & 0x3F));
198 dst[3] = (utf8proc_uint8_t)(0x80 + (uc & 0x3F));
199 return 4;
200 } else return 0;
201}
202
203/* internal version used for inserting 0xff bytes between graphemes */
204static utf8proc_ssize_t charbound_encode_char(utf8proc_int32_t uc, utf8proc_uint8_t *dst) {

Callers 4

utf8proc_reencodeFunction · 0.85
encodeFunction · 0.85
mainFunction · 0.85
issue317Function · 0.85

Calls

no outgoing calls

Tested by 1

encodeFunction · 0.68