]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/spirit/home/support/char_encoding/standard_wide.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / spirit / home / support / char_encoding / standard_wide.hpp
index 515a388136db770f6eb17cf31cfb12d2500186b7..c2d378112064071dfa1409cf1f8ce4d1cadd5f48 100644 (file)
@@ -15,6 +15,7 @@
 #include <cwctype>
 #include <string>
 
+#include <boost/assert.hpp>
 #include <boost/cstdint.hpp>
 #include <boost/spirit/home/support/assert_msg.hpp>
 
@@ -42,6 +43,7 @@ namespace boost { namespace spirit { namespace char_encoding
     struct standard_wide
     {
         typedef wchar_t char_type;
+        typedef wchar_t classify_type;
 
         template <typename Char>
         static typename std::char_traits<Char>::int_type
@@ -60,97 +62,121 @@ namespace boost { namespace spirit { namespace char_encoding
         static bool
         ischar(int ch)
         {
-            // we have to watch out for sign extensions (casting is there to 
+            // we have to watch out for sign extensions (casting is there to
             // silence certain compilers complaining about signed/unsigned
             // mismatch)
             return (
-                std::size_t(0) == 
-                    std::size_t(ch & ~traits::wchar_t_size<sizeof(wchar_t)>::mask) || 
-                std::size_t(~0) == 
+                std::size_t(0) ==
+                    std::size_t(ch & ~traits::wchar_t_size<sizeof(wchar_t)>::mask) ||
+                std::size_t(~0) ==
                     std::size_t(ch | traits::wchar_t_size<sizeof(wchar_t)>::mask)
-            ) ? true : false;     // any wchar_t, but no other bits set
+            ) != 0;     // any wchar_t, but no other bits set
+        }
+
+        // *** Note on assertions: The precondition is that the calls to
+        // these functions do not violate the required range of ch (type int)
+        // which is that strict_ischar(ch) should be true. It is the
+        // responsibility of the caller to make sure this precondition is not
+        // violated.
+
+        static bool
+        strict_ischar(int ch)
+        {
+            // ch should be representable as a wchar_t
+            return ch >= WCHAR_MIN && ch <= WCHAR_MAX;
         }
 
         static bool
         isalnum(wchar_t ch)
         {
             using namespace std;
-            return iswalnum(to_int_type(ch)) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return iswalnum(to_int_type(ch)) != 0;
         }
 
         static bool
         isalpha(wchar_t ch)
         {
             using namespace std;
-            return iswalpha(to_int_type(ch)) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return iswalpha(to_int_type(ch)) != 0;
         }
 
         static bool
         iscntrl(wchar_t ch)
         {
             using namespace std;
-            return iswcntrl(to_int_type(ch)) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return iswcntrl(to_int_type(ch)) != 0;
         }
 
         static bool
         isdigit(wchar_t ch)
         {
             using namespace std;
-            return iswdigit(to_int_type(ch)) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return iswdigit(to_int_type(ch)) != 0;
         }
 
         static bool
         isgraph(wchar_t ch)
         {
             using namespace std;
-            return iswgraph(to_int_type(ch)) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return iswgraph(to_int_type(ch)) != 0;
         }
 
         static bool
         islower(wchar_t ch)
         {
             using namespace std;
-            return iswlower(to_int_type(ch)) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return iswlower(to_int_type(ch)) != 0;
         }
 
         static bool
         isprint(wchar_t ch)
         {
             using namespace std;
-            return iswprint(to_int_type(ch)) ? true : false;
+            return iswprint(to_int_type(ch)) != 0;
         }
 
         static bool
         ispunct(wchar_t ch)
         {
             using namespace std;
-            return iswpunct(to_int_type(ch)) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return iswpunct(to_int_type(ch)) != 0;
         }
 
         static bool
         isspace(wchar_t ch)
         {
             using namespace std;
-            return iswspace(to_int_type(ch)) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return iswspace(to_int_type(ch)) != 0;
         }
 
         static bool
         isupper(wchar_t ch)
         {
             using namespace std;
-            return iswupper(to_int_type(ch)) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return iswupper(to_int_type(ch)) != 0;
         }
 
         static bool
         isxdigit(wchar_t ch)
         {
             using namespace std;
-            return iswxdigit(to_int_type(ch)) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return iswxdigit(to_int_type(ch)) != 0;
         }
 
         static bool
         isblank BOOST_PREVENT_MACRO_SUBSTITUTION (wchar_t ch)
         {
+            BOOST_ASSERT(strict_ischar(ch));
             return (ch == L' ' || ch == L'\t');
         }
 
@@ -162,6 +188,7 @@ namespace boost { namespace spirit { namespace char_encoding
         tolower(wchar_t ch)
         {
             using namespace std;
+            BOOST_ASSERT(strict_ischar(ch));
             return isupper(ch) ?
                 to_char_type<wchar_t>(towlower(to_int_type(ch))) : ch;
         }
@@ -170,6 +197,7 @@ namespace boost { namespace spirit { namespace char_encoding
         toupper(wchar_t ch)
         {
             using namespace std;
+            BOOST_ASSERT(strict_ischar(ch));
             return islower(ch) ?
                 to_char_type<wchar_t>(towupper(to_int_type(ch))) : ch;
         }
@@ -177,10 +205,10 @@ namespace boost { namespace spirit { namespace char_encoding
         static ::boost::uint32_t
         toucs4(int ch)
         {
+            BOOST_ASSERT(strict_ischar(ch));
             return ch;
         }
     };
 }}}
 
 #endif
-