diff options
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/config.cmake | 3 | ||||
-rw-r--r-- | platform/default/codecvt/codecvt | 30 | ||||
-rw-r--r-- | platform/default/utf.cpp | 16 |
3 files changed, 35 insertions, 14 deletions
diff --git a/platform/android/config.cmake b/platform/android/config.cmake index d6be05095b..004912ba1a 100644 --- a/platform/android/config.cmake +++ b/platform/android/config.cmake @@ -71,6 +71,7 @@ macro(mbgl_filesource) target_add_mason_package(mbgl-filesource PUBLIC jni.hpp) target_link_libraries(mbgl-filesource + PRIVATE codecvt PUBLIC sqlite PUBLIC -llog PUBLIC -landroid @@ -86,6 +87,7 @@ add_library(mapbox-gl SHARED ) target_link_libraries(mapbox-gl + PRIVATE codecvt PRIVATE mbgl-core PRIVATE mbgl-filesource ) @@ -106,6 +108,7 @@ macro(mbgl_platform_test) ) target_link_libraries(mbgl-test + PRIVATE codecvt PRIVATE mbgl-core PRIVATE mbgl-filesource ) diff --git a/platform/default/codecvt/codecvt b/platform/default/codecvt/codecvt new file mode 100644 index 0000000000..8d21e82348 --- /dev/null +++ b/platform/default/codecvt/codecvt @@ -0,0 +1,30 @@ +#pragma once + +// This is a minimal polyfill that'll only work exactly for how we use codecvt + +#include <string> +#include <boost/locale/encoding_utf.hpp> + +namespace std { + +template <typename Codecvt, typename Elem = wchar_t> +class wstring_convert { +public: + static_assert(std::is_same<Elem, typename Codecvt::Elem>::value, "type mismatch"); + + inline std::basic_string<Elem> from_bytes(const string& str) { + return boost::locale::conv::utf_to_utf<Elem>(str); + } + + inline string to_bytes(const std::basic_string<Elem>& str) { + return boost::locale::conv::utf_to_utf<char>(str); + } +}; + +template <typename E> +class codecvt_utf8_utf16 { +public: + using Elem = E; +}; + +} // namespace std diff --git a/platform/default/utf.cpp b/platform/default/utf.cpp index 8fc44a9ed3..8bc8ea7314 100644 --- a/platform/default/utf.cpp +++ b/platform/default/utf.cpp @@ -1,25 +1,13 @@ #include <mbgl/util/utf.hpp> -#include <memory> #include <locale> - -// GCC 4.9 compatibility -#if !defined(__GNUC__) || __GNUC__ >= 5 #include <codecvt> -#else -#include <boost/locale/encoding_utf.hpp> -#endif namespace mbgl { namespace util { -std::u16string utf8_to_utf16::convert(std::string const& utf8) { -#if !defined(__GNUC__) || __GNUC__ >= 5 - std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter; - return converter.from_bytes(utf8); -#else - return boost::locale::conv::utf_to_utf<char16_t>(utf8.c_str(), utf8.c_str() + utf8.size()); -#endif +std::u16string utf8_to_utf16::convert(const std::string& utf8) { + return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>().from_bytes(utf8); } } // namespace util |