1 // Copyright (c) 2012 David Bailey 2 // Copyright (c) 2001-2012 Hartmut Kaiser 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 7 #include <boost/config/warning_disable.hpp> 8 #include <boost/detail/lightweight_test.hpp> 9 10 #ifndef BOOST_SPIRIT_UNICODE 11 #define BOOST_SPIRIT_UNICODE 12 #endif 13 14 #include <boost/spirit/home/karma/nonterminal/grammar.hpp> 15 #include <boost/spirit/home/karma/nonterminal/rule.hpp> 16 #include <boost/spirit/home/karma/char.hpp> 17 18 #include "test.hpp" 19 20 using namespace spirit_test; 21 22 /////////////////////////////////////////////////////////////////////////////// 23 template <typename OutputIterator> 24 struct unicode_char_grammar_ 25 : public boost::spirit::karma::grammar< 26 OutputIterator, boost::spirit::char_encoding::unicode::char_type()> 27 { unicode_char_grammar_unicode_char_grammar_28 unicode_char_grammar_() : unicode_char_grammar_::base_type(thechar) 29 { 30 using boost::spirit::karma::unicode::char_; 31 thechar = char_; 32 } 33 34 boost::spirit::karma::rule< 35 OutputIterator, boost::spirit::char_encoding::unicode::char_type() 36 > thechar; 37 }; 38 39 int main()40main() 41 { 42 using namespace boost::spirit; 43 44 { 45 typedef std::basic_string<char_encoding::unicode::char_type> unicode_string; 46 typedef std::back_insert_iterator<unicode_string> unicode_back_insert_iterator_type; 47 48 using namespace boost::spirit::unicode; 49 50 BOOST_TEST(test("x", char_, 'x')); 51 BOOST_TEST(test(L"x", char_, L'x')); 52 53 char_encoding::unicode::char_type unicodeCharacter = 0x00000078u; 54 std::basic_string<char_encoding::unicode::char_type> expected; 55 expected.push_back(unicodeCharacter); 56 57 unicode_char_grammar_<unicode_back_insert_iterator_type> unichar; 58 59 BOOST_TEST(test(expected, unichar, unicodeCharacter)); 60 } 61 62 return boost::report_errors(); 63 } 64