/*============================================================================= Copyright (c) 2011-2017 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout 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) =============================================================================*/ #ifndef SPROUT_WEED_PARSER_STRING_STRING_HPP #define SPROUT_WEED_PARSER_STRING_STRING_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace sprout { namespace weed { // // lit_str_p // template struct lit_str_p : public sprout::weed::parser_base { public: template struct attribute : public sprout::identity {}; template struct result : public sprout::identity::type> > {}; private: T t_; public: SPROUT_CONSTEXPR lit_str_p() SPROUT_DEFAULTED_DEFAULT_CONSTRUCTOR_DECL explicit SPROUT_CONSTEXPR lit_str_p(T const& t) : t_(t) {} template SPROUT_CONSTEXPR typename result::type operator()( Iterator first, Iterator last, Context const& ) const { typedef typename result::type result_type; typedef typename attribute::type attribute_type; return sprout::distance(first, last) >= sprout::size(t_) && sprout::equal(sprout::begin(t_), sprout::end(t_), first) ? result_type(true, sprout::next(first, sprout::size(t_)), attribute_type()) : result_type(false, first, typename attribute::type()) ; } }; // // lit_g // template struct lit_g::eval< T, typename std::enable_if< sprout::weed::traits::is_c_str::value >::type > { public: typedef sprout::weed::lit_str_p< typename sprout::weed::detail::c_str_as_string::type > result_type; public: SPROUT_CONSTEXPR result_type operator()(T const& t) const { return result_type(sprout::to_string(t)); } }; template struct lit_g::eval< T, typename std::enable_if< sprout::weed::traits::is_string::value >::type > { public: typedef sprout::weed::lit_str_p result_type; public: SPROUT_CONSTEXPR result_type operator()(T const& t) const { return result_type(t); } }; // // str_p // template struct str_p : public sprout::weed::parser_base { public: template struct attribute : public sprout::identity {}; template struct result : public sprout::identity::type> > {}; private: T t_; public: SPROUT_CONSTEXPR str_p() SPROUT_DEFAULTED_DEFAULT_CONSTRUCTOR_DECL explicit SPROUT_CONSTEXPR str_p(T const& t) : t_(t) {} template SPROUT_CONSTEXPR typename result::type operator()( Iterator first, Iterator last, Context const& ) const { typedef typename result::type result_type; typedef typename attribute::type attribute_type; return sprout::distance(first, last) >= sprout::size(t_) && sprout::equal(sprout::begin(t_), sprout::end(t_), first) ? result_type(true, sprout::next(first, sprout::size(t_)), attribute_type()) : result_type(false, first, typename attribute::type()) ; } }; // // string // template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::weed::traits::is_c_str::value, sprout::weed::str_p< typename sprout::weed::detail::c_str_as_string::type > >::type string(T const& t) { return sprout::weed::str_p< typename sprout::weed::detail::c_str_as_string::type >(sprout::to_string(t)); } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::weed::traits::is_string::value, sprout::weed::str_p >::type string(T const& t) { return sprout::weed::str_p(t); } } // namespace weed } // namespace sprout #endif // #ifndef SPROUT_WEED_PARSER_STRING_STRING_HPP