summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
Diffstat (limited to 'py')
-rw-r--r--py/unicode.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/py/unicode.c b/py/unicode.c
index 0da247889e..c381200722 100644
--- a/py/unicode.c
+++ b/py/unicode.c
@@ -86,6 +86,17 @@ char *utf8_next_char(const char *s) {
return (char *)s;
}
+machine_uint_t utf8_ptr_to_index(const char *s, const char *ptr) {
+ machine_uint_t i = 0;
+ while (ptr > s) {
+ if (!UTF8_IS_CONT(*--ptr)) {
+ i++;
+ }
+ }
+
+ return i;
+}
+
uint unichar_charlen(const char *str, uint len)
{
uint charlen = 0;