]> git.mdlowis.com Git - archive/carl.git/commitdiff
Added ctype include
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 28 Jun 2015 21:29:34 +0000 (17:29 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 28 Jun 2015 21:29:34 +0000 (17:29 -0400)
source/libc.h
source/utf/rune.c

index ab87ee8e7a64cc5bf6ebaeac13cd00b4ce717957..f79f938e736646812f4c20be205716f61c7d37d9 100644 (file)
@@ -14,6 +14,7 @@
 #include <stdint.h>
 #include <stdarg.h>
 #include <errno.h>
+#include <ctype.h>
 
 #ifndef nil
 #define nil NULL
index 45d9754f7faf5681372e2e330e4468850810e671..5c9df42840255770f3dd50bbcec96a3f76d4efa5 100644 (file)
@@ -16,21 +16,34 @@ int chartorune(Rune* r, char* s)
 
 int runelen(long r)
 {
-    (void)r;
-    return 0;
+    if(r <= 0x7F)
+        return 1;
+    else if(r <= 0x07FF)
+        return 2;
+    else if(r <= 0xD7FF)
+        return 3;
+    else if(r <= 0xDFFF)
+        return 0; /* surrogate character */
+    else if(r <= 0xFFFD)
+        return 3;
+    else if(r <= 0xFFFF)
+        return 0; /* illegal character */
+    else if(r <= Runemax)
+        return 4;
+    else
+        return 0; /* rune too large */
 }
 
 int runenlen(Rune* r, int num)
 {
-    (void)r;
-    (void)num;
-    return 0;
+    size_t i, n = 0;
+    for(i = 0; i < num; i++)
+        n += runelen(r[i]);
+    return n;
 }
 
 bool fullrune(char* s, int n)
 {
-    (void)s;
-    (void)n;
     return false;
 }