diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2021-10-26 21:01:41 -0700 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2021-10-26 21:01:41 -0700 |
commit | 29b56ef4e4113bcd091b19d6926f18814162ca53 (patch) | |
tree | a4888a16927576592af13928bb805f1f2b1159d6 /include/libunicode.h | |
parent | e34a4791b72e426b02f33496fe03be1ad81819a6 (diff) |
Feat(libunicode): Added an explicit unicode library
Refactored code to pull out utf8 functions from base into a standalone
library. Also left the required function inside arg.c so that code that
calls ARG_BEGIN doesn't have to link to libunicode.
Diffstat (limited to 'include/libunicode.h')
-rw-r--r-- | include/libunicode.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/include/libunicode.h b/include/libunicode.h new file mode 100644 index 0000000..e017ac5 --- /dev/null +++ b/include/libunicode.h @@ -0,0 +1,36 @@ +#pragma once + +typedef uint32 rune; + +/* + * We have to use the preprocessor to ensure + * we have unsigned constants. Unfortunate... + */ + +#define UTFmax 4 +#define RuneSync 0x80u +#define RuneSelf 0x80u +#define RuneErr 0xFFFDu +#define RuneMax 0x10FFFFu +#define RuneMask 0x1FFFFFu + +/* + * UTF-8 functions. + */ +int utf8·len(char *s); +int utf8·runelen(rune r); + +int utf8·fullrune(char *s, int n); +char *utf8·findrune(char *s, long i); +char *utf8·findrrune(char* s, long c); +int utf8·bytetorune(rune *r, char *s); +int utf8·runetobyte(char *s, rune *r); + +int utf8·isletter(rune r); +int utf8·isdigit(rune r); +int utf8·isspace(rune r); +int utf8·istitle(rune r); + +rune utf8·toupper(rune r); +rune utf8·tolower(rune r); +rune utf8·totitle(rune r); |