Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add wcwidth_l, wcswidth_l and the wctype.h family of *_l fun...



details:   https://anonhg.NetBSD.org/src/rev/d25472614a1a
branches:  trunk
changeset: 786122:d25472614a1a
user:      joerg <joerg%NetBSD.org@localhost>
date:      Tue Apr 16 11:39:13 2013 +0000

description:
Add wcwidth_l, wcswidth_l and the wctype.h family of *_l functions.

diffstat:

 include/wctype.h              |   27 ++++++++++-
 lib/libc/include/namespace.h  |    3 +-
 lib/libc/locale/iswctype_mb.c |  108 +++++++++++++++++++++++++++++++++++-------
 3 files changed, 118 insertions(+), 20 deletions(-)

diffs (284 lines):

diff -r 9e0c4fe48058 -r d25472614a1a include/wctype.h
--- a/include/wctype.h  Tue Apr 16 11:29:12 2013 +0000
+++ b/include/wctype.h  Tue Apr 16 11:39:13 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: wctype.h,v 1.7 2010/03/27 22:14:09 tnozaki Exp $       */
+/*     $NetBSD: wctype.h,v 1.8 2013/04/16 11:39:13 joerg Exp $ */
 
 /*-
  * Copyright (c)1999 Citrus Project,
@@ -72,6 +72,31 @@
 wint_t towupper(wint_t);
 wctrans_t wctrans(const char *);
 wctype_t wctype(const char *);
+
+#if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE)
+#  ifndef __LOCALE_T_DECLARED
+typedef struct _locale         *locale_t;
+#  define __LOCALE_T_DECLARED
+#  endif
+int    iswalnum_l(wint_t, locale_t);
+int    iswalpha_l(wint_t, locale_t);
+int    iswblank_l(wint_t, locale_t);
+int    iswcntrl_l(wint_t, locale_t);
+int    iswdigit_l(wint_t, locale_t);
+int    iswgraph_l(wint_t, locale_t);
+int    iswlower_l(wint_t, locale_t);
+int    iswprint_l(wint_t, locale_t);
+int    iswpunct_l(wint_t, locale_t);
+int    iswspace_l(wint_t, locale_t);
+int    iswupper_l(wint_t, locale_t);
+int    iswxdigit_l(wint_t, locale_t);
+int    iswctype_l(wint_t, wctype_t, locale_t);
+wint_t towctrans_l(wint_t, wctrans_t, locale_t);
+wint_t towlower_l(wint_t, locale_t);
+wint_t towupper_l(wint_t, locale_t);
+wctrans_t wctrans_l(const char *, locale_t);
+wctype_t wctype_l(const char *, locale_t);
+#endif
 __END_DECLS
 
 #endif         /* _WCTYPE_H_ */
