diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-13 23:00:15 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-27 00:04:18 +0300 |
commit | 86d3898e709f32bef9e44dd558e7ea5569398011 (patch) | |
tree | 3e1efe0058a660e3bcdc0a0b562e05e59f9174b1 /py | |
parent | d215ee1dc1e67bbeedf4bc0564de5ab3facfa6c0 (diff) | |
download | micropython-86d3898e709f32bef9e44dd558e7ea5569398011.tar.gz micropython-86d3898e709f32bef9e44dd558e7ea5569398011.zip |
objstrunicode: Get rid of bytes checking, it's separate type.
Diffstat (limited to 'py')
-rw-r--r-- | py/objstrunicode.c | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/py/objstrunicode.c b/py/objstrunicode.c index 741f1b76e8..d41e92db4a 100644 --- a/py/objstrunicode.c +++ b/py/objstrunicode.c @@ -47,7 +47,7 @@ STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str); /******************************************************************************/ /* str */ -STATIC void uni_print_quoted(void (*print)(void *env, const char *fmt, ...), void *env, const byte *str_data, uint str_len, bool is_bytes) { +STATIC void uni_print_quoted(void (*print)(void *env, const char *fmt, ...), void *env, const byte *str_data, uint str_len) { // this escapes characters, but it will be very slow to print (calling print many times) bool has_single_quote = false; bool has_double_quote = false; @@ -66,12 +66,8 @@ STATIC void uni_print_quoted(void (*print)(void *env, const char *fmt, ...), voi const char *s = (const char *)str_data, *top = (const char *)str_data + str_len; while (s < top) { unichar ch; - if (is_bytes) { - ch = *(unsigned char *)s++; // Don't sign-extend bytes - } else { - ch = utf8_get_char(s); - s = utf8_next_char(s); - } + ch = utf8_get_char(s); + s = utf8_next_char(s); if (ch == quote_char) { print(env, "\\%c", quote_char); } else if (ch == '\\') { @@ -95,16 +91,12 @@ STATIC void uni_print_quoted(void (*print)(void *env, const char *fmt, ...), voi print(env, "%c", quote_char); } -STATIC void str_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { +STATIC void uni_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { GET_STR_DATA_LEN(self_in, str_data, str_len); - bool is_bytes = MP_OBJ_IS_TYPE(self_in, &mp_type_bytes); - if (kind == PRINT_STR && !is_bytes) { + if (kind == PRINT_STR) { print(env, "%.*s", str_len, str_data); } else { - if (is_bytes) { - print(env, "b"); - } - uni_print_quoted(print, env, str_data, str_len, is_bytes); + uni_print_quoted(print, env, str_data, str_len); } } @@ -303,7 +295,7 @@ STATIC MP_DEFINE_CONST_DICT(str_locals_dict, str_locals_dict_table); const mp_obj_type_t mp_type_str = { { &mp_type_type }, .name = MP_QSTR_str, - .print = str_print, + .print = uni_print, .make_new = str_make_new, .binary_op = str_binary_op, .subscr = str_subscr, |