aboutsummaryrefslogtreecommitdiff
path: root/wcsmbs
diff options
context:
space:
mode:
Diffstat (limited to 'wcsmbs')
-rw-r--r--wcsmbs/wcwidth.h42
1 files changed, 31 insertions, 11 deletions
diff --git a/wcsmbs/wcwidth.h b/wcsmbs/wcwidth.h
index ffc74be26c..86a2f216bd 100644
--- a/wcsmbs/wcwidth.h
+++ b/wcsmbs/wcwidth.h
@@ -21,27 +21,47 @@
#include <wchar.h>
#include <wctype.h>
#include "../wctype/cname-lookup.h"
+#include "../wctype/wchar-lookup.h"
-/* Array containing width information. */
+/* Tables containing character property information. */
+extern const char *__ctype32_wctype[12];
+
+/* Tables containing width information. */
extern unsigned char *__ctype_width;
+extern const char *__ctype32_width;
/* If the program is compiled without optimization the following declaration
is not visible in the header. */
extern unsigned int *__ctype32_b;
static __inline int
-internal_wcwidth (wint_t ch)
+internal_wcwidth (wint_t wc)
{
- size_t idx;
- unsigned char res;
-
- if (ch == L'\0')
+ if (wc == L'\0')
return 0;
- idx = cname_lookup (ch);
- if (idx == ~((size_t) 0) || (__ctype32_b[idx] & _ISwprint) == 0)
- return -1;
+ if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_HASH_SIZE) != 0)
+ {
+ /* Old locale format. */
+ size_t idx;
+ unsigned char res;
+
+ idx = cname_lookup (wc);
+ if (idx == ~((size_t) 0) || (__ctype32_b[idx] & _ISwprint) == 0)
+ return -1;
+
+ res = __ctype_width[idx];
+ return res == (unsigned char) '\xff' ? -1 : (int) res;
+ }
+ else
+ {
+ /* New locale format. */
+ unsigned char res;
+
+ if (wctype_table_lookup (__ctype32_wctype[__ISwprint], wc) == 0)
+ return -1;
- res = __ctype_width[idx];
- return res == (unsigned char) '\xff' ? -1 : (int) res;
+ res = wcwidth_table_lookup (__ctype32_width, wc);
+ return res == (unsigned char) '\xff' ? -1 : (int) res;
+ }
}