MCPcopy Create free account
hub / github.com/ablab/spades / isLegalUTF8

Function isLegalUTF8

ext/src/llvm/ConvertUTF.cpp:381–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

379 */
380
381static Boolean isLegalUTF8(const UTF8 *source, int length) {
382 UTF8 a;
383 const UTF8 *srcptr = source+length;
384 switch (length) {
385 default: return false;
386 /* Everything else falls through when "true"... */
387 case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
388 case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
389 case 2: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
390
391 switch (*source) {
392 /* no fall-through in this inner switch */
393 case 0xE0: if (a < 0xA0) return false; break;
394 case 0xED: if (a > 0x9F) return false; break;
395 case 0xF0: if (a < 0x90) return false; break;
396 case 0xF4: if (a > 0x8F) return false; break;
397 default: if (a < 0x80) return false;
398 }
399
400 case 1: if (*source >= 0x80 && *source < 0xC2) return false;
401 }
402 if (*source > 0xF4) return false;
403 return true;
404}
405
406/* --------------------------------------------------------------------- */
407

Callers 4

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

Calls

no outgoing calls

Tested by

no test coverage detected