Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / spirit / home / x3 / char / any_char.hpp
1 /*=============================================================================
2     Copyright (c) 2001-2014 Joel de Guzman
3
4     Distributed under the Boost Software License, Version 1.0. (See accompanying
5     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #if !defined(BOOST_SPIRIT_X3_ANY_CHAR_APRIL_16_2006_1051AM)
8 #define BOOST_SPIRIT_X3_ANY_CHAR_APRIL_16_2006_1051AM
9
10 #include <boost/type_traits/extent.hpp>
11 #include <boost/spirit/home/x3/char/literal_char.hpp>
12 #include <boost/spirit/home/x3/char/char_set.hpp>
13
14 namespace boost { namespace spirit { namespace x3
15 {
16     template <typename Encoding>
17     struct any_char : char_parser<any_char<Encoding>>
18     {
19         typedef typename Encoding::char_type char_type;
20         typedef Encoding encoding;
21         typedef char_type attribute_type;
22         static bool const has_attribute = true;
23
24         template <typename Char, typename Context>
25         bool test(Char ch_, Context const&) const
26         {
27             return encoding::ischar(ch_);
28         }
29
30         template <typename Char>
31         literal_char<Encoding> operator()(Char ch) const
32         {
33             return { ch };
34         }
35
36         template <typename Char>
37         literal_char<Encoding> operator()(const Char (&ch)[2]) const
38         {
39             return { ch[0] };
40         }
41
42         template <typename Char, std::size_t N>
43         char_set<Encoding> operator()(const Char (&ch)[N]) const
44         {
45             return { ch };
46         }
47
48         template <typename Char>
49         char_range<Encoding> operator()(Char from, Char to) const
50         {
51             return { from, to };
52         }
53
54         template <typename Char>
55         char_range<Encoding> operator()(Char (&from)[2], Char (&to)[2]) const
56         {
57             return { static_cast<char_type>(from[0]), static_cast<char_type>(to[0]) };
58         }
59
60         template <typename Char>
61         char_set<Encoding> operator()(std::basic_string<Char> const& s) const
62         {
63             return { s };
64         }
65     };
66 }}}
67
68 #endif