MCPcopy Create free account
hub / github.com/ZDoom/Raze / utf8_decode

Function utf8_decode

source/common/utility/utf8.cpp:87–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85//==========================================================================
86
87int utf8_decode(const uint8_t *src, int *size)
88{
89 int c = src[0];
90 int r;
91
92 *size = 1;
93 if ((c & 0x80) == 0)
94 {
95 return c;
96 }
97
98 int c1 = src[1];
99 if (c1 < 0x80 || c1 >= 0xc0) return -1;
100 c1 &= 0x3f;
101
102 if ((c & 0xE0) == 0xC0)
103 {
104 r = ((c & 0x1F) << 6) | c1;
105 if (r >= 128)
106 {
107 *size = 2;
108 return r;
109 }
110 return -1;
111 }
112
113 int c2 = src[2];
114 if (c2 < 0x80 || c2 >= 0xc0) return -1;
115 c2 &= 0x3f;
116
117 if ((c & 0xF0) == 0xE0)
118 {
119 r = ((c & 0x0F) << 12) | (c1 << 6) | c2;
120 if (r >= 2048 && (r < 55296 || r > 57343))
121 {
122 *size = 3;
123 return r;
124 }
125 return -1;
126 }
127
128 int c3 = src[3];
129 if (c3 < 0x80 || c1 >= 0xc0) return -1;
130 c3 &= 0x3f;
131
132 if ((c & 0xF8) == 0xF0)
133 {
134 r = ((c & 0x07) << 18) | (c1 << 12) | (c2 << 6) | c3;
135 if (r >= 65536 && r <= 1114111)
136 {
137 *size = 4;
138 return r;
139 }
140 }
141 return -1;
142}
143
144//==========================================================================

Callers 3

GetCharFromStringFunction · 0.85
UnicodeToStringFunction · 0.85
MessagePumpFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected