to_utf8.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132
  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/support/utf8.hpp>
  8. #if defined(_MSC_VER) && _MSC_VER < 1700
  9. # pragma warning(disable: 4428) // universal-character-name encountered in source
  10. #endif
  11. int main()
  12. {
  13. using boost::spirit::to_utf8;
  14. // Assume wchar_t is 16-bit on Windows and 32-bit on Unix
  15. #if defined(_WIN32) || defined(__CYGWIN__)
  16. BOOST_TEST_CSTR_EQ("\xEF\xBF\xA1", to_utf8(L'\uFFE1').c_str());
  17. #else
  18. BOOST_TEST_CSTR_EQ("\xF0\x9F\xA7\x90", to_utf8(L'\U0001F9D0').c_str());
  19. #endif
  20. BOOST_TEST_CSTR_EQ("\xF0\x9F\xA7\x90\xF0\x9F\xA7\xA0",
  21. to_utf8(L"\U0001F9D0\U0001F9E0").c_str());
  22. BOOST_TEST_CSTR_EQ("\xF0\x9F\xA7\x90\xF0\x9F\xA7\xA0",
  23. to_utf8(std::wstring(L"\U0001F9D0\U0001F9E0")).c_str());
  24. return boost::report_errors();
  25. }