aboutsummaryrefslogtreecommitdiff
path: root/py/objstrunicode.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-09-25 17:35:56 +0100
committerDamien George <damien.p.george@gmail.com>2014-09-25 17:35:56 +0100
commitcde0ca21bf79420386c7cb31de29b0f799f16655 (patch)
treea11355475cffce12ebcc89b75857a80f400abb7f /py/objstrunicode.c
parentd19c256656d62397344a39351082281039d612c0 (diff)
py: Simplify JSON str printing (while still conforming to JSON spec).
The JSON specs are relatively flexible and allow us to use one function to print strings, be they ascii, bytes or utf-8 encoded.
Diffstat (limited to 'py/objstrunicode.c')
-rw-r--r--py/objstrunicode.c32
1 files changed, 1 insertions, 31 deletions
diff --git a/py/objstrunicode.c b/py/objstrunicode.c
index 0ee7f1dc9..062e011fb 100644
--- a/py/objstrunicode.c
+++ b/py/objstrunicode.c
@@ -91,41 +91,11 @@ STATIC void uni_print_quoted(void (*print)(void *env, const char *fmt, ...), voi
print(env, "%c", quote_char);
}
-#if MICROPY_PY_UJSON
-STATIC void uni_print_json(void (*print)(void *env, const char *fmt, ...), void *env, const byte *str_data, uint str_len) {
- print(env, "\"");
- const byte *s = str_data, *top = str_data + str_len;
- while (s < top) {
- unichar ch;
- ch = utf8_get_char(s);
- s = utf8_next_char(s);
- if (ch == '"' || ch == '\\' || ch == '/') {
- print(env, "\\%c", ch);
- } else if (32 <= ch && ch <= 126) {
- print(env, "%c", ch);
- } else if (*s == '\b') {
- print(env, "\\b");
- } else if (*s == '\f') {
- print(env, "\\f");
- } else if (*s == '\n') {
- print(env, "\\n");
- } else if (*s == '\r') {
- print(env, "\\r");
- } else if (*s == '\t') {
- print(env, "\\t");
- } else {
- print(env, "\\u%04x", ch);
- }
- }
- print(env, "\"");
-}
-#endif
-
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);
#if MICROPY_PY_UJSON
if (kind == PRINT_JSON) {
- uni_print_json(print, env, str_data, str_len);
+ mp_str_print_json(print, env, str_data, str_len);
return;
}
#endif