aboutsummaryrefslogtreecommitdiff
path: root/utf8.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-01-27 10:47:49 +0000
committerOmar Polo <op@omarpolo.com>2021-01-27 10:47:49 +0000
commit3300cbe06a9567c66ee63f3866bcbcf3430e0205 (patch)
treea7686f8e774573b55ebbe18373a27eb60f44baa4 /utf8.c
parent390a61189309451462c0a1dc56c68f71e334ad4b (diff)
initial punycode support
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/utf8.c b/utf8.c
index 8f530b0..20985b4 100644
--- a/utf8.c
+++ b/utf8.c
@@ -77,3 +77,20 @@ valid_multibyte_utf8(struct parser *p)
}
return 1;
}
+
+char *
+utf8_nth(char *s, size_t n)
+{
+ size_t i;
+ uint32_t cp = 0, state = 0;
+
+ for (i = 0; *s && i < n; ++s)
+ if (!utf8_decode(&state, &cp, *s))
+ ++i;
+
+ if (state != UTF8_ACCEPT)
+ return NULL;
+ if (i == n)
+ return s;
+ return NULL;
+}