+static uint16_t utf8_strlen(const char *text, int len)
+{
+ uint16_t i = 0, ret = 0;
+ while (i < len) {
+ char c = text[i];
+ if ((c & 0x80) == 0)
+ i += 1;
+ else if ((c & 0xE0) == 0xC0)
+ i += 2;
+ else if ((c & 0xF0) == 0xE0)
+ i += 3;
+ else if ((c & 0xF8) == 0xF0)
+ i += 4;
+ else
+ return 0;
+ ret++;
+ }
+ return ret;
+}
+