diff options
author | Uros Majstorovic <majstor@majstor.org> | 2020-08-09 02:07:13 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2020-08-09 02:07:13 +0200 |
commit | 9dd66a7dd0c5ba39f9b602daafea88a00cef75e8 (patch) | |
tree | 390e414ff712e8316d71d9a57535ca60224e9e8d /fw/fe310/eos/unicode.c | |
parent | 8c76421b174c6c53109df411a6670160a85933a1 (diff) |
unicode utf_len added; cell sms services added
Diffstat (limited to 'fw/fe310/eos/unicode.c')
-rw-r--r-- | fw/fe310/eos/unicode.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/fw/fe310/eos/unicode.c b/fw/fe310/eos/unicode.c index 2915791..e2fb772 100644 --- a/fw/fe310/eos/unicode.c +++ b/fw/fe310/eos/unicode.c @@ -57,6 +57,15 @@ int utf8_dec(utf8_t *str, utf32_t *ch) { } } +int utf8_len(utf8_t *str) { + if ((*str & 0xf8) == 0xf0) return 4; + if ((*str & 0xf0) == 0xe0) return 3; + if ((*str & 0xe0) == 0xc0) return 2; + if ((*str & 0x80) == 0x00) return 1; + + return UTF_ERR; +} + int utf8_seek(utf8_t *str, int off, utf32_t *ch) { int i; int len = 0; @@ -91,11 +100,8 @@ int utf8_verify(utf8_t *str, int str_size, int *str_len) { while (len < str_size) { if (str_size - len < 4) { - if (((str[len] & 0xf8) == 0xf0) || - (((str[len] & 0xf0) == 0xe0) && (str_size - len < 3)) || - (((str[len] & 0xe0) == 0xc0) && (str_size - len < 2))) { - break; - } + int _len = utf8_len(str + len); + if ((_len == UTF_ERR) || ((str_size - len) < _len)) break; } ch_l = utf8_dec(str + len, &ch); if (ch_l > 0) { @@ -151,6 +157,14 @@ int utf16_dec(uint8_t *str, utf32_t *ch) { } } +int utf16_len(uint8_t *str) { + uint16_t ch = (str[0] << 8) | str[1]; + + if ((ch >= 0xdc00) && (ch <= 0xdfff)) return UTF_ERR; + if ((ch >= 0xd800) && (ch <= 0xdfff)) return 4; + return 2; +} + int utf16_seek(uint8_t *str, int off, utf32_t *ch) { int i; int len = 0; |