#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 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: lit_str_p() = default; 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: str_p() = default; 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