From 30e570aae7d2ba5522feafb962b334ef3f35459e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 21 Jun 2018 14:44:00 +0200 Subject: [core] add polyfill for codecvt for STLs that don't have it yet --- platform/default/codecvt/codecvt | 30 ++++++++++++++++++++++++++++++ platform/default/utf.cpp | 16 ++-------------- 2 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 platform/default/codecvt/codecvt (limited to 'platform/default') 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 +#include + +namespace std { + +template +class wstring_convert { +public: + static_assert(std::is_same::value, "type mismatch"); + + inline std::basic_string from_bytes(const string& str) { + return boost::locale::conv::utf_to_utf(str); + } + + inline string to_bytes(const std::basic_string& str) { + return boost::locale::conv::utf_to_utf(str); + } +}; + +template +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 -#include #include - -// GCC 4.9 compatibility -#if !defined(__GNUC__) || __GNUC__ >= 5 #include -#else -#include -#endif namespace mbgl { namespace util { -std::u16string utf8_to_utf16::convert(std::string const& utf8) { -#if !defined(__GNUC__) || __GNUC__ >= 5 - std::wstring_convert, char16_t> converter; - return converter.from_bytes(utf8); -#else - return boost::locale::conv::utf_to_utf(utf8.c_str(), utf8.c_str() + utf8.size()); -#endif +std::u16string utf8_to_utf16::convert(const std::string& utf8) { + return std::wstring_convert, char16_t>().from_bytes(utf8); } } // namespace util -- cgit v1.2.1