summaryrefslogtreecommitdiff
path: root/py/misc.h
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-02-14 18:19:22 +1100
committerDamien George <damien.p.george@gmail.com>2018-02-14 18:19:22 +1100
commit19aee9438a7a8cf8539536dab5147aedb6b16bb3 (patch)
treec2300b20c7915eb222b3c20fcb61720aa5a78ef3 /py/misc.h
parent49e0dd54e650295fcb46b2a47ae08f369e5cfdac (diff)
py/unicode: Clean up utf8 funcs and provide non-utf8 inline versions.
This patch provides inline versions of the utf8 helper functions for the case when unicode is disabled (MICROPY_PY_BUILTINS_STR_UNICODE set to 0). This saves code size. The unichar_charlen function is also renamed to utf8_charlen to match the other utf8 helper functions, and the signature of this function is adjusted for consistency (const char* -> const byte*, mp_uint_t -> size_t).
Diffstat (limited to 'py/misc.h')
-rw-r--r--py/misc.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/py/misc.h b/py/misc.h
index 5d557db6f..a14bef7fe 100644
--- a/py/misc.h
+++ b/py/misc.h
@@ -121,8 +121,15 @@ typedef uint32_t unichar;
typedef uint unichar;
#endif
+#if MICROPY_PY_BUILTINS_STR_UNICODE
unichar utf8_get_char(const byte *s);
const byte *utf8_next_char(const byte *s);
+size_t utf8_charlen(const byte *str, size_t len);
+#else
+static inline unichar utf8_get_char(const byte *s) { return *s; }
+static inline const byte *utf8_next_char(const byte *s) { return s + 1; }
+static inline size_t utf8_charlen(const byte *str, size_t len) { (void)str; return len; }
+#endif
bool unichar_isspace(unichar c);
bool unichar_isalpha(unichar c);
@@ -135,7 +142,6 @@ bool unichar_islower(unichar c);
unichar unichar_tolower(unichar c);
unichar unichar_toupper(unichar c);
mp_uint_t unichar_xdigit_value(unichar c);
-mp_uint_t unichar_charlen(const char *str, mp_uint_t len);
#define UTF8_IS_NONASCII(ch) ((ch) & 0x80)
#define UTF8_IS_CONT(ch) (((ch) & 0xC0) == 0x80)