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/cstdint.hpp>
19 #include <boost/spirit/home/support/assert_msg.hpp>
21 namespace boost { namespace spirit { namespace traits
23 template <std::size_t N>
26 BOOST_SPIRIT_ASSERT_MSG(N == 1 || N == 2 || N == 4,
27 not_supported_size_of_wchar_t, ());
30 template <> struct wchar_t_size<1> { enum { mask = 0xff }; };
31 template <> struct wchar_t_size<2> { enum { mask = 0xffff }; };
32 template <> struct wchar_t_size<4> { enum { mask = 0xffffffff }; };
36 namespace boost { namespace spirit { namespace char_encoding
38 ///////////////////////////////////////////////////////////////////////////
39 // Test characters for specified conditions (using std wchar_t functions)
40 ///////////////////////////////////////////////////////////////////////////
44 typedef wchar_t char_type;
46 template <typename Char>
47 static typename std::char_traits<Char>::int_type
50 return std::char_traits<Char>::to_int_type(ch);
53 template <typename Char>
55 to_char_type(typename std::char_traits<Char>::int_type ch)
57 return std::char_traits<Char>::to_char_type(ch);
63 // we have to watch out for sign extensions (casting is there to
64 // silence certain compilers complaining about signed/unsigned
68 std::size_t(ch & ~traits::wchar_t_size<sizeof(wchar_t)>::mask) ||
70 std::size_t(ch | traits::wchar_t_size<sizeof(wchar_t)>::mask)
71 ) ? true : false; // any wchar_t, but no other bits set
78 return iswalnum(to_int_type(ch)) ? true : false;
85 return iswalpha(to_int_type(ch)) ? true : false;
92 return iswcntrl(to_int_type(ch)) ? true : false;
99 return iswdigit(to_int_type(ch)) ? true : false;
106 return iswgraph(to_int_type(ch)) ? true : false;
113 return iswlower(to_int_type(ch)) ? true : false;
120 return iswprint(to_int_type(ch)) ? true : false;
127 return iswpunct(to_int_type(ch)) ? true : false;
134 return iswspace(to_int_type(ch)) ? true : false;
141 return iswupper(to_int_type(ch)) ? true : false;
148 return iswxdigit(to_int_type(ch)) ? true : false;
152 isblank BOOST_PREVENT_MACRO_SUBSTITUTION (wchar_t ch)
154 return (ch == L' ' || ch == L'\t');
157 ///////////////////////////////////////////////////////////////////////
158 // Simple character conversions
159 ///////////////////////////////////////////////////////////////////////
166 to_char_type<wchar_t>(towlower(to_int_type(ch))) : ch;
174 to_char_type<wchar_t>(towupper(to_int_type(ch))) : ch;
177 static ::boost::uint32_t