summaryrefslogtreecommitdiffstatshomepage
path: root/py/misc.h
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-06-28 10:30:53 +0100
committerDamien George <damien.p.george@gmail.com>2014-06-28 10:30:53 +0100
commitb1b840554d27659f760304713c98f5c7f2d7f74b (patch)
treec112d08faa88043084f4d4d19094127b31d4e2c2 /py/misc.h
parent8993fb6cf0677ce980ab56cbad326e4e6bc47811 (diff)
parent635b60e299509a85722db77c4409c78ca86dbdc7 (diff)
downloadmicropython-b1b840554d27659f760304713c98f5c7f2d7f74b.tar.gz
micropython-b1b840554d27659f760304713c98f5c7f2d7f74b.zip
Merge branch 'unicode'
Diffstat (limited to 'py/misc.h')
-rw-r--r--py/misc.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/py/misc.h b/py/misc.h
index 3f62e3198f..bf63ce1354 100644
--- a/py/misc.h
+++ b/py/misc.h
@@ -100,7 +100,9 @@ bool unichar_isupper(unichar c);
bool unichar_islower(unichar c);
unichar unichar_tolower(unichar c);
unichar unichar_toupper(unichar c);
-#define unichar_charlen(s, bytelen) (bytelen)
+uint unichar_charlen(const char *str, uint len); // TODO this should return machine_uint_t
+#define UTF8_IS_NONASCII(ch) ((ch) & 0x80)
+#define UTF8_IS_CONT(ch) (((ch) & 0xC0) == 0x80)
/** variable string *********************************************/
@@ -164,4 +166,18 @@ int DEBUG_printf(const char *fmt, ...);
extern uint mp_verbose_flag;
+// This is useful for unicode handling. Some CPU archs has
+// special instructions for efficient implentation of this
+// function (e.g. CLZ on ARM).
+// NOTE: this function is unused at the moment
+#ifndef count_lead_ones
+static inline uint count_lead_ones(byte val) {
+ uint c = 0;
+ for (byte mask = 0x80; val & mask; mask >>= 1) {
+ c++;
+ }
+ return c;
+}
+#endif
+
#endif // _INCLUDED_MINILIB_H