1 /*=============================================================================
2 Copyright (c) 2001-2011 Hartmut Kaiser
3 Copyright (c) 2001-2011 Joel de Guzman
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 #if !defined(BOOST_SPIRIT_STANDARD_WIDE_NOVEMBER_10_2006_0913AM)
9 #define BOOST_SPIRIT_STANDARD_WIDE_NOVEMBER_10_2006_0913AM
18 #include <boost/assert.hpp>
19 #include <boost/cstdint.hpp>
20 #include <boost/spirit/home/support/assert_msg.hpp>
22 namespace boost { namespace spirit { namespace traits
24 template <std::size_t N>
27 BOOST_SPIRIT_ASSERT_MSG(N == 1 || N == 2 || N == 4,
28 not_supported_size_of_wchar_t, ());
31 template <> struct wchar_t_size<1> { enum { mask = 0xff }; };
32 template <> struct wchar_t_size<2> { enum { mask = 0xffff }; };
33 template <> struct wchar_t_size<4> { enum { mask = 0xffffffff }; };
37 namespace boost { namespace spirit { namespace char_encoding
39 ///////////////////////////////////////////////////////////////////////////
40 // Test characters for specified conditions (using std wchar_t functions)
41 ///////////////////////////////////////////////////////////////////////////
45 typedef wchar_t char_type;
46 typedef wchar_t classify_type;
48 template <typename Char>
49 static typename std::char_traits<Char>::int_type
52 return std::char_traits<Char>::to_int_type(ch);
55 template <typename Char>
57 to_char_type(typename std::char_traits<Char>::int_type ch)
59 return std::char_traits<Char>::to_char_type(ch);
65 // we have to watch out for sign extensions (casting is there to
66 // silence certain compilers complaining about signed/unsigned
70 std::size_t(ch & ~traits::wchar_t_size<sizeof(wchar_t)>::mask) ||
72 std::size_t(ch | traits::wchar_t_size<sizeof(wchar_t)>::mask)
73 ) != 0; // any wchar_t, but no other bits set
76 // *** Note on assertions: The precondition is that the calls to
77 // these functions do not violate the required range of ch (type int)
78 // which is that strict_ischar(ch) should be true. It is the
79 // responsibility of the caller to make sure this precondition is not
85 // ch should be representable as a wchar_t
86 return ch >= WCHAR_MIN && ch <= WCHAR_MAX;
93 BOOST_ASSERT(strict_ischar(ch));
94 return iswalnum(to_int_type(ch)) != 0;
101 BOOST_ASSERT(strict_ischar(ch));
102 return iswalpha(to_int_type(ch)) != 0;
109 BOOST_ASSERT(strict_ischar(ch));
110 return iswcntrl(to_int_type(ch)) != 0;
117 BOOST_ASSERT(strict_ischar(ch));
118 return iswdigit(to_int_type(ch)) != 0;
125 BOOST_ASSERT(strict_ischar(ch));
126 return iswgraph(to_int_type(ch)) != 0;
133 BOOST_ASSERT(strict_ischar(ch));
134 return iswlower(to_int_type(ch)) != 0;
141 return iswprint(to_int_type(ch)) != 0;
148 BOOST_ASSERT(strict_ischar(ch));
149 return iswpunct(to_int_type(ch)) != 0;
156 BOOST_ASSERT(strict_ischar(ch));
157 return iswspace(to_int_type(ch)) != 0;
164 BOOST_ASSERT(strict_ischar(ch));
165 return iswupper(to_int_type(ch)) != 0;
172 BOOST_ASSERT(strict_ischar(ch));
173 return iswxdigit(to_int_type(ch)) != 0;
177 isblank BOOST_PREVENT_MACRO_SUBSTITUTION (wchar_t ch)
179 BOOST_ASSERT(strict_ischar(ch));
180 return (ch == L' ' || ch == L'\t');
183 ///////////////////////////////////////////////////////////////////////
184 // Simple character conversions
185 ///////////////////////////////////////////////////////////////////////
191 BOOST_ASSERT(strict_ischar(ch));
193 to_char_type<wchar_t>(towlower(to_int_type(ch))) : ch;
200 BOOST_ASSERT(strict_ischar(ch));
202 to_char_type<wchar_t>(towupper(to_int_type(ch))) : ch;
205 static ::boost::uint32_t
208 BOOST_ASSERT(strict_ischar(ch));