utf.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (C) 2020 T. Zachary Laine
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_PARSER_DETAIL_TEXT_UTF_HPP
  7. #define BOOST_PARSER_DETAIL_TEXT_UTF_HPP
  8. #include <boost/parser/detail/text/config.hpp>
  9. #include <cstdint>
  10. #include <type_traits>
  11. #include <cstdint>
  12. namespace boost::parser::detail { namespace text {
  13. /** The Unicode Transformation Formats. */
  14. enum class format { none = 0, utf8 = 1, utf16 = 2, utf32 = 4 };
  15. namespace detail {
  16. template<typename T>
  17. constexpr format format_of()
  18. {
  19. if constexpr (
  20. std::is_same_v<T, char>
  21. #if defined(__cpp_char8_t)
  22. || std::is_same_v<T, char8_t>
  23. #endif
  24. ) {
  25. return format::utf8;
  26. } else if (
  27. std::is_same_v<T, char16_t>
  28. #ifdef _MSC_VER
  29. || std::is_same_v<T, wchar_t>
  30. #endif
  31. ) {
  32. return format::utf16;
  33. } else {
  34. return format::utf32;
  35. }
  36. }
  37. }
  38. }}
  39. #endif