aboutsummaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
authorBruce Mitchener <bruce.mitchener@gmail.com>2013-04-29 15:30:32 +0700
committerBruce Mitchener <bruce.mitchener@gmail.com>2013-04-29 15:30:32 +0700
commitedc773c64d30030e74c9f95056c6d2fd47385d83 (patch)
tree8df366cd4b2f32c261a694f9306ec06791d17649 /system
parent454d7f9dd208646035b1598c9aa615500aa76af4 (diff)
[libcextra] Add wcwidth, wcswidth.
Diffstat (limited to 'system')
-rw-r--r--system/lib/libc/musl/src/ctype/wcswidth.c8
-rw-r--r--system/lib/libc/musl/src/ctype/wcwidth.c29
-rw-r--r--system/lib/libcextra.symbols2
3 files changed, 39 insertions, 0 deletions
diff --git a/system/lib/libc/musl/src/ctype/wcswidth.c b/system/lib/libc/musl/src/ctype/wcswidth.c
new file mode 100644
index 00000000..5c8a5a4d
--- /dev/null
+++ b/system/lib/libc/musl/src/ctype/wcswidth.c
@@ -0,0 +1,8 @@
+#include <wchar.h>
+
+int wcswidth(const wchar_t *wcs, size_t n)
+{
+ int l=0, k=0;
+ for (; n-- && *wcs && (k = wcwidth(*wcs)) >= 0; l+=k, wcs++);
+ return (k < 0) ? k : l;
+}
diff --git a/system/lib/libc/musl/src/ctype/wcwidth.c b/system/lib/libc/musl/src/ctype/wcwidth.c
new file mode 100644
index 00000000..49c40eea
--- /dev/null
+++ b/system/lib/libc/musl/src/ctype/wcwidth.c
@@ -0,0 +1,29 @@
+#include <wchar.h>
+
+static const unsigned char table[] = {
+#include "nonspacing.h"
+};
+
+static const unsigned char wtable[] = {
+#include "wide.h"
+};
+
+int wcwidth(wchar_t wc)
+{
+ if (wc < 0xffU)
+ return (wc+1 & 0x7f) >= 0x21 ? 1 : wc ? -1 : 0;
+ if ((wc & 0xfffeffffU) < 0xfffe) {
+ if ((table[table[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1)
+ return 0;
+ if ((wtable[wtable[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1)
+ return 2;
+ return 1;
+ }
+ if ((wc & 0xfffe) == 0xfffe)
+ return -1;
+ if (wc-0x20000U < 0x20000)
+ return 2;
+ if (wc == 0xe0001 || wc-0xe0020U < 0x5f || wc-0xe0100 < 0xef)
+ return 0;
+ return 1;
+}
diff --git a/system/lib/libcextra.symbols b/system/lib/libcextra.symbols
index 345c3d1c..42e66b51 100644
--- a/system/lib/libcextra.symbols
+++ b/system/lib/libcextra.symbols
@@ -48,10 +48,12 @@
T wcstok
T wcstombs
T wcswcs
+ T wcswidth
T wctob
T wctomb
T wctrans
T wctype
+ T wcwidth
T wmemchr
T wmemcmp
T wmemcpy