to_utf8.cpp 1.0 KB

12345678910111213141516171819202122232425262728
  1. /*=============================================================================
  2. Copyright (c) 2018 Nikita Kniazev
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. =============================================================================*/
  6. #include <boost/core/lightweight_test.hpp>
  7. #include <boost/spirit/home/x3/support/utility/utf8.hpp>
  8. int main()
  9. {
  10. using boost::spirit::x3::to_utf8;
  11. // Assume wchar_t is 16-bit on Windows and 32-bit on Unix
  12. #if defined(_WIN32) || defined(__CYGWIN__)
  13. BOOST_TEST_CSTR_EQ("\xEF\xBF\xA1", to_utf8(L'\uFFE1').c_str());
  14. #else
  15. BOOST_TEST_CSTR_EQ("\xF0\x9F\xA7\x90", to_utf8(L'\U0001F9D0').c_str());
  16. #endif
  17. BOOST_TEST_CSTR_EQ("\xF0\x9F\xA7\x90\xF0\x9F\xA7\xA0",
  18. to_utf8(L"\U0001F9D0\U0001F9E0").c_str());
  19. BOOST_TEST_CSTR_EQ("\xF0\x9F\xA7\x90\xF0\x9F\xA7\xA0",
  20. to_utf8(std::wstring(L"\U0001F9D0\U0001F9E0")).c_str());
  21. return boost::report_errors();
  22. }