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