diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-14 03:15:00 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-27 00:04:19 +0300 |
commit | 5048df0b7c1cfb951e28fc2d4b1f1385b1c8046e (patch) | |
tree | bcd8f0c95ef458389f900cd044ddd3075ea48d18 /py | |
parent | 46d31e9ca90635707031afedf09da7aeed25a321 (diff) | |
download | micropython-5048df0b7c1cfb951e28fc2d4b1f1385b1c8046e.tar.gz micropython-5048df0b7c1cfb951e28fc2d4b1f1385b1c8046e.zip |
objstr: find(), rfind(), index(): Make return value be unicode-aware.
Diffstat (limited to 'py')
-rw-r--r-- | py/objstr.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/py/objstr.c b/py/objstr.c index acbf002837..c732719dd5 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -32,6 +32,7 @@ #include "mpconfig.h" #include "nlr.h" #include "misc.h" +#include "unicode.h" #include "qstr.h" #include "obj.h" #include "runtime0.h" @@ -591,6 +592,11 @@ STATIC mp_obj_t str_finder(uint n_args, const mp_obj_t *args, machine_int_t dire } } else { // found + #if MICROPY_PY_BUILTINS_STR_UNICODE + if (self_type == &mp_type_str) { + return MP_OBJ_NEW_SMALL_INT(utf8_ptr_to_index(haystack, p)); + } + #endif return MP_OBJ_NEW_SMALL_INT(p - haystack); } } |