mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-23 15:50:49 +01:00
Upgrade to MicroPython 1.9.3
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
@@ -182,3 +182,31 @@ mp_uint_t unichar_xdigit_value(unichar c) {
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
bool utf8_check(const byte *p, size_t len) {
|
||||
uint8_t need = 0;
|
||||
const byte *end = p + len;
|
||||
for (; p < end; p++) {
|
||||
byte c = *p;
|
||||
if (need) {
|
||||
if (c >= 0x80) {
|
||||
need--;
|
||||
} else {
|
||||
// mismatch
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (c >= 0xc0) {
|
||||
if (c >= 0xf8) {
|
||||
// mismatch
|
||||
return 0;
|
||||
}
|
||||
need = (0xe5 >> ((c >> 3) & 0x6)) & 3;
|
||||
} else if (c >= 0x80) {
|
||||
// mismatch
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return need == 0; // no pending fragments allowed
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user