summaryrefslogtreecommitdiffstats
blob: 515a388136db770f6eb17cf31cfb12d2500186b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*=============================================================================
    Copyright (c) 2001-2011 Hartmut Kaiser
    Copyright (c) 2001-2011 Joel de Guzman

    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#if !defined(BOOST_SPIRIT_STANDARD_WIDE_NOVEMBER_10_2006_0913AM)
#define BOOST_SPIRIT_STANDARD_WIDE_NOVEMBER_10_2006_0913AM

#if defined(_MSC_VER)
#pragma once
#endif

#include <cwctype>
#include <string>

#include <boost/cstdint.hpp>
#include <boost/spirit/home/support/assert_msg.hpp>

namespace boost { namespace spirit { namespace traits
{
    template <std::size_t N>
    struct wchar_t_size
    {
        BOOST_SPIRIT_ASSERT_MSG(N == 1 || N == 2 || N == 4,
            not_supported_size_of_wchar_t, ());
    };

    template <> struct wchar_t_size<1> { enum { mask = 0xff }; };
    template <> struct wchar_t_size<2> { enum { mask = 0xffff }; };
    template <> struct wchar_t_size<4> { enum { mask = 0xffffffff }; };

}}}

namespace boost { namespace spirit { namespace char_encoding
{
    ///////////////////////////////////////////////////////////////////////////
    //  Test characters for specified conditions (using std wchar_t functions)
    ///////////////////////////////////////////////////////////////////////////

    struct standard_wide
    {
        typedef wchar_t char_type;

        template <typename Char>
        static typename std::char_traits<Char>::int_type
        to_int_type(Char ch)
        {
            return std::char_traits<Char>::to_int_type(ch);
        }

        template <typename Char>
        static Char
        to_char_type(typename std::char_traits<Char>::int_type ch)
        {
            return std::char_traits<Char>::to_char_type(ch);
        }

        static bool
        ischar(int ch)
        {
            // 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(ch | traits::wchar_t_size<sizeof(wchar_t)>::mask)
            ) ? true : false;     // any wchar_t, but no other bits set
        }

        static bool
        isalnum(wchar_t ch)
        {
            using namespace std;
            return iswalnum(to_int_type(ch)) ? true : false;
        }

        static bool
        isalpha(wchar_t ch)
        {
            using namespace std;
            return iswalpha(to_int_type(ch)) ? true : false;
        }

        static bool
        iscntrl(wchar_t ch)
        {
            using namespace std;
            return iswcntrl(to_int_type(ch)) ? true : false;
        }

        static bool
        isdigit(wchar_t ch)
        {
            using namespace std;
            return iswdigit(to_int_type(ch)) ? true : false;
        }

        static bool
        isgraph(wchar_t ch)
        {
            using namespace std;
            return iswgraph(to_int_type(ch)) ? true : false;
        }

        static bool
        islower(wchar_t ch)
        {
            using namespace std;
            return iswlower(to_int_type(ch)) ? true : false;
        }

        static bool
        isprint(wchar_t ch)
        {
            using namespace std;
            return iswprint(to_int_type(ch)) ? true : false;
        }

        static bool
        ispunct(wchar_t ch)
        {
            using namespace std;
            return iswpunct(to_int_type(ch)) ? true : false;
        }

        static bool
        isspace(wchar_t ch)
        {
            using namespace std;
            return iswspace(to_int_type(ch)) ? true : false;
        }

        static bool
        isupper(wchar_t ch)
        {
            using namespace std;
            return iswupper(to_int_type(ch)) ? true : false;
        }

        static bool
        isxdigit(wchar_t ch)
        {
            using namespace std;
            return iswxdigit(to_int_type(ch)) ? true : false;
        }

        static bool
        isblank BOOST_PREVENT_MACRO_SUBSTITUTION (wchar_t ch)
        {
            return (ch == L' ' || ch == L'\t');
        }

        ///////////////////////////////////////////////////////////////////////
        //  Simple character conversions
        ///////////////////////////////////////////////////////////////////////

        static wchar_t
        tolower(wchar_t ch)
        {
            using namespace std;
            return isupper(ch) ?
                to_char_type<wchar_t>(towlower(to_int_type(ch))) : ch;
        }

        static wchar_t
        toupper(wchar_t ch)
        {
            using namespace std;
            return islower(ch) ?
                to_char_type<wchar_t>(towupper(to_int_type(ch))) : ch;
        }

        static ::boost::uint32_t
        toucs4(int ch)
        {
            return ch;
        }
    };
}}}

#endif