incubator-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] 22.locale.ctype.narrow.cpp
Date Thu, 04 Oct 2007 17:50:28 GMT
  ChangeLog:
  * 22.locale.ctype.narrow.cpp: Move libc_mask (, wchar_t, )
  and libc_is (, wchar_t, ) functions up before the first use
  in cond1 (, char, ).
  Remove #ifndef _RWSTD_NO_WCHAR_T / #endif preprocessor
  directives as unusual.
  (narrow): Check the return value of the wctob().

------------
Index: tests/localization/22.locale.ctype.narrow.cpp
===================================================================
--- tests/localization/22.locale.ctype.narrow.cpp	(revision
581916)
+++ tests/localization/22.locale.ctype.narrow.cpp	(working copy)
@@ -165,6 +165,53 @@
     return 0 != (m & mask);
 }
 
+std::ctype_base::mask libc_mask (int mask, wchar_t ch, const char
*locname)
+{
+    char curlocname [256];
+
+    if (locname) {
+        std::strcpy (curlocname, std::setlocale (LC_CTYPE, 0));
+
+        if (0 == std::setlocale (LC_CTYPE, locname))
+            return std::ctype_base::mask ();
+    }
+
+    int result = 0;
+
+    if (mask & ALPHA && (std::iswalpha)(ch))
+        result |= ALPHA;
+    if (mask & CNTRL && (std::iswcntrl)(ch))
+        result |= CNTRL;
+    if (mask & DIGIT && (std::iswdigit)(ch))
+        result |= DIGIT;
+    if (mask & GRAPH && (std::iswgraph)(ch))
+        result |= GRAPH;
+    if (mask & LOWER && (std::iswlower)(ch))
+        result |= LOWER;
+    if (mask & PRINT && (std::iswprint)(ch))
+        result |= PRINT;
+    if (mask & PUNCT && (std::iswpunct)(ch))
+        result |= PUNCT;
+    if (mask & SPACE && (std::iswspace)(ch))
+        result |= SPACE;
+    if (mask & UPPER && (std::iswupper)(ch))
+        result |= UPPER;
+    if (mask & XDIGIT && (std::iswxdigit)(ch))
+        result |= XDIGIT;
+
+    if (locname)
+        std::setlocale (LC_CTYPE, curlocname);
+
+    return std::ctype_base::mask (result);
+}
+
+bool libc_is (std::ctype_base::mask mask, wchar_t ch, const char
*locname)
+{
+    const std::ctype_base::mask m = libc_mask (mask, ch, locname);
+
+    return 0 != (m & mask);
+}
+
 const char* narrow (char *dst, const char *src)
 {
     if (src == dst || !src || !dst)
@@ -244,8 +291,6 @@
 }
 
 
-#ifndef _RWSTD_NO_WCHAR_T
-
 const char* narrow (char *dst, const wchar_t *src)
 {
     static char buf [4096];
@@ -291,53 +336,6 @@
     return dst;
 }
 
-std::ctype_base::mask libc_mask (int mask, wchar_t ch, const char
*locname)
-{
-    char curlocname [256];
-
-    if (locname) {
-        std::strcpy (curlocname, std::setlocale (LC_CTYPE, 0));
-
-        if (0 == std::setlocale (LC_CTYPE, locname))
-            return std::ctype_base::mask ();
-    }
-
-    int result = 0;
-
-    if (mask & ALPHA && (std::iswalpha)(ch))
-        result |= ALPHA;
-    if (mask & CNTRL && (std::iswcntrl)(ch))
-        result |= CNTRL;
-    if (mask & DIGIT && (std::iswdigit)(ch))
-        result |= DIGIT;
-    if (mask & GRAPH && (std::iswgraph)(ch))
-        result |= GRAPH;
-    if (mask & LOWER && (std::iswlower)(ch))
-        result |= LOWER;
-    if (mask & PRINT && (std::iswprint)(ch))
-        result |= PRINT;
-    if (mask & PUNCT && (std::iswpunct)(ch))
-        result |= PUNCT;
-    if (mask & SPACE && (std::iswspace)(ch))
-        result |= SPACE;
-    if (mask & UPPER && (std::iswupper)(ch))
-        result |= UPPER;
-    if (mask & XDIGIT && (std::iswxdigit)(ch))
-        result |= XDIGIT;
-
-    if (locname)
-        std::setlocale (LC_CTYPE, curlocname);
-
-    return std::ctype_base::mask (result);
-}
-
-bool libc_is (std::ctype_base::mask mask, wchar_t ch, const char
*locname)
-{
-    const std::ctype_base::mask m = libc_mask (mask, ch, locname);
-
-    return 0 != (m & mask);
-}
-
 wchar_t widen (wchar_t, char ch, const char *locname)
 {
     char curlocname [256];
@@ -381,7 +379,8 @@
 
 #ifndef _RWSTD_NO_WCTOB
 
-    result [0] = std::wctob (ch);
+    const int tmp = std::wctob (ch);
+    result [0] = EOF == tmp ? '\377' : char (tmp);
 
 #elif !defined (_RWSTD_NO_WCTOMB)
 
@@ -431,8 +430,6 @@
     return result;
 }
 
-#endif   // _RWSTD_NO_WCHAR_T
-
 
/***********************************************************************
***/
 
 template <class charT>
------------

Farid.

Mime
View raw message