summaryrefslogtreecommitdiffstatshomepage
path: root/py/objstr.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-12-21 21:07:03 +0000
committerDamien George <damien.p.george@gmail.com>2014-12-21 21:07:03 +0000
commit81836c28b346c5158e6fc8a79b74a8caa7211dd7 (patch)
treea2fabba71ad4f6fd1b40f0d62ec90cc645026c5c /py/objstr.c
parent01039b5bd8297e4a0393da26710f7ec99b7b8749 (diff)
downloadmicropython-81836c28b346c5158e6fc8a79b74a8caa7211dd7.tar.gz
micropython-81836c28b346c5158e6fc8a79b74a8caa7211dd7.zip
py: Use str_to_int function in more places to reduce code size.
Diffstat (limited to 'py/objstr.c')
-rw-r--r--py/objstr.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/py/objstr.c b/py/objstr.c
index 1bb89dda91..7cd44471ec 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -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);
}
}
}