regression_unicode_char.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include <boost/config/warning_disable.hpp>
  7. #include <boost/detail/lightweight_test.hpp>
  8. #ifndef BOOST_SPIRIT_UNICODE
  9. #define BOOST_SPIRIT_UNICODE
  10. #endif
  11. #include <boost/spirit/home/karma/nonterminal/grammar.hpp>
  12. #include <boost/spirit/home/karma/nonterminal/rule.hpp>
  13. #include <boost/spirit/home/karma/char.hpp>
  14. #include "test.hpp"
  15. using namespace spirit_test;
  16. ///////////////////////////////////////////////////////////////////////////////
  17. template <typename OutputIterator>
  18. struct unicode_char_grammar_
  19. : public boost::spirit::karma::grammar<
  20. OutputIterator, boost::spirit::char_encoding::unicode::char_type()>
  21. {
  22. unicode_char_grammar_() : unicode_char_grammar_::base_type(thechar)
  23. {
  24. using boost::spirit::karma::unicode::char_;
  25. thechar = char_;
  26. }
  27. boost::spirit::karma::rule<
  28. OutputIterator, boost::spirit::char_encoding::unicode::char_type()
  29. > thechar;
  30. };
  31. int
  32. main()
  33. {
  34. using namespace boost::spirit;
  35. {
  36. typedef std::basic_string<char_encoding::unicode::char_type> unicode_string;
  37. typedef std::back_insert_iterator<unicode_string> unicode_back_insert_iterator_type;
  38. using namespace boost::spirit::unicode;
  39. BOOST_TEST(test("x", char_, 'x'));
  40. BOOST_TEST(test(L"x", char_, L'x'));
  41. char_encoding::unicode::char_type unicodeCharacter = 0x00000078u;
  42. std::basic_string<char_encoding::unicode::char_type> expected;
  43. expected.push_back(unicodeCharacter);
  44. unicode_char_grammar_<unicode_back_insert_iterator_type> unichar;
  45. BOOST_TEST(test(expected, unichar, unicodeCharacter));
  46. }
  47. return boost::report_errors();
  48. }