Commit c2dd494b authored by Damien George's avatar Damien George
Browse files

py/parsenum: Simplify and generalise decoding of digit values.

This function should be able to parse integers with any value for the
base, because it is called by int('xxx', base).
parent 25f44c19
......@@ -81,20 +81,18 @@ mp_obj_t mp_parse_num_integer(const char *restrict str_, size_t len, int base, m
for (; str < top; str++) {
// get next digit as a value
mp_uint_t dig = *str;
if (unichar_isdigit(dig) && (int)dig - '0' < base) {
// 0-9 digit
dig = dig - '0';
} else if (base == 16) {
dig |= 0x20;
if ('a' <= dig && dig <= 'f') {
// a-f hex digit
dig = dig - 'a' + 10;
if ('0' <= dig && dig <= '9') {
dig -= '0';
} else {
dig |= 0x20; // make digit lower-case
if ('a' <= dig && dig <= 'z') {
dig -= 'a' - 10;
} else {
// unknown character
break;
}
} else {
// unknown character
}
if (dig >= base) {
break;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment