Commit 81836c28 authored by Damien George's avatar Damien George
Browse files

py: Use str_to_int function in more places to reduce code size.

parent 01039b5b
......@@ -790,13 +790,13 @@ STATIC mp_obj_t str_rstrip(mp_uint_t n_args, const mp_obj_t *args) {
// *num if at least one digit was parsed.
static int str_to_int(const char *str, int *num) {
const char *s = str;
if (unichar_isdigit(*s)) {
if ('0' <= *s && *s <= '9') {
*num = 0;
do {
*num = *num * 10 + (*s - '0');
s++;
}
while (unichar_isdigit(*s));
while ('0' <= *s && *s <= '9');
}
return s - str;
}
......@@ -1331,9 +1331,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o
width = mp_obj_get_int(args[arg_i++]);
str++;
} else {
for (; str < top && '0' <= *str && *str <= '9'; str++) {
width = width * 10 + *str - '0';
}
str += str_to_int((const char*)str, &width);
}
}
int prec = -1;
......@@ -1347,9 +1345,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o
str++;
} else {
prec = 0;
for (; str < top && '0' <= *str && *str <= '9'; str++) {
prec = prec * 10 + *str - '0';
}
str += str_to_int((const char*)str, &prec);
}
}
}
......
Supports Markdown
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