MCPcopy Create free account
hub / github.com/ZDoom/gzdoom / utf8_encode

Function utf8_encode

src/common/utility/utf8.cpp:45–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43//==========================================================================
44
45int utf8_encode(int32_t codepoint, uint8_t *buffer, int *size)
46{
47 if (codepoint < 0)
48 return -1;
49 else if (codepoint < 0x80)
50 {
51 buffer[0] = (char)codepoint;
52 *size = 1;
53 }
54 else if (codepoint < 0x800)
55 {
56 buffer[0] = 0xC0 + ((codepoint & 0x7C0) >> 6);
57 buffer[1] = 0x80 + ((codepoint & 0x03F));
58 *size = 2;
59 }
60 else if (codepoint < 0x10000)
61 {
62 buffer[0] = 0xE0 + ((codepoint & 0xF000) >> 12);
63 buffer[1] = 0x80 + ((codepoint & 0x0FC0) >> 6);
64 buffer[2] = 0x80 + ((codepoint & 0x003F));
65 *size = 3;
66 }
67 else if (codepoint <= 0x10FFFF)
68 {
69 buffer[0] = 0xF0 + ((codepoint & 0x1C0000) >> 18);
70 buffer[1] = 0x80 + ((codepoint & 0x03F000) >> 12);
71 buffer[2] = 0x80 + ((codepoint & 0x000FC0) >> 6);
72 buffer[3] = 0x80 + ((codepoint & 0x00003F));
73 *size = 4;
74 }
75 else
76 return -1;
77
78 return 0;
79}
80
81//==========================================================================
82//

Callers 2

MakeUTF8Function · 0.70
StringToUnicodeFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected