// Copyright (c) 2001-2008 Hartmut Kaiser // // 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) #if !defined(BOOST_SPIRIT_KARMA_LIT_FEB_22_2007_0534PM) #define BOOST_SPIRIT_KARMA_LIT_FEB_22_2007_0534PM #if defined(_MSC_VER) && (_MSC_VER >= 1020) #pragma once // MS compatible compilers support #pragma once #endif #include #include #include #include #include #include #include #include #include namespace boost { namespace spirit { namespace karma { /////////////////////////////////////////////////////////////////////////// // generate literal strings from a given parameter /////////////////////////////////////////////////////////////////////////// template struct any_string { template struct attribute { typedef std::basic_string type; }; // lit has a parameter attached template static bool generate(Component const& /*component*/, OutputIterator& sink, Context& /*ctx*/, Delimiter const& d, Parameter const& param) { bool result = detail::string_generate(sink, param); if (result) karma::delimit(sink, d); // always do post-delimiting return result; } // this lit has no parameter attached, it needs to have been // initialized from a direct literal template static bool generate(Component const& component, OutputIterator& sink, Context& /*ctx*/, Delimiter const& d, unused_type) { BOOST_MPL_ASSERT_MSG(false, lit_not_usable_without_parameter, ()); return false; } template static std::string what(Component const& component, Context const& ctx) { return "any-string"; } }; /////////////////////////////////////////////////////////////////////////// // generate literal strings /////////////////////////////////////////////////////////////////////////// template struct literal_string { template struct attribute { typedef unused_type type; }; template static bool generate(Component const& component, OutputIterator& sink, Context& /*ctx*/, Delimiter const& d, Parameter const& /*param*/) { bool result = detail::string_generate(sink, fusion::at_c<0>(component.elements)); karma::delimit(sink, d); // always do post-delimiting return result; } template static std::string what(Component const& component, Context const& ctx) { return std::string("\"") + spirit::detail::to_narrow_string( fusion::at_c<0>(component.elements)) + std::string("\"") ; } }; /////////////////////////////////////////////////////////////////////////// // lazy string generation /////////////////////////////////////////////////////////////////////////// struct lazy_string { template struct attribute { typedef unused_type type; }; template static bool generate(Component const& component, OutputIterator& sink, Context& ctx, Delimiter const& d, Parameter const& /*param*/) { bool result = detail::string_generate(sink, fusion::at_c<0>(component.elements)(unused, ctx)); karma::delimit(sink, d); // always do post-delimiting return result; } template static std::string what(Component const& component, Context const& ctx) { return "string"; } }; /////////////////////////////////////////////////////////////////////////// // generate literal strings from a given parameter /////////////////////////////////////////////////////////////////////////// template struct case_any_string { template struct attribute { typedef std::basic_string type; }; // case_any_string has a parameter attached template static bool generate(Component const& /*component*/, OutputIterator& sink, Context& /*ctx*/, Delimiter const& d, Parameter const& param) { bool result = detail::string_generate(sink, param, Tag()); karma::delimit(sink, d); // always do post-delimiting return result; } // this case_any_string has no parameter attached, it needs to have been // initialized from a direct literal template static bool generate(Component const& component, OutputIterator& sink, Context& /*ctx*/, Delimiter const& d, unused_type) { BOOST_MPL_ASSERT_MSG(false, lit_not_usable_without_parameter, ()); return false; } template static std::string what(Component const& component, Context const& ctx) { typedef typename Tag::char_set char_set; typedef typename Tag::char_class char_class_; return std::string("any-") + spirit::char_class::what::is(char_class_()) + "case-string"; } }; }}} namespace boost { namespace spirit { namespace traits { /////////////////////////////////////////////////////////////////////////// // lower_case and upper_case literal_string generator /////////////////////////////////////////////////////////////////////////// template struct make_modified_component< Domain, karma::literal_string, Elements, Modifier, typename enable_if< is_member_of_modifier >::type > { typedef std::basic_string string_type; typedef fusion::vector vector_type; typedef component, vector_type> type; static type call(Elements const& elements) { typedef typename Modifier::char_set char_set; string_type val(fusion::at_c<0>(elements)); typename string_type::iterator end = val.end(); for (typename string_type::iterator it = val.begin(); it != end; ++it) { *it = char_set::tolower(*it); } return type(vector_type(val)); } }; template struct make_modified_component< Domain, karma::literal_string, Elements, Modifier, typename enable_if< is_member_of_modifier >::type > { typedef std::basic_string string_type; typedef fusion::vector vector_type; typedef component, vector_type> type; static type call(Elements const& elements) { typedef typename Modifier::char_set char_set; string_type val(fusion::at_c<0>(elements)); typename string_type::iterator end = val.end(); for (typename string_type::iterator it = val.begin(); it != end; ++it) { *it = char_set::toupper(*it); } return type(vector_type(val)); } }; /////////////////////////////////////////////////////////////////////////// // lower and upper case_any_string conversions /////////////////////////////////////////////////////////////////////////// template struct make_modified_component< Domain, karma::any_string, Elements, Modifier, typename enable_if< is_member_of_modifier >::type > { typedef typename Modifier::char_set char_set; typedef spirit::char_class::tag::lower char_class_; typedef spirit::char_class::key key_tag; typedef component< karma::domain, karma::case_any_string, fusion::nil > type; static type call(Elements const&) { return type(fusion::nil()); } }; template struct make_modified_component< Domain, karma::any_string, Elements, Modifier, typename enable_if< is_member_of_modifier >::type > { typedef typename Modifier::char_set char_set; typedef spirit::char_class::tag::upper char_class_; typedef spirit::char_class::key key_tag; typedef component< karma::domain, karma::case_any_string, fusion::nil > type; static type call(Elements const&) { return type(fusion::nil()); } }; }}} #endif