MCPcopy Create free account
hub / github.com/TASEmulators/fceux / isLegalUTF8

Function isLegalUTF8

src/utils/ConvertUTF.c:295–318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293 */
294
295static Boolean isLegalUTF8(const UTF8 *source, int length) {
296 UTF8 a;
297 const UTF8 *srcptr = source+length;
298 switch (length) {
299 default: return false;
300 /* Everything else falls through when "true"... */
301 case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
302 case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
303 case 2: if ((a = (*--srcptr)) > 0xBF) return false;
304
305 switch (*source) {
306 /* no fall-through in this inner switch */
307 case 0xE0: if (a < 0xA0) return false; break;
308 case 0xED: if (a > 0x9F) return false; break;
309 case 0xF0: if (a < 0x90) return false; break;
310 case 0xF4: if (a > 0x8F) return false; break;
311 default: if (a < 0x80) return false;
312 }
313
314 case 1: if (*source >= 0x80 && *source < 0xC2) return false;
315 }
316 if (*source > 0xF4) return false;
317 return true;
318}
319
320/* --------------------------------------------------------------------- */
321

Callers 3

isLegalUTF8SequenceFunction · 0.85
ConvertUTF8toUTF16Function · 0.85
ConvertUTF8toUTF32Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected