encoding.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // Copyright (c) 2022-2023 Alexander Grund
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. #ifndef BOOST_LOCALE_DETAIL_ENCODING_HPP_INCLUDED
  7. #define BOOST_LOCALE_DETAIL_ENCODING_HPP_INCLUDED
  8. #include <boost/locale/config.hpp>
  9. #include <boost/locale/encoding_errors.hpp>
  10. #include <boost/utility/string_view.hpp>
  11. #include <memory>
  12. #include <string>
  13. /// \cond INTERNAL
  14. namespace boost { namespace locale { namespace conv { namespace detail {
  15. template<typename CharIn, typename CharOut>
  16. class BOOST_SYMBOL_VISIBLE charset_converter {
  17. public:
  18. using char_out_type = CharOut;
  19. using char_in_type = CharIn;
  20. using string_type = std::basic_string<CharOut>;
  21. virtual ~charset_converter() = default;
  22. virtual string_type convert(const CharIn* begin, const CharIn* end) = 0;
  23. string_type convert(const boost::basic_string_view<CharIn>& text)
  24. {
  25. return convert(text.data(), text.data() + text.length());
  26. }
  27. };
  28. using narrow_converter = charset_converter<char, char>;
  29. template<typename CharType>
  30. using utf_encoder = charset_converter<char, CharType>;
  31. template<typename CharType>
  32. using utf_decoder = charset_converter<CharType, char>;
  33. enum class conv_backend { Default, IConv, ICU, WinAPI };
  34. template<typename Char>
  35. BOOST_LOCALE_DECL std::unique_ptr<utf_encoder<Char>>
  36. make_utf_encoder(const std::string& charset, method_type how, conv_backend impl = conv_backend::Default);
  37. template<typename Char>
  38. BOOST_LOCALE_DECL std::unique_ptr<utf_decoder<Char>>
  39. make_utf_decoder(const std::string& charset, method_type how, conv_backend impl = conv_backend::Default);
  40. BOOST_LOCALE_DECL std::unique_ptr<narrow_converter>
  41. make_narrow_converter(const std::string& src_encoding,
  42. const std::string& target_encoding,
  43. method_type how,
  44. conv_backend impl = conv_backend::Default);
  45. }}}} // namespace boost::locale::conv::detail
  46. /// \endcond
  47. #endif