objstrunicode: Get rid of bytes checking, it's separate type.
This commit is contained in:
parent
d215ee1dc1
commit
86d3898e70
|
@ -47,7 +47,7 @@ STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str);
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* 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)
|
// this escapes characters, but it will be very slow to print (calling print many times)
|
||||||
bool has_single_quote = false;
|
bool has_single_quote = false;
|
||||||
bool has_double_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;
|
const char *s = (const char *)str_data, *top = (const char *)str_data + str_len;
|
||||||
while (s < top) {
|
while (s < top) {
|
||||||
unichar ch;
|
unichar ch;
|
||||||
if (is_bytes) {
|
ch = utf8_get_char(s);
|
||||||
ch = *(unsigned char *)s++; // Don't sign-extend bytes
|
s = utf8_next_char(s);
|
||||||
} else {
|
|
||||||
ch = utf8_get_char(s);
|
|
||||||
s = utf8_next_char(s);
|
|
||||||
}
|
|
||||||
if (ch == quote_char) {
|
if (ch == quote_char) {
|
||||||
print(env, "\\%c", quote_char);
|
print(env, "\\%c", quote_char);
|
||||||
} else if (ch == '\\') {
|
} 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);
|
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);
|
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) {
|
||||||
if (kind == PRINT_STR && !is_bytes) {
|
|
||||||
print(env, "%.*s", str_len, str_data);
|
print(env, "%.*s", str_len, str_data);
|
||||||
} else {
|
} else {
|
||||||
if (is_bytes) {
|
uni_print_quoted(print, env, str_data, str_len);
|
||||||
print(env, "b");
|
|
||||||
}
|
|
||||||
uni_print_quoted(print, env, str_data, str_len, is_bytes);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +295,7 @@ STATIC MP_DEFINE_CONST_DICT(str_locals_dict, str_locals_dict_table);
|
||||||
const mp_obj_type_t mp_type_str = {
|
const mp_obj_type_t mp_type_str = {
|
||||||
{ &mp_type_type },
|
{ &mp_type_type },
|
||||||
.name = MP_QSTR_str,
|
.name = MP_QSTR_str,
|
||||||
.print = str_print,
|
.print = uni_print,
|
||||||
.make_new = str_make_new,
|
.make_new = str_make_new,
|
||||||
.binary_op = str_binary_op,
|
.binary_op = str_binary_op,
|
||||||
.subscr = str_subscr,
|
.subscr = str_subscr,
|
||||||
|
|
Loading…
Reference in New Issue