]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/spirit/home/x3/string/literal_string.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / spirit / home / x3 / string / literal_string.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_LITERAL_STRING_APR_18_2006_1125PM)
8 #define BOOST_SPIRIT_X3_LITERAL_STRING_APR_18_2006_1125PM
9
10 #include <boost/spirit/home/x3/core/parser.hpp>
11 #include <boost/spirit/home/x3/core/skip_over.hpp>
12 #include <boost/spirit/home/x3/string/detail/string_parse.hpp>
13 #include <boost/spirit/home/x3/support/no_case.hpp>
14 #include <boost/spirit/home/x3/string/detail/no_case_string_parse.hpp>
15 #include <boost/spirit/home/x3/support/utility/utf8.hpp>
16 #include <boost/spirit/home/support/char_encoding/ascii.hpp>
17 #include <boost/spirit/home/support/char_encoding/standard.hpp>
18 #include <boost/spirit/home/support/char_encoding/standard_wide.hpp>
19
20 #include <boost/type_traits/is_same.hpp>
21 #include <boost/type_traits/add_reference.hpp>
22 #include <string>
23
24 namespace boost { namespace spirit { namespace x3
25 {
26 template <typename String, typename Encoding,
27 typename Attribute = std::basic_string<typename Encoding::char_type>>
28 struct literal_string : parser<literal_string<String, Encoding, Attribute>>
29 {
30 typedef typename Encoding::char_type char_type;
31 typedef Encoding encoding;
32 typedef Attribute attribute_type;
33 static bool const has_attribute =
34 !is_same<unused_type, attribute_type>::value;
35 static bool const handles_container = has_attribute;
36
37 literal_string(typename add_reference< typename add_const<String>::type >::type str)
38 : str(str)
39 {}
40
41 template <typename Iterator, typename Context, typename Attribute_>
42 bool parse(Iterator& first, Iterator const& last
43 , Context const& context, unused_type, Attribute_& attr) const
44 {
45 x3::skip_over(first, last, context);
46 return detail::string_parse(str, first, last, attr, get_case_compare<encoding>(context));
47 }
48
49 String str;
50 };
51
52 namespace standard
53 {
54 inline literal_string<char const*, char_encoding::standard>
55 string(char const* s)
56 {
57 return { s };
58 }
59
60 inline literal_string<std::basic_string<char>, char_encoding::standard>
61 string(std::basic_string<char> const& s)
62 {
63 return { s };
64 }
65
66 inline literal_string<char const*, char_encoding::standard, unused_type>
67 lit(char const* s)
68 {
69 return { s };
70 }
71
72 template <typename Char>
73 literal_string<std::basic_string<Char>, char_encoding::standard, unused_type>
74 lit(std::basic_string<Char> const& s)
75 {
76 return { s };
77 }
78 }
79
80 #ifndef BOOST_SPIRIT_NO_STANDARD_WIDE
81 namespace standard_wide
82 {
83 inline literal_string<wchar_t const*, char_encoding::standard_wide>
84 string(wchar_t const* s)
85 {
86 return { s };
87 }
88
89 inline literal_string<std::basic_string<wchar_t>, char_encoding::standard_wide>
90 string(std::basic_string<wchar_t> const& s)
91 {
92 return { s };
93 }
94
95 inline literal_string<wchar_t const*, char_encoding::standard_wide, unused_type>
96 lit(wchar_t const* s)
97 {
98 return { s };
99 }
100
101 inline literal_string<std::basic_string<wchar_t>, char_encoding::standard_wide, unused_type>
102 lit(std::basic_string<wchar_t> const& s)
103 {
104 return { s };
105 }
106 }
107 #endif
108
109 namespace ascii
110 {
111 inline literal_string<wchar_t const*, char_encoding::ascii>
112 string(wchar_t const* s)
113 {
114 return { s };
115 }
116
117 inline literal_string<std::basic_string<wchar_t>, char_encoding::ascii>
118 string(std::basic_string<wchar_t> const& s)
119 {
120 return { s };
121 }
122
123 inline literal_string<char const*, char_encoding::ascii, unused_type>
124 lit(char const* s)
125 {
126 return { s };
127 }
128
129 template <typename Char>
130 literal_string<std::basic_string<Char>, char_encoding::ascii, unused_type>
131 lit(std::basic_string<Char> const& s)
132 {
133 return { s };
134 }
135 }
136
137 namespace iso8859_1
138 {
139 inline literal_string<wchar_t const*, char_encoding::iso8859_1>
140 string(wchar_t const* s)
141 {
142 return { s };
143 }
144
145 inline literal_string<std::basic_string<wchar_t>, char_encoding::iso8859_1>
146 string(std::basic_string<wchar_t> const& s)
147 {
148 return { s };
149 }
150
151 inline literal_string<char const*, char_encoding::iso8859_1, unused_type>
152 lit(char const* s)
153 {
154 return { s };
155 }
156
157 template <typename Char>
158 literal_string<std::basic_string<Char>, char_encoding::iso8859_1, unused_type>
159 lit(std::basic_string<Char> const& s)
160 {
161 return { s };
162 }
163 }
164
165 using standard::string;
166 using standard::lit;
167 #ifndef BOOST_SPIRIT_NO_STANDARD_WIDE
168 using standard_wide::string;
169 using standard_wide::lit;
170 #endif
171
172 namespace extension
173 {
174 template <int N>
175 struct as_parser<char[N]>
176 {
177 typedef literal_string<
178 char const*, char_encoding::standard, unused_type>
179 type;
180
181 typedef type value_type;
182
183 static type call(char const* s)
184 {
185 return type(s);
186 }
187 };
188
189 template <int N>
190 struct as_parser<char const[N]> : as_parser<char[N]> {};
191
192 #ifndef BOOST_SPIRIT_NO_STANDARD_WIDE
193 template <int N>
194 struct as_parser<wchar_t[N]>
195 {
196 typedef literal_string<
197 wchar_t const*, char_encoding::standard_wide, unused_type>
198 type;
199
200 typedef type value_type;
201
202 static type call(wchar_t const* s)
203 {
204 return type(s);
205 }
206 };
207
208 template <int N>
209 struct as_parser<wchar_t const[N]> : as_parser<wchar_t[N]> {};
210 #endif
211
212 template <>
213 struct as_parser<char const*>
214 {
215 typedef literal_string<
216 char const*, char_encoding::standard, unused_type>
217 type;
218
219 typedef type value_type;
220
221 static type call(char const* s)
222 {
223 return type(s);
224 }
225 };
226
227 template <typename Char>
228 struct as_parser< std::basic_string<Char> >
229 {
230 typedef literal_string<
231 Char const*, char_encoding::standard, unused_type>
232 type;
233
234 typedef type value_type;
235
236 static type call(std::basic_string<Char> const& s)
237 {
238 return type(s.c_str());
239 }
240 };
241 }
242
243 template <typename String, typename Encoding, typename Attribute>
244 struct get_info<literal_string<String, Encoding, Attribute>>
245 {
246 typedef std::string result_type;
247 std::string operator()(literal_string<String, Encoding, Attribute> const& p) const
248 {
249 return '"' + to_utf8(p.str) + '"';
250 }
251 };
252 }}}
253
254 #endif