MCPcopy Create free account
hub / github.com/axmolengine/axmol / isLegalUTF8

Function isLegalUTF8

3rdparty/ConvertUTF/ConvertUTF.cpp:398–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

396 */
397
398static Boolean isLegalUTF8(const UTF8 *source, int length) {
399 UTF8 a;
400 const UTF8 *srcptr = source+length;
401 switch (length) {
402 default: return false;
403 /* Everything else falls through when "true"... */
404 case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
405 case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
406 case 2: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
407
408 switch (*source) {
409 /* no fall-through in this inner switch */
410 case 0xE0: if (a < 0xA0) return false; break;
411 case 0xED: if (a > 0x9F) return false; break;
412 case 0xF0: if (a < 0x90) return false; break;
413 case 0xF4: if (a > 0x8F) return false; break;
414 default: if (a < 0x80) return false;
415 }
416
417 case 1: if (*source >= 0x80 && *source < 0xC2) return false;
418 }
419 if (*source > 0xF4) return false;
420 return true;
421}
422
423/* --------------------------------------------------------------------- */
424

Callers 5

isLegalUTF8SequenceFunction · 0.85
getUTF8SequenceSizeFunction · 0.85
isLegalUTF8StringFunction · 0.85
ConvertUTF8toUTF16Function · 0.85
ConvertUTF8toUTF32ImplFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected