MCPcopy Create free account
hub / github.com/cuberite/cuberite / isLegalUTF8

Function isLegalUTF8

src/StringUtils.cpp:401–428  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

StringUtils.cppFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected