summaryrefslogtreecommitdiff
path: root/unicode.c
diff options
context:
space:
mode:
Diffstat (limited to 'unicode.c')
-rw-r--r--unicode.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/unicode.c b/unicode.c
index 3d81a34..6d115a9 100644
--- a/unicode.c
+++ b/unicode.c
@@ -1,7 +1,20 @@
#include <stdint.h>
#include <stddef.h>
+#include <string.h>
#include "unicode.h"
+int utf8_last_size(const char *str) {
+ int len = 0;
+ char *pos = strchr(str, '\0');
+ while (pos > str) {
+ --pos; ++len;
+ if ((*pos & 0xc0) != 0x80) {
+ return len;
+ }
+ }
+ return 0;
+}
+
size_t utf8_chsize(uint32_t ch) {
if (ch < 0x80) {
return 1;