summaryrefslogtreecommitdiff
path: root/unicode.h
diff options
context:
space:
mode:
Diffstat (limited to 'unicode.h')
-rw-r--r--unicode.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/unicode.h b/unicode.h
index 4e8c020..8765164 100644
--- a/unicode.h
+++ b/unicode.h
@@ -211,4 +211,15 @@ static size_t unicode_utf16_to_utf8_offset(const char *str, size_t utf16_offset)
return SIZE_MAX;
}
+static bool unicode_is_valid_utf8(const char *cstr) {
+ char32_t c = 0;
+ while (*cstr) {
+ size_t n = unicode_utf8_to_utf32(&c, cstr, 4);
+ if (n >= (size_t)-2)
+ return false;
+ cstr += n;
+ }
+ return true;
+}
+
#endif // UNICODE_H_