// Copyright (c) 2001-2011 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_CHAR_CLASS_AUG_10_2009_0720AM) #define BOOST_SPIRIT_KARMA_CHAR_CLASS_AUG_10_2009_0720AM #if defined(_MSC_VER) #pragma once #endif #include #include #include #include #include #include #include #include #include #include #include #include /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { /////////////////////////////////////////////////////////////////////////// // Enablers /////////////////////////////////////////////////////////////////////////// // enables alnum, alpha, graph, etc. template struct use_terminal > : mpl::true_ {}; }} /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { namespace karma { // hoist the char classification namespaces into karma sub-namespaces of // the same name namespace ascii { using namespace boost::spirit::ascii; } namespace iso8859_1 { using namespace boost::spirit::iso8859_1; } namespace standard { using namespace boost::spirit::standard; } namespace standard_wide { using namespace boost::spirit::standard_wide; } #if defined(BOOST_SPIRIT_UNICODE) namespace unicode { using namespace boost::spirit::unicode; } #endif // Import the standard namespace into the karma namespace. This allows // for default handling of all character/string related operations if not // prefixed with a character set namespace. using namespace boost::spirit::standard; // Import encoding using spirit::encoding; /////////////////////////////////////////////////////////////////////////// // // char_class // generates a single character if it matches the given character // class // /////////////////////////////////////////////////////////////////////////// template struct char_class : char_generator< char_class , CharEncoding, CharClass> { typedef typename Tag::char_encoding char_encoding; typedef typename char_encoding::char_type char_type; typedef typename Tag::char_class classification; template struct attribute { typedef char_type type; }; // char_class needs an attached attribute template bool test(Attribute const& attr, CharParam& ch, Context&) const { ch = attr; using spirit::char_class::classify; return classify::is(classification(), attr); } // char_class shouldn't be used without any associated attribute template bool test(unused_type, CharParam&, Context&) const { // It is not possible (doesn't make sense) to use char_ generators // without providing any attribute, as the generator doesn't 'know' // what to output. The following assertion fires if this situation // is detected in your code. BOOST_SPIRIT_ASSERT_FAIL(CharParam , char_class_not_usable_without_attribute, ()); return false; } template static info what(Context const& /*context*/) { typedef spirit::char_class::what what_; return info(what_::is(classification())); } }; /////////////////////////////////////////////////////////////////////////// // // space // generates a single character from the associated parameter // /////////////////////////////////////////////////////////////////////////// template struct any_space : char_generator, CharEncoding, tag::space> { typedef typename CharEncoding::char_type char_type; typedef CharEncoding char_encoding; template struct attribute { typedef char_type type; }; // any_space has an attached parameter template bool test(Attribute const& attr, CharParam& ch, Context&) const { ch = CharParam(attr); using spirit::char_class::classify; return classify::is(tag::space(), attr); } // any_space has no attribute attached, use single space character template bool test(unused_type, CharParam& ch, Context&) const { ch = ' '; return true; } template static info what(Context const& /*context*/) { return info("space"); } }; /////////////////////////////////////////////////////////////////////////// // Generator generators: make_xxx function (objects) /////////////////////////////////////////////////////////////////////////// namespace detail { template struct make_char_class : mpl::identity {}; template <> struct make_char_class : mpl::identity {}; template <> struct make_char_class : mpl::identity {}; template <> struct make_char_class : mpl::identity {}; template <> struct make_char_class : mpl::identity {}; } // enables alnum, alpha, graph, etc. template struct make_primitive, Modifiers> { static bool const lower = has_modifier >::value; static bool const upper = has_modifier >::value; typedef tag::char_code< typename detail::make_char_class::type , CharEncoding> tag_type; typedef char_class< tag_type , typename spirit::detail::get_encoding_with_case< Modifiers, CharEncoding, lower || upper>::type , typename detail::get_casetag::type > result_type; result_type operator()(unused_type, unused_type) const { return result_type(); } }; // space is special template struct make_primitive, Modifiers> { typedef any_space result_type; result_type operator()(unused_type, unused_type) const { return result_type(); } }; }}} // namespace boost::spirit::karma #endif // !defined(BOOST_SPIRIT_KARMA_CHAR_FEB_21_2007_0543PM)