diff options
author | Nicholas <nbnoll@eml.cc> | 2021-11-10 20:12:45 -0800 |
---|---|---|
committer | Nicholas <nbnoll@eml.cc> | 2021-11-11 08:16:47 -0800 |
commit | 7ea1cdb7d31f00024f5a1d124b42cd19a03b959a (patch) | |
tree | f65abf9fa32856287de586129d4ed7c1c473864a /sys/libutf/canfit.c | |
parent | 43688fe7190d0350349d47727c3663421d5618dc (diff) |
chore: libunicode -> libutf
Diffstat (limited to 'sys/libutf/canfit.c')
-rw-r--r-- | sys/libutf/canfit.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/sys/libutf/canfit.c b/sys/libutf/canfit.c new file mode 100644 index 0000000..4579ab3 --- /dev/null +++ b/sys/libutf/canfit.c @@ -0,0 +1,23 @@ +#include "internal.h" + +/* returns 1 if string of length n is long enough to be decoded */ +int +utf8·canfit(byte* s, int n) +{ + int i; + rune c; + + if(n <= 0) + return 0; + + c = *(ubyte*)s; + if(c < TByte1) + return 1; + + if(c < TByte3) + return n >= 2; + if(c < TByte4) + return n >= 3; + + return n >= UTFmax; +} |