diff options
Diffstat (limited to 'py')
-rw-r--r-- | py/lexer.c | 12 | ||||
-rw-r--r-- | py/misc.h | 1 | ||||
-rw-r--r-- | py/qstrdefs.h | 1 | ||||
-rw-r--r-- | py/unicode.c | 10 |
4 files changed, 13 insertions, 11 deletions
diff --git a/py/lexer.c b/py/lexer.c index 536208e41..12cb5ae5b 100644 --- a/py/lexer.c +++ b/py/lexer.c @@ -261,16 +261,6 @@ STATIC const char *tok_kw[] = { "__debug__", }; -STATIC mp_uint_t hex_digit(unichar c) { - // c is assumed to be hex digit - mp_uint_t n = c - '0'; - if (n > 9) { - n &= ~('a' - 'A'); - n -= ('A' - ('9' + 1)); - } - return n; -} - // This is called with CUR_CHAR() before first hex digit, and should return with // it pointing to last hex digit // num_digits must be greater than zero @@ -282,7 +272,7 @@ STATIC bool get_hex(mp_lexer_t *lex, mp_uint_t num_digits, mp_uint_t *result) { if (!unichar_isxdigit(c)) { return false; } - num = (num << 4) + hex_digit(c); + num = (num << 4) + unichar_xdigit_value(c); } *result = num; return true; @@ -127,6 +127,7 @@ bool unichar_isupper(unichar c); bool unichar_islower(unichar c); unichar unichar_tolower(unichar c); unichar unichar_toupper(unichar c); +mp_uint_t unichar_xdigit_value(unichar c); mp_uint_t unichar_charlen(const char *str, mp_uint_t len); #define UTF8_IS_NONASCII(ch) ((ch) & 0x80) #define UTF8_IS_CONT(ch) (((ch) & 0xC0) == 0x80) diff --git a/py/qstrdefs.h b/py/qstrdefs.h index 5d0dc9d27..a5e543bbb 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -584,6 +584,7 @@ Q(sha256) #if MICROPY_PY_UBINASCII Q(ubinascii) Q(hexlify) +Q(unhexlify) #endif #if MICROPY_PY_MACHINE diff --git a/py/unicode.c b/py/unicode.c index db4aa438a..63e960118 100644 --- a/py/unicode.c +++ b/py/unicode.c @@ -169,3 +169,13 @@ unichar unichar_toupper(unichar c) { } return c; } + +mp_uint_t unichar_xdigit_value(unichar c) { + // c is assumed to be hex digit + mp_uint_t n = c - '0'; + if (n > 9) { + n &= ~('a' - 'A'); + n -= ('A' - ('9' + 1)); + } + return n; +} |