aboutsummaryrefslogtreecommitdiff
path: root/src/system
diff options
context:
space:
mode:
Diffstat (limited to 'src/system')
-rw-r--r--src/system/utf8.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/system/utf8.c b/src/system/utf8.c
index 201fedf..5d5ec79 100644
--- a/src/system/utf8.c
+++ b/src/system/utf8.c
@@ -73,3 +73,20 @@ bool mgl_utf8_decode(const unsigned char *str, size_t size, uint32_t *decoded_co
*decoded_codepoint = codepoint;
return true;
}
+
+/* TODO: Optimize (remove branching, etc) */
+size_t mgl_utf8_get_start_of_codepoint(const unsigned char *str, size_t size, size_t offset) {
+ if(size == 0)
+ return 0;
+
+ if(offset > size - 1)
+ offset = size - 1;
+
+ /* i <= offset is an overflow (underflow?) check */
+ for(size_t i = offset; i <= offset; --i) {
+ if((str[i] & 0xC0) != 0x80)
+ return i;
+ }
+
+ return 0;
+}