aboutsummaryrefslogtreecommitdiff
path: root/src/libutf/canfit.c
diff options
context:
space:
mode:
authorNicholas <nbnoll@eml.cc>2021-11-12 09:22:01 -0800
committerNicholas <nbnoll@eml.cc>2021-11-12 09:22:01 -0800
commitce05175372a9ddca1a225db0765ace1127a39293 (patch)
tree5988b4d4f6b402e4953945886fc90aae11203df6 /src/libutf/canfit.c
parentb375f3cdedb5b0e08745d100b40e38d2f8396a58 (diff)
chore: simplified organizational structurelaptop
Diffstat (limited to 'src/libutf/canfit.c')
-rw-r--r--src/libutf/canfit.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libutf/canfit.c b/src/libutf/canfit.c
new file mode 100644
index 0000000..4579ab3
--- /dev/null
+++ b/src/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;
+}