diff -r 9e0c4fe48058 -r d25472614a1a lib/libc/include/namespace.h
--- a/lib/libc/include/namespace.h      Tue Apr 16 11:29:12 2013 +0000
+++ b/lib/libc/include/namespace.h      Tue Apr 16 11:39:13 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: namespace.h,v 1.156 2012/08/20 21:38:10 dsl Exp $      */
+/*     $NetBSD: namespace.h,v 1.157 2013/04/16 11:39:13 joerg Exp $    */
 
 /*-
  * Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
@@ -703,6 +703,7 @@
 #define wcstod                 _wcstod
 #define wcstold                        _wcstold
 #define wcwidth                        _wcwidth
+#define wcwidth_l              _wcwidth_l
 #define xdr_accepted_reply     _xdr_accepted_reply
 #define xdr_array              _xdr_array
 #define xdr_authunix_parms     _xdr_authunix_parms
diff -r 9e0c4fe48058 -r d25472614a1a lib/libc/locale/iswctype_mb.c
--- a/lib/libc/locale/iswctype_mb.c     Tue Apr 16 11:29:12 2013 +0000
+++ b/lib/libc/locale/iswctype_mb.c     Tue Apr 16 11:39:13 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: iswctype_mb.c,v 1.11 2010/06/13 04:14:57 tnozaki Exp $ */
+/* $NetBSD: iswctype_mb.c,v 1.12 2013/04/16 11:39:13 joerg Exp $ */
 
 /*-
  * Copyright (c)2008 Citrus Project,
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: iswctype_mb.c,v 1.11 2010/06/13 04:14:57 tnozaki Exp $");
+__RCSID("$NetBSD: iswctype_mb.c,v 1.12 2013/04/16 11:39:13 joerg Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -47,20 +47,29 @@
 #include "_wctype_local.h"
 #include "_wctrans_local.h"
 
-#define _RUNE_LOCALE() ((_RuneLocale const *) \
-    (*_current_locale())->part_impl[(size_t)LC_CTYPE])
+#define _RUNE_LOCALE(loc) ((_RuneLocale const *) \
+    (loc)->part_impl[(size_t)LC_CTYPE])
 
 #define _ISWCTYPE_FUNC(name, index)                    \
 int                                                    \
-isw##name(wint_t wc)                                   \
+isw##name##_l(wint_t wc, locale_t loc)                 \
 {                                                      \
        _RuneLocale const *rl;                          \
        _WCTypeEntry const *te;                         \
                                                        \
-       rl = _RUNE_LOCALE();                            \
+       if (loc == NULL)                                \
+               loc = _C_locale;                        \
+                                                       \
+       rl = _RUNE_LOCALE(loc);                         \
        te = &rl->rl_wctype[index];                     \
        return _iswctype_priv(rl, wc, te);              \
+}                                                      \
+int                                                    \
+isw##name(wint_t wc)                                   \
+{                                                      \
+       return isw##name##_l(wc, *_current_locale());   \
 }
+
 _ISWCTYPE_FUNC(alnum,  _WCTYPE_INDEX_ALNUM)
 _ISWCTYPE_FUNC(alpha,  _WCTYPE_INDEX_ALPHA)
 _ISWCTYPE_FUNC(blank,  _WCTYPE_INDEX_BLANK)
@@ -76,25 +85,36 @@
 
 #define _TOWCTRANS_FUNC(name, index)                   \
 wint_t                                                 \
-tow##name(wint_t wc)                                   \
+tow##name##_l(wint_t wc, locale_t loc)                 \
 {                                                      \
        _RuneLocale const *rl;                          \
        _WCTransEntry const *te;                        \
                                                        \
-       rl = _RUNE_LOCALE();                            \
+       if (loc == NULL)                                \
+               loc = _C_locale;                        \
+                                                       \
+       rl = _RUNE_LOCALE(loc);                         \
        te = &rl->rl_wctrans[index];                    \
        return _towctrans_priv(wc, te);                 \
+}                                                      \
+wint_t                                                 \
+tow##name(wint_t wc)                                   \
+{                                                      \
+       return tow##name##_l(wc, *_current_locale());   \
 }
 _TOWCTRANS_FUNC(upper, _WCTRANS_INDEX_UPPER)
 _TOWCTRANS_FUNC(lower, _WCTRANS_INDEX_LOWER)
 
 wctype_t
-wctype(const char *charclass)
+wctype_l(const char *charclass, locale_t loc)
 {
        _RuneLocale const *rl;
        size_t i;
 
-       rl = _RUNE_LOCALE();
+       if (loc == NULL)
+               loc = _C_locale;
+
+       rl = _RUNE_LOCALE(loc);
        for (i = 0; i < _WCTYPE_NINDEXES; ++i) {
                if (!strcmp(rl->rl_wctype[i].te_name, charclass))
                        return (wctype_t)__UNCONST(&rl->rl_wctype[i]);
@@ -102,13 +122,22 @@
        return (wctype_t)NULL;
 }
 
+wctype_t
+wctype(const char *charclass)
+{
+       return wctype_l(charclass, *_current_locale());
+}
+
 wctrans_t
-wctrans(const char *charmap)
+wctrans_l(const char *charmap, locale_t loc)
 {
        _RuneLocale const *rl;
        size_t i;
 
-       rl = _RUNE_LOCALE();
+       if (loc == NULL)
+               loc = _C_locale;
+
+       rl = _RUNE_LOCALE(loc);
        for (i = 0; i < _WCTRANS_NINDEXES; ++i) {
                _DIAGASSERT(rl->rl_wctrans[i].te_name != NULL);
                if (!strcmp(rl->rl_wctrans[i].te_name, charmap))
@@ -117,8 +146,14 @@
        return (wctrans_t)NULL;
 }
 
+wctrans_t
+wctrans(const char *charmap)
+{
+       return wctrans_l(charmap, *_current_locale());
+}
+
 int
-iswctype(wint_t wc, wctype_t charclass)
+iswctype_l(wint_t wc, wctype_t charclass, locale_t loc)
 {
        _RuneLocale const *rl;
        _WCTypeEntry const *te;
@@ -127,11 +162,21 @@
                errno = EINVAL;
                return 0;
        }
-       rl = _RUNE_LOCALE();
+
+       if (loc == NULL)
+               loc = _C_locale;
+
+       rl = _RUNE_LOCALE(loc);
        te = (_WCTypeEntry const *)(void *)charclass;
        return _iswctype_priv(rl, wc, te);
 }
 
+int
+iswctype(wint_t wc, wctype_t charclass)
+{
+       return iswctype_l(wc, charclass, *_current_locale());
+}
+
 wint_t
 towctrans(wint_t wc, wctrans_t charmap)
 {
@@ -145,17 +190,29 @@
        return _towctrans_priv(wc, te);
 }
 
+/* ARGSUSED */
+wint_t
+towctrans_l(wint_t wc, wctrans_t charmap, locale_t loc)
+{
+       return towctrans(wc, charmap);
+}
+
 __weak_alias(wcwidth,_wcwidth)
+__weak_alias(wcwidth_l,_wcwidth_l)
 
 int
-wcwidth(wchar_t wc)
+wcwidth_l(wchar_t wc, locale_t loc)
 {
        _RuneLocale const *rl;
        _RuneType x;
 
        if (wc == L'\0')
                return 0;
-       rl = _RUNE_LOCALE();
+
+       if (loc == NULL)
+               loc = _C_locale;
+
+       rl = _RUNE_LOCALE(loc);
        x = _runetype_priv(rl, wc);
        if (x & _RUNETYPE_R)
                return ((unsigned)x & _RUNETYPE_SWM) >> _RUNETYPE_SWS;
@@ -163,7 +220,13 @@
 }
 
 int
-wcswidth(const wchar_t * __restrict ws, size_t wn)
+wcwidth(wchar_t wc)
+{
+       return wcwidth_l(wc, *_current_locale());
+}
+
+int
+wcswidth_l(const wchar_t * __restrict ws, size_t wn, locale_t loc)
 {
        _RuneLocale const *rl;
        _RuneType x;
@@ -171,7 +234,10 @@
 
        _DIAGASSERT(ws != NULL);
 
-       rl = _RUNE_LOCALE();
+       if (loc == NULL)
+               loc = _C_locale;
+
+       rl = _RUNE_LOCALE(loc);
        width = 0;
        while (wn > 0 && *ws != L'\0') {
                x = _runetype_priv(rl, *ws);
@@ -182,3 +248,9 @@
        }
        return width;
 }
+
+int
+wcswidth(const wchar_t * __restrict ws, size_t wn)
+{
+       return wcswidth_l(ws, wn, *_current_locale());
+}



Home | Main Index | Thread Index | Old Index