diff options
| author | bluebear94 <[email protected]> | 2016-07-22 04:55:55 -0400 |
|---|---|---|
| committer | bluebear94 <[email protected]> | 2016-07-22 04:55:55 -0400 |
| commit | 8a24caa4056ac18d8fbae84728a5ea4ee4604d32 (patch) | |
| tree | 15eff6928985402e09a736706a37314d82fa3864 /utf8.h | |
| download | sanstop-8a24caa4056ac18d8fbae84728a5ea4ee4604d32.tar.xz sanstop-8a24caa4056ac18d8fbae84728a5ea4ee4604d32.zip | |
Initial commit (first release plus some changes)
Diffstat (limited to 'utf8.h')
| -rwxr-xr-x | utf8.h | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -0,0 +1,44 @@ +#pragma once
+
+#include <stdlib.h>
+
+inline int isASCII(unsigned char c) {
+ return c < 128;
+}
+inline int isContinuation(unsigned char c) {
+ return c >= 128 && c < 192;
+}
+inline int is2ByteStarter(unsigned char c) {
+ return c >= 192 && c < 224;
+}
+inline int is3ByteStarter(unsigned char c) {
+ return c >= 224 && c < 240;
+}
+inline int is4ByteStarter(unsigned char c) {
+ return c >= 240 && c < 248;
+}
+inline int utf8DecodeErrorClass(int err) {
+ return err >> 12;
+}
+
+#define ERR_UNEXPECTED_CONTINUATION 0x1000
+#define ERR_INVALID_UTF8_BYTE 0x2000
+#define ERR_CONTINUATION_EXPECTED 0x3000
+#define ERRC_UNEXPECTED_CONTINUATION 0x1
+#define ERRC_INVALID_UTF8_BYTE 0x2
+#define ERRC_CONTINUATION_EXPECTED 0x3
+
+/*
+ Returns the next UTF-8 character and advances the string pointer.
+ This function does not consider the case when the current byte
+ does not align with any codepoint.
+ @param strRef a pointer to a pointer to the current character
+ @param codeRef where you want the resulting codepoint to be stored
+ @return
+ 0 if everything went well
+ ERR_UNEXPECTED_CONTINUATION + 0x100 * bytes advanced + byte
+ if an unexpected continuation byte was found
+ ERR_INVALID_UTF8_BYTE + 0x100 * bytes advanced + byte
+ if an unexpected continuation byte was found
+*/
+int utf8Next(char** strRef, int* codeRef);
|