stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Farid Zaripov" <Farid_Zari...@epam.com>
Subject [PATCH] ctype<wchar_t> fixes
Date Thu, 04 Oct 2007 17:43:20 GMT
  The following patch fixes the rw_asserts in 22.locale.ctype.narrow.cpp
test.

  ChangeLog:
  * _ctype.h (ctype<wchar_t>::narrow): Don't cast __c to unsigned char
  to avoid using the same __idx for the different __c (i.e. 2 and 258).
  * wctype.cpp (ctype_byname<wchar_t>::do_narrow): Compare tmp with
  _RWSTD_EOF instead of < 0. Set locale before invoking wctomb().
  (ctype_byname<wchar_t>::do_widen): Use mbtowc() if it's available and
  if btowc() is not available.

---------------------
Index: include/loc/_ctype.h
===================================================================
--- include/loc/_ctype.h	(revision 581916)
+++ include/loc/_ctype.h	(working copy)
@@ -541,7 +541,7 @@
 inline char
 ctype<wchar_t>::narrow (char_type __c, char __dfault) const
 {
-    const _RWSTD_SIZE_T __inx = _RWSTD_STATIC_CAST (unsigned char,
__c);
+    const _RWSTD_SIZE_T __inx = __c;
 
     // optimize away all but the first call to the virtual do_widen()
     if (   __inx < sizeof _C_narrow_tab / sizeof *_C_narrow_tab
Index: src/wctype.cpp
===================================================================
--- src/wctype.cpp	(revision 581916)
+++ src/wctype.cpp	(working copy)
@@ -881,11 +881,12 @@
         const _RW::__rw_setlocale clocale (_C_name, LC_CTYPE);
 
         const int tmp = wctob (c);
+        ch = _RWSTD_EOF == tmp ? dfault : char (tmp);
 
-        ch = tmp < 0 ? dfault : char (tmp);
-
 #elif !defined (_RWSTD_NO_WCTOMB)
 
+        const _RW::__rw_setlocale clocale (_C_name, LC_CTYPE);
+
         char tmp [_RWSTD_MB_LEN_MAX];
         ch = 1 == wctomb (tmp, c) ? *tmp : dfault;
 
@@ -1005,8 +1006,15 @@
         // prevent sign extension if `c' is negative
         ch = btowc (u_c);
 
-#else   // if defined (_RWSTD_NO_BTOWC)
+#elif !defined (_RWSTD_NO_MBTOWC)
 
+        const _RW::__rw_setlocale clocale (_C_name, LC_CTYPE);
+
+        char_type tmp;
+        ch = 1 == mbtowc (&tmp, &c, 1) ? tmp : char_type (_RWSTD_WEOF);
+
+#else   // if defined (_RWSTD_NO_MBTOWC)
+
         ch = char_type (u_c);
 
 #endif   // _RWSTD_NO_BTOWC
---------------------

Farid.

Mime
View raw message