]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/spirit/home/support/char_encoding/standard.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / spirit / home / support / char_encoding / standard.hpp
index fb307ced45a3e86f85bd9aa56f44ad20624cf387..704b001461221836361f71c94a2ee6d221bd81aa 100644 (file)
@@ -13,6 +13,7 @@
 #endif
 
 #include <cctype>
+#include <boost/assert.hpp>
 #include <boost/cstdint.hpp>
 
 namespace boost { namespace spirit { namespace char_encoding
@@ -23,6 +24,7 @@ namespace boost { namespace spirit { namespace char_encoding
     struct standard
     {
         typedef char char_type;
+        typedef unsigned char classify_type;
 
         static bool
         isascii_(int ch)
@@ -35,79 +37,104 @@ namespace boost { namespace spirit { namespace char_encoding
         {
             // uses all 8 bits
             // we have to watch out for sign extensions
-            return (0 == (ch & ~0xff) || ~0 == (ch | 0xff)) ? true : false;
+            return (0 == (ch & ~0xff) || ~0 == (ch | 0xff)) != 0;
+        }
+
+        // *** Note on assertions: The precondition is that the calls to
+        // these functions do not violate the required range of ch (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 an unsigned char
+            return ch >= 0 && ch <= UCHAR_MAX;
         }
 
         static bool
         isalnum(int ch)
         {
-            return std::isalnum(ch) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return std::isalnum(ch) != 0;
         }
 
         static bool
         isalpha(int ch)
         {
-            return std::isalpha(ch) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return std::isalpha(ch) != 0;
         }
 
         static bool
         isdigit(int ch)
         {
-            return std::isdigit(ch) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return std::isdigit(ch) != 0;
         }
 
         static bool
         isxdigit(int ch)
         {
-            return std::isxdigit(ch) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return std::isxdigit(ch) != 0;
         }
 
         static bool
         iscntrl(int ch)
         {
-            return std::iscntrl(ch) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return std::iscntrl(ch) != 0;
         }
 
         static bool
         isgraph(int ch)
         {
-            return std::isgraph(ch) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return std::isgraph(ch) != 0;
         }
 
         static bool
         islower(int ch)
         {
-            return std::islower(ch) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return std::islower(ch) != 0;
         }
 
         static bool
         isprint(int ch)
         {
-            return std::isprint(ch) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return std::isprint(ch) != 0;
         }
 
         static bool
         ispunct(int ch)
         {
-            return std::ispunct(ch) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return std::ispunct(ch) != 0;
         }
 
         static bool
         isspace(int ch)
         {
-            return std::isspace(ch) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return std::isspace(ch) != 0;
         }
 
         static bool
         isblank BOOST_PREVENT_MACRO_SUBSTITUTION (int ch)
         {
+            BOOST_ASSERT(strict_ischar(ch));
             return (ch == ' ' || ch == '\t');
         }
 
         static bool
         isupper(int ch)
         {
-            return std::isupper(ch) ? true : false;
+            BOOST_ASSERT(strict_ischar(ch));
+            return std::isupper(ch) != 0;
         }
 
     ///////////////////////////////////////////////////////////////////////////////
@@ -117,22 +144,24 @@ namespace boost { namespace spirit { namespace char_encoding
         static int
         tolower(int ch)
         {
+            BOOST_ASSERT(strict_ischar(ch));
             return std::tolower(ch);
         }
 
         static int
         toupper(int ch)
         {
+            BOOST_ASSERT(strict_ischar(ch));
             return std::toupper(ch);
         }
 
         static ::boost::uint32_t
         toucs4(int ch)
         {
+            BOOST_ASSERT(strict_ischar(ch));
             return ch;
         }
     };
 }}}
 
 #endif
-