summaryrefslogtreecommitdiffstats
path: root/unicode/unicode_wcwidth.c
diff options
context:
space:
mode:
authorSam Varshavchik2013-08-19 16:39:41 -0400
committerSam Varshavchik2013-08-25 14:43:51 -0400
commit9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch)
tree7a81a04cb51efb078ee350859a64be2ebc6b8813 /unicode/unicode_wcwidth.c
parenta9520698b770168d1f33d6301463bb70a19655ec (diff)
downloadcourier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2
Initial checkin
Imported from subversion report, converted to git. Updated all paths in scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'unicode/unicode_wcwidth.c')
-rw-r--r--unicode/unicode_wcwidth.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/unicode/unicode_wcwidth.c b/unicode/unicode_wcwidth.c
new file mode 100644
index 0000000..372f7a7
--- /dev/null
+++ b/unicode/unicode_wcwidth.c
@@ -0,0 +1,71 @@
+#include "unicode_config.h"
+#include "unicode.h"
+
+#include "eastasianwidth.h"
+#include "linebreaktab_internal.h"
+
+#include <stdlib.h>
+
+int unicode_wcwidth(unicode_char c)
+{
+ size_t b=0;
+ size_t e=sizeof(unicode_wcwidth_tab)/sizeof(unicode_wcwidth_tab[0]);
+
+ while (b < e)
+ {
+ size_t n=b + (e-b)/2;
+
+ if (c >= unicode_wcwidth_tab[n][0])
+ {
+ if (c <= unicode_wcwidth_tab[n][1])
+ return 2;
+ b=n+1;
+ }
+ else
+ {
+ e=n;
+ }
+ }
+
+ switch (unicode_lb_lookup(c)) {
+ case UNICODE_LB_BK:
+ case UNICODE_LB_CR:
+ case UNICODE_LB_LF:
+ case UNICODE_LB_CM:
+ case UNICODE_LB_NL:
+ case UNICODE_LB_WJ:
+ case UNICODE_LB_ZW:
+ return 0;
+ default:
+ break;
+ }
+ return 1;
+}
+
+int unicode_isspace(unicode_char ch)
+{
+ if (ch == 9)
+ return 1;
+
+ switch (unicode_lb_lookup(ch)) {
+ case UNICODE_LB_BK:
+ case UNICODE_LB_CR:
+ case UNICODE_LB_LF:
+ case UNICODE_LB_NL:
+ case UNICODE_LB_SP:
+ return 1;
+ }
+
+ return 0;
+}
+
+size_t unicode_wcwidth_str(const unicode_char *c)
+{
+ size_t w=0;
+
+ while (*c)
+ w += unicode_wcwidth(*c++);
+
+
+ return w;
+}