MCPcopy Create free account
hub / github.com/MapServer/MapServer / ms_Tcl_UtfToUniChar

Function ms_Tcl_UtfToUniChar

maptclutf.c:224–311  ·  view source on GitHub ↗
(str, chPtr)

Source from the content-addressed store, hash-verified

222 */
223
224static int
225ms_Tcl_UtfToUniChar(str, chPtr)
226 register const char *str; /* The UTF-8 string. */
227 register Tcl_UniChar *chPtr; /* Filled with the Tcl_UniChar represented
228 * by the UTF-8 string. */
229{
230 register int byte;
231 int entitylgth;
232
233 /*check if the string is an html entity (eg { or Ī)*/
234 if((entitylgth=msGetUnicodeEntity(str, chPtr))>0)
235 return entitylgth;
236
237 /*
238 * Unroll 1 to 3 byte UTF-8 sequences, use loop to handle longer ones.
239 */
240
241 byte = *((unsigned char *) str);
242 if (byte < 0xC0) {
243 /*
244 * Handles properly formed UTF-8 characters between 0x01 and 0x7F.
245 * Also treats \0 and naked trail bytes 0x80 to 0xBF as valid
246 * characters representing themselves.
247 */
248
249 *chPtr = (Tcl_UniChar) byte;
250 return 1;
251 } else if (byte < 0xE0) {
252 if ((str[1] & 0xC0) == 0x80) {
253 /*
254 * Two-byte-character lead-byte followed by a trail-byte.
255 */
256
257 *chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (str[1] & 0x3F));
258 return 2;
259 }
260 /*
261 * A two-byte-character lead-byte not followed by trail-byte
262 * represents itself.
263 */
264
265 *chPtr = (Tcl_UniChar) byte;
266 return 1;
267 } else if (byte < 0xF0) {
268 if (((str[1] & 0xC0) == 0x80) && ((str[2] & 0xC0) == 0x80)) {
269 /*
270 * Three-byte-character lead byte followed by two trail bytes.
271 */
272
273 *chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12)
274 | ((str[1] & 0x3F) << 6) | (str[2] & 0x3F));
275 return 3;
276 }
277 /*
278 * A three-byte-character lead-byte not followed by two trail-bytes
279 * represents itself.
280 */
281

Callers 1

msUTF8ToUniCharFunction · 0.85

Calls 1

msGetUnicodeEntityFunction · 0.85

Tested by

no test coverage detected