1 #ifndef BOOST_METAPARSE_V1_STRING_HPP
2 #define BOOST_METAPARSE_V1_STRING_HPP
4 // Copyright Abel Sinkovics (abel@sinkovics.hu) 2012.
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 #include <boost/metaparse/config.hpp>
10 #include <boost/metaparse/v1/fwd/string.hpp>
11 #include <boost/metaparse/v1/string_tag.hpp>
12 #include <boost/metaparse/v1/impl/string_iterator.hpp>
13 #include <boost/metaparse/v1/impl/empty_string.hpp>
14 #include <boost/metaparse/v1/impl/size.hpp>
15 #include <boost/metaparse/v1/impl/pop_front.hpp>
16 #include <boost/metaparse/v1/impl/push_front_c.hpp>
17 #include <boost/metaparse/v1/impl/push_back_c.hpp>
18 #include <boost/metaparse/v1/impl/pop_back.hpp>
19 #include <boost/metaparse/v1/impl/assert_string_length.hpp>
20 #include <boost/metaparse/v1/impl/string_at.hpp>
22 #include <boost/preprocessor/arithmetic/sub.hpp>
23 #include <boost/preprocessor/punctuation/comma_if.hpp>
24 #include <boost/preprocessor/repetition/enum.hpp>
25 #include <boost/preprocessor/repetition/enum_params.hpp>
26 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
27 #include <boost/preprocessor/tuple/eat.hpp>
29 #include <boost/type_traits/is_same.hpp>
41 #ifdef BOOST_METAPARSE_VARIADIC_STRING
46 typedef string_tag tag;
49 template <BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, int C)>
53 typedef string_tag tag;
70 struct push_back_impl;
73 struct push_back_impl<boost::metaparse::v1::string_tag>
75 typedef push_back_impl type;
77 template <class S, class C>
79 boost::metaparse::v1::impl::push_back_c<
91 struct pop_back_impl<boost::metaparse::v1::string_tag>
93 typedef pop_back_impl type;
96 struct apply : boost::metaparse::v1::impl::pop_back<S> {};
101 struct push_front_impl;
104 struct push_front_impl<boost::metaparse::v1::string_tag>
106 typedef push_front_impl type;
108 template <class S, class C>
110 boost::metaparse::v1::impl::push_front_c<
119 struct pop_front_impl;
122 struct pop_front_impl<boost::metaparse::v1::string_tag>
124 typedef pop_front_impl type;
127 struct apply : boost::metaparse::v1::impl::pop_front<S> {};
135 struct clear_impl<boost::metaparse::v1::string_tag>
137 typedef clear_impl type;
140 struct apply : boost::metaparse::v1::string<> {};
148 struct begin_impl<boost::metaparse::v1::string_tag>
150 typedef begin_impl type;
154 boost::metaparse::v1::impl::string_iterator<typename S::type, 0>
163 struct end_impl<boost::metaparse::v1::string_tag>
165 typedef end_impl type;
169 boost::metaparse::v1::impl::string_iterator<
171 boost::metaparse::v1::impl::size<typename S::type>::type::value
177 template <class A, class B>
178 struct equal_to_impl;
181 struct equal_to_impl<
182 boost::metaparse::v1::string_tag,
183 boost::metaparse::v1::string_tag
186 typedef equal_to_impl type;
188 template <class A, class B>
189 struct apply : boost::is_same<typename A::type, typename B::type> {};
193 struct equal_to_impl<boost::metaparse::v1::string_tag, T>
195 typedef equal_to_impl type;
197 template <class, class>
198 struct apply : false_ {};
202 struct equal_to_impl<T, boost::metaparse::v1::string_tag> :
203 equal_to_impl<boost::metaparse::v1::string_tag, T>
210 #ifdef BOOST_METAPARSE_VARIADIC_STRING
211 template <char... Cs>
212 struct c_str<boost::metaparse::v1::string<Cs...>>
215 #ifdef BOOST_NO_CONSTEXPR_C_STR
216 static const char value[sizeof...(Cs) + 1];
218 static constexpr char value[sizeof...(Cs) + 1] = {Cs..., 0};
223 struct c_str<boost::metaparse::v1::string<>> :
224 boost::metaparse::v1::impl::empty_string<>
227 #ifdef BOOST_NO_CONSTEXPR_C_STR
228 template <char... Cs>
229 const char c_str<boost::metaparse::v1::string<Cs...>>::value[]
232 template <char... Cs>
233 constexpr char c_str<boost::metaparse::v1::string<Cs...>>::value[];
237 template <BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, int C)>
239 boost::metaparse::v1::string<
240 BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, C)
245 static BOOST_CONSTEXPR const char
246 value[BOOST_METAPARSE_LIMIT_STRING_SIZE + 1]
247 #if !defined BOOST_NO_CONSTEXPR && !defined BOOST_NO_CXX11_CONSTEXPR
248 = {BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, C), 0}
253 template <BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, int C)>
254 BOOST_CONSTEXPR const char
256 boost::metaparse::v1::string<
257 BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, C)
259 >::value[BOOST_METAPARSE_LIMIT_STRING_SIZE + 1]
260 #if defined BOOST_NO_CONSTEXPR || defined BOOST_NO_CXX11_CONSTEXPR
261 = {BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, C), 0}
266 struct c_str<boost::metaparse::v1::string<> > :
267 boost::metaparse::v1::impl::empty_string<>
272 #ifdef BOOST_METAPARSE_DEF
273 # error BOOST_METAPARSE_DEF already defined
275 #define BOOST_METAPARSE_DEF(n) \
276 = {BOOST_PP_ENUM_PARAMS(n, C) BOOST_PP_COMMA_IF(n) 0}
278 #ifdef BOOST_METAPARSE_STRING_DECLARE
279 # error BOOST_METAPARSE_STRING_DECLARE already defined
281 #ifdef BOOST_METAPARSE_STRING_DEFINE
282 # error BOOST_METAPARSE_STRING_DECLARE already defined
284 #if !defined BOOST_NO_CONSTEXPR && !defined BOOST_NO_CXX11_CONSTEXPR
285 # define BOOST_METAPARSE_STRING_DECLARE(n) BOOST_METAPARSE_DEF(n)
286 # define BOOST_METAPARSE_STRING_DEFINE(n)
288 # define BOOST_METAPARSE_STRING_DECLARE(n)
289 # define BOOST_METAPARSE_STRING_DEFINE(n) BOOST_METAPARSE_DEF(n)
292 #ifdef BOOST_METAPARSE_STRING_CASE
293 # error BOOST_METAPARSE_STRING_CASE is already defined
295 #define BOOST_METAPARSE_STRING_CASE(z, n, unused) \
296 template <BOOST_PP_ENUM_PARAMS(n, int C)> \
299 boost::metaparse::v1::string< \
300 BOOST_PP_ENUM_PARAMS(n, C) BOOST_PP_COMMA_IF(n) \
302 BOOST_PP_SUB(BOOST_METAPARSE_LIMIT_STRING_SIZE, n), \
303 BOOST_NO_CHAR BOOST_PP_TUPLE_EAT(3), \
309 typedef c_str type; \
310 static BOOST_CONSTEXPR const char value[n + 1] \
311 BOOST_METAPARSE_STRING_DECLARE(n); \
314 template <BOOST_PP_ENUM_PARAMS(n, int C)> \
315 BOOST_CONSTEXPR const char c_str< \
316 boost::metaparse::v1::string< \
317 BOOST_PP_ENUM_PARAMS(n, C) BOOST_PP_COMMA_IF(n) \
319 BOOST_PP_SUB(BOOST_METAPARSE_LIMIT_STRING_SIZE, n), \
320 BOOST_NO_CHAR BOOST_PP_TUPLE_EAT(3), \
324 >::value[n + 1] BOOST_METAPARSE_STRING_DEFINE(n);
326 BOOST_PP_REPEAT_FROM_TO(
328 BOOST_METAPARSE_LIMIT_STRING_SIZE,
329 BOOST_METAPARSE_STRING_CASE,
333 #undef BOOST_METAPARSE_STRING_CASE
334 #undef BOOST_METAPARSE_STRING_DECLARE
335 #undef BOOST_METAPARSE_STRING_DEFINE
336 #undef BOOST_METAPARSE_DEF
341 #include <boost/metaparse/v1/impl/remove_trailing_no_chars.hpp>
344 defined BOOST_METAPARSE_VARIADIC_STRING \
345 && !defined BOOST_NO_CONSTEXPR && !defined BOOST_NO_CXX11_CONSTEXPR
347 # include <boost/metaparse/v1/impl/string.hpp>
351 # define BOOST_METAPARSE_V1_CONFIG_NO_BOOST_METAPARSE_STRING 1