diff options
author | Omar Polo <op@omarpolo.com> | 2021-01-27 10:47:49 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2021-01-27 10:47:49 +0000 |
commit | 3300cbe06a9567c66ee63f3866bcbcf3430e0205 (patch) | |
tree | a7686f8e774573b55ebbe18373a27eb60f44baa4 /utf8.c | |
parent | 390a61189309451462c0a1dc56c68f71e334ad4b (diff) |
initial punycode support
Diffstat (limited to 'utf8.c')
-rw-r--r-- | utf8.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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; +} |