From 6318ddb69ad8380694bbca35ca5a72230c2ee694 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Thu, 28 Oct 2021 11:55:47 -0700 Subject: Feat(libunicode): cleaned up decode/encode Additionally, decode can now apply backwards on a byte string. --- sys/libunicode/canfit.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'sys/libunicode/canfit.c') 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; } -- cgit v1.2.1