aboutsummaryrefslogtreecommitdiff
path: root/wctype
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-07-25 04:37:22 +0000
committerUlrich Drepper <drepper@redhat.com>2000-07-25 04:37:22 +0000
commitef4461440540e0ad4e25ba35203594e25dc38b3a (patch)
tree6b454c8f044abd370ab99f5e7f05f34b98d13fb6 /wctype
parentf79d99cb260028d1eae399c99f8cee645a32538f (diff)
downloadglibc-ef4461440540e0ad4e25ba35203594e25dc38b3a.tar
glibc-ef4461440540e0ad4e25ba35203594e25dc38b3a.tar.gz
glibc-ef4461440540e0ad4e25ba35203594e25dc38b3a.tar.bz2
glibc-ef4461440540e0ad4e25ba35203594e25dc38b3a.zip
Update.
2000-07-23 Bruno Haible <haible@clisp.cons.org> * wctype/wchar-lookup.h: New file. * wctype/iswctype.c: Include "wchar-lookup.h". (__iswctype): Support alternate locale format with 3-level tables. * wctype/iswctype_l.c (__iswctype_l): Likewise. * wctype/towctrans.c (__towctrans): Likewise. * wctype/towctrans_l.c (__towctrans_l): Likewise. * wctype/wcfuncs.c: Include "wchar-lookup.h". (__ctype32_wctype, __ctype32_wctrans): Declare external. (__iswalnum, __iswalpha, __iswcntrl, __iswdigit, __iswlower, __iswgraph, __iswprint, __iswpunct, __iswspace, __iswupper, __iswxdigit, towlower, towupper): Support alternate locale format with 3-level tables. * wctype/wcextra.c (iswblank): Likewise. * wctype/wcfuncs_l.c: Include "wchar-lookup.h". (__iswalnum_l, __iswalpha_l, __iswcntrl_l, __iswdigit_l, __iswlower_l, __iswgraph_l, __iswprint_l, __iswpunct_l, __iswspace_l, __iswupper_l, __iswxdigit_l, __towlower_l, __towupper_l): Support alternate locale format with 3-level tables. * wctype/wcextra_l.c (__iswblank_l): Likewise. * wctype/wctype.c (__wctype): Likewise. In the alternate locale format, return a 3-level table pointer. * wctype/wctype_l.c (__wctype_l): Likewise. * wctype/wctrans.c (wctrans): Likewise. * wctype/wctype.h (__ISwupper, __ISwlower, __ISwalpha, __ISwdigit, __ISwxdigit, __ISwspace, __ISwprint, __ISwgraph, __ISwblank, __ISwcntrl, __ISwpunct, __ISwalnum): New enum values. (iswctype): Remove macro definition. * wcsmbs/wcwidth.h: Include "wchar-lookup.h". (internal_wcwidth): Support alternate locale format with 3-level tables. * locale/langinfo.h (_NL_CTYPE_CLASS_OFFSET, _NL_CTYPE_MAP_OFFSET): New nl_items. * locale/categories.def (_NL_CTYPE_CLASS_OFFSET, _NL_CTYPE_MAP_OFFSET): Define them as being type "word". * locale/C-ctype.c (_nl_C_LC_CTYPE): Add initializers for them. * ctype/ctype-info.c (__ctype32_wctype, __ctype32_wctrans, __ctype32_width): New exported variables. * locale/lc-ctype.c (_nl_postload_ctype): Initialize them in the alternate locale format. Don't initialize __ctype_names and __ctype_width in the alternate locale format. * locale/programs/localedef.h (oldstyle_tables): New declaration. * locale/programs/localedef.c (oldstyle_tables): New variable. (OPT_OLDSTYLE): New macro. (options): Add --old-style option. (parse_opt): Handle --old-style option. * locale/programs/ld-ctype.c (locale_ctype_t): Add class_offset, map_offset, class_3level, map_3level, width_3level members. (ctype_output): Support for alternate locale format: Computation of nelems changes. _NL_CTYPE_TOUPPER32, _NL_CTYPE_TOLOWER32 and _NL_CTYPE_CLASS32 only 256 characters. _NL_CTYPE_NAMES empty. New fields _NL_CTYPE_CLASS_OFFSET, _NL_CTYPE_MAP_OFFSET. Field _NL_CTYPE_WIDTH now contains the three-level table. Extra elems now contain both class and map tables. (struct wctype_table): New type. (wctype_table_init, wctype_table_add, wctype_table_finalize): New functions. (struct wcwidth_table): New type. (wcwidth_table_init, wcwidth_table_add, wcwidth_table_finalize): New functions. (struct wctrans_table): New type. (wctrans_table_init, wctrans_table_add, wctrans_table_finalize): New functions. (allocate_arrays): Support for alternate locale format: Set plane_size and plane_cnt to 0. Restrict ctype->ctype32_b to the first 256 characters. Compute ctype->class_3level. Restrict ctype->map32[idx] to the first 256 characters. Compute ctype->map_3level. Set ctype->class_offset and ctype->map_offset. Compute ctype->width_3level instead of ctype->width.
Diffstat (limited to 'wctype')
-rw-r--r--wctype/iswctype.c31
-rw-r--r--wctype/iswctype_l.c37
-rw-r--r--wctype/towctrans.c26
-rw-r--r--wctype/towctrans_l.c29
-rw-r--r--wctype/wcextra.c29
-rw-r--r--wctype/wcextra_l.c36
-rw-r--r--wctype/wcfuncs.c94
-rw-r--r--wctype/wcfuncs_l.c116
-rw-r--r--wctype/wchar-lookup.h139
-rw-r--r--wctype/wctrans.c25
-rw-r--r--wctype/wctype.c21
-rw-r--r--wctype/wctype.h42
-rw-r--r--wctype/wctype_l.c21
13 files changed, 487 insertions, 159 deletions
diff --git a/wctype/iswctype.c b/wctype/iswctype.c
index 58a2a5288f..60475d0192 100644
--- a/wctype/iswctype.c
+++ b/wctype/iswctype.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>.
@@ -21,6 +21,7 @@
#include <wctype.h>
#include "cname-lookup.h"
+#include "wchar-lookup.h"
extern unsigned int *__ctype32_b;
@@ -29,12 +30,26 @@ extern unsigned int *__ctype32_b;
int
__iswctype (wint_t wc, wctype_t desc)
{
- size_t idx;
-
- idx = cname_lookup (wc);
- if (idx == ~((size_t) 0))
- return 0;
-
- return __ctype32_b[idx] & desc;
+ if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_HASH_SIZE) != 0)
+ {
+ /* Old locale format. */
+ size_t idx;
+
+ idx = cname_lookup (wc);
+ if (idx == ~((size_t) 0))
+ return 0;
+
+ return __ctype32_b[idx] & desc;
+ }
+ else
+ {
+ /* If the user passes in an invalid DESC valid (the one returned from
+ `wctype' in case of an error) simply return 0. */
+ if (desc == (wctype_t) 0)
+ return 0;
+
+ /* New locale format. */
+ return wctype_table_lookup ((const char *) desc, wc);
+ }
}
weak_alias (__iswctype, iswctype)
diff --git a/wctype/iswctype_l.c b/wctype/iswctype_l.c
index fa4e024fce..192001e033 100644
--- a/wctype/iswctype_l.c
+++ b/wctype/iswctype_l.c
@@ -22,20 +22,35 @@
#define USE_IN_EXTENDED_LOCALE_MODEL 1
#include "cname-lookup.h"
+#include "wchar-lookup.h"
int
__iswctype_l (wint_t wc, wctype_t desc, __locale_t locale)
{
- const uint32_t *class32_b;
- size_t idx;
-
- idx = cname_lookup (wc, locale);
- if (idx == ~((size_t) 0))
- return 0;
-
- class32_b = (uint32_t *)
- locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_CLASS32)].string;
-
- return class32_b[idx] & desc;
+ if (locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_HASH_SIZE)].word != 0)
+ {
+ /* Old locale format. */
+ const uint32_t *class32_b;
+ size_t idx;
+
+ idx = cname_lookup (wc, locale);
+ if (idx == ~((size_t) 0))
+ return 0;
+
+ class32_b = (uint32_t *)
+ locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_CLASS32)].string;
+
+ return class32_b[idx] & desc;
+ }
+ else
+ {
+ /* If the user passes in an invalid DESC valid (the one returned from
+ `__wctype_l' in case of an error) simply return 0. */
+ if (desc == (wctype_t) 0)
+ return 0;
+
+ /* New locale format. */
+ return wctype_table_lookup ((const char *) desc, wc);
+ }
}
diff --git a/wctype/towctrans.c b/wctype/towctrans.c
index 425fd52d46..498417b80a 100644
--- a/wctype/towctrans.c
+++ b/wctype/towctrans.c
@@ -21,22 +21,32 @@
/* Define the lookup function. */
#include "cname-lookup.h"
+#include "wchar-lookup.h"
wint_t
__towctrans (wint_t wc, wctrans_t desc)
{
- size_t idx;
-
/* If the user passes in an invalid DESC valid (the one returned from
`wctrans' in case of an error) simply return the value. */
if (desc == (wctrans_t) 0)
return wc;
- idx = cname_lookup (wc);
- if (idx == ~((size_t) 0))
- /* Character is not known. Default action is to simply return it. */
- return wc;
-
- return (wint_t) desc[idx];
+ if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_HASH_SIZE) != 0)
+ {
+ /* Old locale format. */
+ size_t idx;
+
+ idx = cname_lookup (wc);
+ if (idx == ~((size_t) 0))
+ /* Character is not known. Default action is to simply return it. */
+ return wc;
+
+ return (wint_t) desc[idx];
+ }
+ else
+ {
+ /* New locale format. */
+ return wctrans_table_lookup ((const char *) desc, wc);
+ }
}
weak_alias (__towctrans, towctrans)
diff --git a/wctype/towctrans_l.c b/wctype/towctrans_l.c
index 09596b9685..e3624441ca 100644
--- a/wctype/towctrans_l.c
+++ b/wctype/towctrans_l.c
@@ -1,5 +1,5 @@
/* Map wide character using given mapping and locale.
- Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -22,16 +22,31 @@
/* Define the lookup function. */
#define USE_IN_EXTENDED_LOCALE_MODEL 1
#include "cname-lookup.h"
+#include "wchar-lookup.h"
wint_t
__towctrans_l (wint_t wc, wctrans_t desc, __locale_t locale)
{
- size_t idx;
-
- idx = cname_lookup (wc, locale);
- if (idx == ~((size_t) 0))
- /* Character is not known. Default action is to simply return it. */
+ /* If the user passes in an invalid DESC valid (the one returned from
+ `__wctrans_l' in case of an error) simply return the value. */
+ if (desc == (wctrans_t) 0)
return wc;
- return (wint_t) desc[idx];
+ if (locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_HASH_SIZE)].word != 0)
+ {
+ /* Old locale format. */
+ size_t idx;
+
+ idx = cname_lookup (wc, locale);
+ if (idx == ~((size_t) 0))
+ /* Character is not known. Default action is to simply return it. */
+ return wc;
+
+ return (wint_t) desc[idx];
+ }
+ else
+ {
+ /* New locale format. */
+ return wctrans_table_lookup ((const char *) desc, wc);
+ }
}
diff --git a/wctype/wcextra.c b/wctype/wcextra.c
index 44b72c8833..581c6807de 100644
--- a/wctype/wcextra.c
+++ b/wctype/wcextra.c
@@ -1,5 +1,5 @@
/* Additional non standardized wide character classification functions.
- Copyright (C) 1997, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
@@ -23,19 +23,32 @@
#include <wctype.h>
#include "cname-lookup.h"
+#include "wchar-lookup.h"
/* If the program is compiled without optimization the following declaration
is not visible in the header. */
extern unsigned int *__ctype32_b;
+/* This is not exported. */
+extern const char *__ctype32_wctype[12];
+
int
(iswblank) (wint_t wc)
{
- size_t idx;
-
- idx = cname_lookup (wc);
- if (idx == ~((size_t) 0))
- return 0;
-
- return __ctype32_b[idx] & _ISwblank;
+ if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_HASH_SIZE) != 0)
+ {
+ /* Old locale format. */
+ size_t idx;
+
+ idx = cname_lookup (wc);
+ if (idx == ~((size_t) 0))
+ return 0;
+
+ return __ctype32_b[idx] & _ISwblank;
+ }
+ else
+ {
+ /* New locale format. */
+ return wctype_table_lookup (__ctype32_wctype[__ISwblank], wc);
+ }
}
diff --git a/wctype/wcextra_l.c b/wctype/wcextra_l.c
index d326327954..8fc9c2733d 100644
--- a/wctype/wcextra_l.c
+++ b/wctype/wcextra_l.c
@@ -1,5 +1,5 @@
/* Additional non standardized wide character classification functions.
- Copyright (C) 1997, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
@@ -24,20 +24,32 @@
#define USE_IN_EXTENDED_LOCALE_MODEL 1
#include "cname-lookup.h"
+#include "wchar-lookup.h"
int
(__iswblank_l) (wint_t wc, __locale_t locale)
{
- const unsigned int *class32_b;
- size_t idx;
-
- idx = cname_lookup (wc, locale);
- if (idx == ~((size_t) 0))
- return 0;
-
- class32_b = (uint32_t *)
- locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_CLASS32)].string;
-
- return class32_b[idx] & _ISwblank;
+ if (locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_HASH_SIZE)].word != 0)
+ {
+ /* Old locale format. */
+ const uint32_t *class32_b;
+ size_t idx;
+
+ idx = cname_lookup (wc, locale);
+ if (idx == ~((size_t) 0))
+ return 0;
+
+ class32_b = (uint32_t *)
+ locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_CLASS32)].string;
+
+ return class32_b[idx] & _ISwbit (__ISwblank);
+ }
+ else
+ {
+ /* New locale format. */
+ size_t i = locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_CLASS_OFFSET)].word + __ISwblank;
+ const char *desc = locale->__locales[LC_CTYPE]->values[i].string;
+ return wctype_table_lookup (desc, wc);
+ }
}
diff --git a/wctype/wcfuncs.c b/wctype/wcfuncs.c
index fdb5dc7a70..f241ed5587 100644
--- a/wctype/wcfuncs.c
+++ b/wctype/wcfuncs.c
@@ -21,6 +21,7 @@
#include <ctype.h> /* For __ctype_tolower and __ctype_toupper. */
#include "cname-lookup.h"
+#include "wchar-lookup.h"
/* If the program is compiled without optimization the following declaration
is not visible in the header. */
@@ -29,6 +30,8 @@ extern unsigned int *__ctype32_b;
/* These are not exported. */
extern const uint32_t *__ctype32_toupper;
extern const uint32_t *__ctype32_tolower;
+extern const char *__ctype32_wctype[12];
+extern const char *__ctype32_wctrans[2];
/* Provide real-function versions of all the wctype macros. */
@@ -36,63 +39,90 @@ extern const uint32_t *__ctype32_tolower;
int \
__##name (wint_t wc) \
{ \
- size_t idx; \
+ if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_HASH_SIZE) != 0) \
+ { \
+ /* Old locale format. */ \
+ size_t idx; \
\
- idx = cname_lookup (wc); \
- if (idx == ~((size_t) 0)) \
- return 0; \
+ idx = cname_lookup (wc); \
+ if (idx == ~((size_t) 0)) \
+ return 0; \
\
- return __ctype32_b[idx] & type; \
+ return __ctype32_b[idx] & _ISwbit (type); \
+ } \
+ else \
+ { \
+ /* New locale format. */ \
+ return wctype_table_lookup (__ctype32_wctype[type], wc); \
+ } \
} \
weak_alias (__##name, name)
#undef iswalnum
-func (iswalnum, _ISwalnum)
+func (iswalnum, __ISwalnum)
#undef iswalpha
-func (iswalpha, _ISwalpha)
+func (iswalpha, __ISwalpha)
#undef iswcntrl
-func (iswcntrl, _ISwcntrl)
+func (iswcntrl, __ISwcntrl)
#undef iswdigit
-func (iswdigit, _ISwdigit)
+func (iswdigit, __ISwdigit)
#undef iswlower
-func (iswlower, _ISwlower)
+func (iswlower, __ISwlower)
#undef iswgraph
-func (iswgraph, _ISwgraph)
+func (iswgraph, __ISwgraph)
#undef iswprint
-func (iswprint, _ISwprint)
+func (iswprint, __ISwprint)
#undef iswpunct
-func (iswpunct, _ISwpunct)
+func (iswpunct, __ISwpunct)
#undef iswspace
-func (iswspace, _ISwspace)
+func (iswspace, __ISwspace)
#undef iswupper
-func (iswupper, _ISwupper)
+func (iswupper, __ISwupper)
#undef iswxdigit
-func (iswxdigit, _ISwxdigit)
+func (iswxdigit, __ISwxdigit)
wint_t
(towlower) (wc)
wint_t wc;
{
- size_t idx;
-
- idx = cname_lookup (wc);
- if (idx == ~((size_t) 0))
- /* Character is not known. Default action is to simply return it. */
- return wc;
-
- return (wint_t) __ctype32_tolower[idx];
+ if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_HASH_SIZE) != 0)
+ {
+ /* Old locale format. */
+ size_t idx;
+
+ idx = cname_lookup (wc);
+ if (idx == ~((size_t) 0))
+ /* Character is not known. Default action is to simply return it. */
+ return wc;
+
+ return (wint_t) __ctype32_tolower[idx];
+ }
+ else
+ {
+ /* New locale format. */
+ return wctrans_table_lookup (__ctype32_wctrans[1], wc);
+ }
}
wint_t
(towupper) (wc)
wint_t wc;
{
- size_t idx;
-
- idx = cname_lookup (wc);
- if (idx == ~((size_t) 0))
- /* Character is not known. Default action is to simply return it. */
- return wc;
-
- return (wint_t) __ctype32_toupper[idx];
+ if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_HASH_SIZE) != 0)
+ {
+ /* Old locale format. */
+ size_t idx;
+
+ idx = cname_lookup (wc);
+ if (idx == ~((size_t) 0))
+ /* Character is not known. Default action is to simply return it. */
+ return wc;
+
+ return (wint_t) __ctype32_toupper[idx];
+ }
+ else
+ {
+ /* New locale format. */
+ return wctrans_table_lookup (__ctype32_wctrans[0], wc);
+ }
}
diff --git a/wctype/wcfuncs_l.c b/wctype/wcfuncs_l.c
index 0c75359a41..7b8eb96ce6 100644
--- a/wctype/wcfuncs_l.c
+++ b/wctype/wcfuncs_l.c
@@ -22,53 +22,99 @@
#define USE_IN_EXTENDED_LOCALE_MODEL
#include "cname-lookup.h"
+#include "wchar-lookup.h"
/* Provide real-function versions of all the wctype macros. */
#define func(name, type) \
int name (wint_t wc, __locale_t locale) \
- { return __iswctype_l (wc, type, locale); }
-
-func (__iswalnum_l, _ISwalnum)
-func (__iswalpha_l, _ISwalpha)
-func (__iswcntrl_l, _ISwcntrl)
-func (__iswdigit_l, _ISwdigit)
-func (__iswlower_l, _ISwlower)
-func (__iswgraph_l, _ISwgraph)
-func (__iswprint_l, _ISwprint)
-func (__iswpunct_l, _ISwpunct)
-func (__iswspace_l, _ISwspace)
-func (__iswupper_l, _ISwupper)
-func (__iswxdigit_l, _ISwxdigit)
+ { \
+ if (locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_HASH_SIZE)].word != 0) \
+ { \
+ /* Old locale format. */ \
+ const uint32_t *class32_b; \
+ size_t idx; \
+ \
+ idx = cname_lookup (wc, locale); \
+ if (idx == ~((size_t) 0)) \
+ return 0; \
+ \
+ class32_b = (uint32_t *) \
+ locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_CLASS32)].string; \
+ \
+ return class32_b[idx] & _ISwbit (type); \
+ } \
+ else \
+ { \
+ /* New locale format. */ \
+ size_t i = locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_CLASS_OFFSET)].word + type; \
+ const char *desc = locale->__locales[LC_CTYPE]->values[i].string; \
+ return wctype_table_lookup (desc, wc); \
+ } \
+ }
+
+func (__iswalnum_l, __ISwalnum)
+func (__iswalpha_l, __ISwalpha)
+func (__iswcntrl_l, __ISwcntrl)
+func (__iswdigit_l, __ISwdigit)
+func (__iswlower_l, __ISwlower)
+func (__iswgraph_l, __ISwgraph)
+func (__iswprint_l, __ISwprint)
+func (__iswpunct_l, __ISwpunct)
+func (__iswspace_l, __ISwspace)
+func (__iswupper_l, __ISwupper)
+func (__iswxdigit_l, __ISwxdigit)
wint_t
(__towlower_l) (wint_t wc, __locale_t locale)
{
- const int32_t *class32_tolower;
- size_t idx;
-
- idx = cname_lookup (wc, locale);
- if (idx == ~((size_t) 0))
- return 0;
-
- class32_tolower = (const int32_t *)
- locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_TOLOWER32)].string;
-
- return class32_tolower[idx];
+ if (locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_HASH_SIZE)].word != 0)
+ {
+ /* Old locale format. */
+ const int32_t *class32_tolower;
+ size_t idx;
+
+ idx = cname_lookup (wc, locale);
+ if (idx == ~((size_t) 0))
+ return 0;
+
+ class32_tolower = (const int32_t *)
+ locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_TOLOWER32)].string;
+
+ return class32_tolower[idx];
+ }
+ else
+ {
+ /* New locale format. */
+ size_t i = locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_MAP_OFFSET)].word + 1;
+ const char *desc = locale->__locales[LC_CTYPE]->values[i].string;
+ return wctrans_table_lookup (desc, wc);
+ }
}
wint_t
(__towupper_l) (wint_t wc, __locale_t locale)
{
- const int32_t *class32_toupper;
- size_t idx;
-
- idx = cname_lookup (wc, locale);
- if (idx == ~((size_t) 0))
- return 0;
-
- class32_toupper = (const int32_t *)
- locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_TOUPPER32)].string;
-
- return class32_toupper[idx];
+ if (locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_HASH_SIZE)].word != 0)
+ {
+ /* Old locale format. */
+ const int32_t *class32_toupper;
+ size_t idx;
+
+ idx = cname_lookup (wc, locale);
+ if (idx == ~((size_t) 0))
+ return 0;
+
+ class32_toupper = (const int32_t *)
+ locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_TOUPPER32)].string;
+
+ return class32_toupper[idx];
+ }
+ else
+ {
+ /* New locale format. */
+ size_t i = locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_MAP_OFFSET)].word + 0;
+ const char *desc = locale->__locales[LC_CTYPE]->values[i].string;
+ return wctrans_table_lookup (desc, wc);
+ }
}
diff --git a/wctype/wchar-lookup.h b/wctype/wchar-lookup.h
new file mode 100644
index 0000000000..1d08492035
--- /dev/null
+++ b/wctype/wchar-lookup.h
@@ -0,0 +1,139 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Bruno Haible <haible@clisp.cons.org>, 2000.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* Tables indexed by a wide character are compressed through the use
+ of a multi-level lookup. The compression effect comes from blocks
+ that don't need particular data and from block that can share their
+ data. */
+
+/* Bit tables are accessed by cutting wc in four blocks of bits:
+ - the high 32-q-p bits,
+ - the next q bits,
+ - the next p bits,
+ - the next 5 bits.
+
+ +------------------+-----+-----+-----+
+ wc = + 32-q-p-5 | q | p | 5 |
+ +------------------+-----+-----+-----+
+
+ p and q are variable. For 16-bit Unicode it is sufficient to
+ choose p and q such that q+p+5 <= 16.
+
+ The table contains the following uint32_t words:
+ - q+p+5,
+ - s = upper exclusive bound for wc >> (q+p+5),
+ - p+5,
+ - 2^q-1,
+ - 2^p-1,
+ - 1st-level table: s offsets, pointing into the 2nd-level table,
+ - 2nd-level table: k*2^q offsets, pointing into the 3rd-level table,
+ - 3rd-level table: j*2^p words, each containing 32 bits of data.
+*/
+
+static __inline int
+wctype_table_lookup (const char *table, uint32_t wc)
+{
+ uint32_t shift1 = ((const uint32_t *) table)[0];
+ uint32_t index1 = wc >> shift1;
+ uint32_t bound = ((const uint32_t *) table)[1];
+ if (index1 < bound)
+ {
+ uint32_t lookup1 = ((const uint32_t *) table)[5 + index1];
+ if (lookup1 != 0)
+ {
+ uint32_t shift2 = ((const uint32_t *) table)[2];
+ uint32_t mask2 = ((const uint32_t *) table)[3];
+ uint32_t index2 = (wc >> shift2) & mask2;
+ uint32_t lookup2 = ((const uint32_t *)(table + lookup1))[index2];
+ if (lookup2 != 0)
+ {
+ uint32_t mask3 = ((const uint32_t *) table)[4];
+ uint32_t index3 = (wc >> 5) & mask3;
+ uint32_t lookup3 = ((const uint32_t *)(table + lookup2))[index3];
+
+ return (lookup3 >> (wc & 0x1f)) & 1;
+ }
+ }
+ }
+ return 0;
+}
+
+/* Byte tables are similar to bit tables, except that the addressing
+ unit is a single byte, and no 5 bits are used as a word index. */
+
+static __inline int
+wcwidth_table_lookup (const char *table, uint32_t wc)
+{
+ uint32_t shift1 = ((const uint32_t *) table)[0];
+ uint32_t index1 = wc >> shift1;
+ uint32_t bound = ((const uint32_t *) table)[1];
+ if (index1 < bound)
+ {
+ uint32_t lookup1 = ((const uint32_t *) table)[5 + index1];
+ if (lookup1 != 0)
+ {
+ uint32_t shift2 = ((const uint32_t *) table)[2];
+ uint32_t mask2 = ((const uint32_t *) table)[3];
+ uint32_t index2 = (wc >> shift2) & mask2;
+ uint32_t lookup2 = ((const uint32_t *)(table + lookup1))[index2];
+ if (lookup2 != 0)
+ {
+ uint32_t mask3 = ((const uint32_t *) table)[4];
+ uint32_t index3 = wc & mask3;
+ uint8_t lookup3 = ((const uint8_t *)(table + lookup2))[index3];
+
+ return lookup3;
+ }
+ }
+ }
+ return 0xff;
+}
+
+/* Mapping tables are similar to bit tables, except that the
+ addressing unit is a single signed 32-bit word, containing the
+ difference between the desired result and the argument, and no 5
+ bits are used as a word index. */
+
+static __inline uint32_t
+wctrans_table_lookup (const char *table, uint32_t wc)
+{
+ uint32_t shift1 = ((const uint32_t *) table)[0];
+ uint32_t index1 = wc >> shift1;
+ uint32_t bound = ((const uint32_t *) table)[1];
+ if (index1 < bound)
+ {
+ uint32_t lookup1 = ((const uint32_t *) table)[5 + index1];
+ if (lookup1 != 0)
+ {
+ uint32_t shift2 = ((const uint32_t *) table)[2];
+ uint32_t mask2 = ((const uint32_t *) table)[3];
+ uint32_t index2 = (wc >> shift2) & mask2;
+ uint32_t lookup2 = ((const uint32_t *)(table + lookup1))[index2];
+ if (lookup2 != 0)
+ {
+ uint32_t mask3 = ((const uint32_t *) table)[4];
+ uint32_t index3 = wc & mask3;
+ int32_t lookup3 = ((const int32_t *)(table + lookup2))[index3];
+
+ return wc + lookup3;
+ }
+ }
+ }
+ return wc;
+}
diff --git a/wctype/wctrans.c b/wctype/wctrans.c
index 771fb842ef..3dd72231cd 100644
--- a/wctype/wctrans.c
+++ b/wctype/wctrans.c
@@ -32,7 +32,6 @@ wctrans (const char *property)
{
const char *names;
size_t cnt;
- int32_t *result;
names = _NL_CURRENT (LC_CTYPE, _NL_CTYPE_MAP_NAMES);
cnt = 0;
@@ -48,13 +47,21 @@ wctrans (const char *property)
if (names[0] == '\0')
return 0;
- if (cnt == 0)
- return (wctrans_t) __ctype32_toupper;
- else if (cnt == 1)
- return (wctrans_t) __ctype32_tolower;
-
- /* We have to search the table. */
- result = (int32_t *) _NL_CURRENT (LC_CTYPE, _NL_NUM_LC_CTYPE + cnt - 2);
+ if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_HASH_SIZE) != 0)
+ {
+ /* Old locale format. */
+ if (cnt == 0)
+ return (wctrans_t) __ctype32_toupper;
+ else if (cnt == 1)
+ return (wctrans_t) __ctype32_tolower;
- return (wctrans_t) result;
+ /* We have to search the table. */
+ return (wctrans_t) (const int32_t *) _NL_CURRENT (LC_CTYPE, _NL_NUM_LC_CTYPE + cnt - 2);
+ }
+ else
+ {
+ /* New locale format. */
+ size_t i = _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MAP_OFFSET) + cnt;
+ return (wctrans_t) _nl_current_LC_CTYPE->values[i].string;
+ }
}
diff --git a/wctype/wctype.c b/wctype/wctype.c
index 6f6338c2e2..476707cfd2 100644
--- a/wctype/wctype.c
+++ b/wctype/wctype.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
@@ -26,11 +26,11 @@ wctype_t
__wctype (const char *property)
{
const char *names;
- wctype_t result;
+ unsigned int result;
size_t proplen = strlen (property);
names = _NL_CURRENT (LC_CTYPE, _NL_CTYPE_CLASS_NAMES);
- for (result = 1; result != 0; result <<= 1)
+ for (result = 0; ; result++)
{
size_t nameslen = strlen (names);
@@ -42,13 +42,22 @@ __wctype (const char *property)
return 0;
}
+ if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_HASH_SIZE) != 0)
+ {
+ /* Old locale format. */
#if __BYTE_ORDER == __BIG_ENDIAN
- return result;
+ return 1 << result;
#else
# define SWAPU32(w) \
(((w) << 24) | (((w) & 0xff00) << 8) | (((w) >> 8) & 0xff00) | ((w) >> 24))
-
- return SWAPU32 (result);
+ return 1 << (result ^ 0x18); /* = SWAPU32 (1 << result); */
#endif
+ }
+ else
+ {
+ /* New locale format. */
+ size_t i = _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_CLASS_OFFSET) + result;
+ return (wctype_t) _nl_current_LC_CTYPE->values[i].string;
+ }
}
weak_alias (__wctype, wctype)
diff --git a/wctype/wctype.h b/wctype/wctype.h
index 2812bd8286..ef986c257c 100644
--- a/wctype/wctype.h
+++ b/wctype/wctype.h
@@ -78,18 +78,31 @@ typedef unsigned long int wctype_t;
enum
{
- _ISwupper = _ISwbit (0), /* UPPERCASE. */
- _ISwlower = _ISwbit (1), /* lowercase. */
- _ISwalpha = _ISwbit (2), /* Alphabetic. */
- _ISwdigit = _ISwbit (3), /* Numeric. */
- _ISwxdigit = _ISwbit (4), /* Hexadecimal numeric. */
- _ISwspace = _ISwbit (5), /* Whitespace. */
- _ISwprint = _ISwbit (6), /* Printing. */
- _ISwgraph = _ISwbit (7), /* Graphical. */
- _ISwblank = _ISwbit (8), /* Blank (usually SPC and TAB). */
- _ISwcntrl = _ISwbit (9), /* Control character. */
- _ISwpunct = _ISwbit (10), /* Punctuation. */
- _ISwalnum = _ISwbit (11) /* Alphanumeric. */
+ __ISwupper = 0, /* UPPERCASE. */
+ __ISwlower = 1, /* lowercase. */
+ __ISwalpha = 2, /* Alphabetic. */
+ __ISwdigit = 3, /* Numeric. */
+ __ISwxdigit = 4, /* Hexadecimal numeric. */
+ __ISwspace = 5, /* Whitespace. */
+ __ISwprint = 6, /* Printing. */
+ __ISwgraph = 7, /* Graphical. */
+ __ISwblank = 8, /* Blank (usually SPC and TAB). */
+ __ISwcntrl = 9, /* Control character. */
+ __ISwpunct = 10, /* Punctuation. */
+ __ISwalnum = 11, /* Alphanumeric. */
+
+ _ISwupper = _ISwbit (__ISwupper), /* UPPERCASE. */
+ _ISwlower = _ISwbit (__ISwlower), /* lowercase. */
+ _ISwalpha = _ISwbit (__ISwalpha), /* Alphabetic. */
+ _ISwdigit = _ISwbit (__ISwdigit), /* Numeric. */
+ _ISwxdigit = _ISwbit (__ISwxdigit), /* Hexadecimal numeric. */
+ _ISwspace = _ISwbit (__ISwspace), /* Whitespace. */
+ _ISwprint = _ISwbit (__ISwprint), /* Printing. */
+ _ISwgraph = _ISwbit (__ISwgraph), /* Graphical. */
+ _ISwblank = _ISwbit (__ISwblank), /* Blank (usually SPC and TAB). */
+ _ISwcntrl = _ISwbit (__ISwcntrl), /* Control character. */
+ _ISwpunct = _ISwbit (__ISwpunct), /* Punctuation. */
+ _ISwalnum = _ISwbit (__ISwalnum) /* Alphanumeric. */
};
# endif /* Not _ISwbit */
@@ -227,11 +240,6 @@ extern unsigned int *__ctype32_b;
? (int) (__ctype32_b[(wint_t) (wc)] & _ISwblank) : iswblank (wc)))
# endif
-# define iswctype(wc, desc) \
- (__extension__ \
- (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
- ? (int) (__ctype32_b[(wint_t) (wc)] & desc) : iswctype (wc, desc)))
-
#endif /* gcc && optimizing */
/*
diff --git a/wctype/wctype_l.c b/wctype/wctype_l.c
index 0a19504503..fdbd1ff451 100644
--- a/wctype/wctype_l.c
+++ b/wctype/wctype_l.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
@@ -26,11 +26,11 @@ wctype_t
__wctype_l (const char *property, __locale_t locale)
{
const char *names;
- wctype_t result;
+ unsigned int result;
size_t proplen = strlen (property);
names = locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_CLASS_NAMES)].string;
- for (result = 1; result != 0; result <<= 1)
+ for (result = 0; ; result++)
{
size_t nameslen = strlen (names);
@@ -42,12 +42,21 @@ __wctype_l (const char *property, __locale_t locale)
return 0;
}
+ if (locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_HASH_SIZE)].word == 0)
+ {
+ /* Old locale format. */
#if __BYTE_ORDER == __BIG_ENDIAN
- return result;
+ return 1 << result;
#else
# define SWAPU32(w) \
(((w) << 24) | (((w) & 0xff00) << 8) | (((w) >> 8) & 0xff00) | ((w) >> 24))
-
- return SWAPU32 (result);
+ return 1 << (result ^ 0x18); /* = SWAPU32 (1 << result); */
#endif
+ }
+ else
+ {
+ /* New locale format. */
+ size_t i = locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_CLASS_OFFSET)].word + result;
+ return (wctype_t) locale->__locales[LC_CTYPE]->values[i].string;
+ }
}