From f77cbdabec0d6312323c5635d704b06a473c9222 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 28 Jun 2015 17:29:34 -0400 Subject: [PATCH] Added ctype include --- source/libc.h | 1 + source/utf/rune.c | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/source/libc.h b/source/libc.h index ab87ee8..f79f938 100644 --- a/source/libc.h +++ b/source/libc.h @@ -14,6 +14,7 @@ #include #include #include +#include #ifndef nil #define nil NULL diff --git a/source/utf/rune.c b/source/utf/rune.c index 45d9754..5c9df42 100644 --- a/source/utf/rune.c +++ b/source/utf/rune.c @@ -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; } -- 2.54.0