diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2021-10-28 11:55:47 -0700 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2021-10-28 11:55:47 -0700 |
commit | 6318ddb69ad8380694bbca35ca5a72230c2ee694 (patch) | |
tree | e9ef65d79c264d88c2d02402a587c2561b5b1299 /sys/libunicode/canfit.c | |
parent | 189b9e23edfe60b7e82c4c7b6071a3f98799653a (diff) |
Feat(libunicode): cleaned up decode/encode
Additionally, decode can now apply backwards on a byte string.
Diffstat (limited to 'sys/libunicode/canfit.c')
-rw-r--r-- | sys/libunicode/canfit.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/sys/libunicode/canfit.c b/sys/libunicode/canfit.c index d44c9e6..4579ab3 100644 --- a/sys/libunicode/canfit.c +++ b/sys/libunicode/canfit.c @@ -7,14 +7,17 @@ utf8·canfit(byte* s, int n) int i; rune c; - if(n <= 0) return 0; - c = *(ubyte*) s; - if(c < Tx) return 1; + if(n <= 0) + return 0; - for(i = 3; i < UTFmax + 1; i++){ - if(c < Tbyte(i)) - return n >= i - 1; - } + c = *(ubyte*)s; + if(c < TByte1) + return 1; + + if(c < TByte3) + return n >= 2; + if(c < TByte4) + return n >= 3; return n >= UTFmax; } |