diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2018-10-18 17:33:27 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2018-10-23 12:23:40 +0200 |
commit | 282c71e8e9a8ec9c2eab612f2e60a71b15d24c8a (patch) | |
tree | 2d5a7d0f9b054af2686fe94dfa8c5690e8c92e72 | |
parent | 729eeeb3f821981cc5d3c9e06ffbb85ed4d857d7 (diff) | |
download | qtlocation-mapboxgl-282c71e8e9a8ec9c2eab612f2e60a71b15d24c8a.tar.gz |
[core] unify UTF-8/16 conversion to <boost/locale/encoding_utf.hpp>
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | cmake/codecvt.cmake | 19 | ||||
-rw-r--r-- | cmake/core.cmake | 2 | ||||
-rw-r--r-- | cmake/mason-dependencies.cmake | 2 | ||||
-rw-r--r-- | platform/android/config.cmake | 7 | ||||
-rw-r--r-- | platform/default/codecvt/codecvt | 30 | ||||
-rw-r--r-- | platform/default/jni/string_conversion.hpp | 17 | ||||
-rw-r--r-- | platform/default/utf.cpp | 11 | ||||
-rw-r--r-- | platform/qt/src/utf.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/layout/symbol_layout.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/util/i18n.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/util/utf.hpp | 6 |
12 files changed, 34 insertions, 68 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b37a69a83e..bb315916b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,8 +142,6 @@ else() message(STATUS "Can't find ccache — consider installing ccache to improve recompilation performance") endif() -include(cmake/codecvt.cmake) - if(NOT EXISTS ${CMAKE_SOURCE_DIR}/platform/${MBGL_PLATFORM}/config.cmake) message(ERROR "Can't find config.cmake file for platform ${MBGL_PLATFORM}") endif() diff --git a/cmake/codecvt.cmake b/cmake/codecvt.cmake deleted file mode 100644 index 8228a6df6b..0000000000 --- a/cmake/codecvt.cmake +++ /dev/null @@ -1,19 +0,0 @@ -add_library(codecvt INTERFACE) - -# Determine if the STL has codecvt -file(WRITE "${CMAKE_BINARY_DIR}/features/codecvt/main.cpp" "#include <codecvt>\nint main() {}") -try_compile(STL_SUPPORTS_CODECVT - "${CMAKE_BINARY_DIR}/features/codecvt" - SOURCES "${CMAKE_BINARY_DIR}/features/codecvt/main.cpp" - CMAKE_FLAGS "-DCMAKE_MACOSX_BUNDLE:STRING=YES" "-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED:STRING=NO" - COMPILE_DEFINITIONS "-std=c++14" # CXX_STANDARD wasn't added to try_compile until CMake 3.8 - OUTPUT_VARIABLE CODECVT_TEST_OUTPUT -) - -if (NOT STL_SUPPORTS_CODECVT) - if ($ENV{V}) - message("codecvt support not detected: ${CODECVT_TEST_OUTPUT}") - endif() - target_include_directories(codecvt INTERFACE platform/default/codecvt) - target_add_mason_package(codecvt INTERFACE boost) -endif() diff --git a/cmake/core.cmake b/cmake/core.cmake index 1b29b4fb08..32e77f5d55 100644 --- a/cmake/core.cmake +++ b/cmake/core.cmake @@ -7,8 +7,6 @@ target_include_directories(mbgl-core PRIVATE src ) -target_link_libraries(mbgl-core PRIVATE codecvt) - target_add_mason_package(mbgl-core PUBLIC geometry) target_add_mason_package(mbgl-core PUBLIC variant) target_add_mason_package(mbgl-core PRIVATE unique_resource) diff --git a/cmake/mason-dependencies.cmake b/cmake/mason-dependencies.cmake index 160060a6fa..79d343ac8b 100644 --- a/cmake/mason-dependencies.cmake +++ b/cmake/mason-dependencies.cmake @@ -19,7 +19,7 @@ mason_use(cheap-ruler VERSION 2.5.3 HEADER_ONLY) mason_use(vector-tile VERSION 1.0.2 HEADER_ONLY) if(MBGL_PLATFORM STREQUAL "android") - mason_use(jni.hpp VERSION 4.0.0 HEADER_ONLY) + mason_use(jni.hpp VERSION 4.0.1 HEADER_ONLY) elseif(MBGL_PLATFORM STREQUAL "ios") # noop elseif(MBGL_PLATFORM STREQUAL "linux") diff --git a/platform/android/config.cmake b/platform/android/config.cmake index cc44c2585c..ec64b239f8 100644 --- a/platform/android/config.cmake +++ b/platform/android/config.cmake @@ -69,7 +69,6 @@ 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 @@ -84,8 +83,11 @@ add_library(mapbox-gl SHARED platform/android/src/main.cpp ) +target_include_directories(mapbox-gl + PRIVATE src +) + target_link_libraries(mapbox-gl - PRIVATE codecvt PRIVATE mbgl-core PRIVATE mbgl-filesource ) @@ -106,7 +108,6 @@ 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 deleted file mode 100644 index 8d21e82348..0000000000 --- a/platform/default/codecvt/codecvt +++ /dev/null @@ -1,30 +0,0 @@ -#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/jni/string_conversion.hpp b/platform/default/jni/string_conversion.hpp new file mode 100644 index 0000000000..66df539f4e --- /dev/null +++ b/platform/default/jni/string_conversion.hpp @@ -0,0 +1,17 @@ +#pragma once + +// This file replaces the default implementation in jni.hpp. + +#include <mbgl/util/utf.hpp> + +namespace jni { + +inline std::u16string convertUTF8ToUTF16(const std::string& str) { + return mbgl::util::convertUTF8ToUTF16(str); +} + +inline std::string convertUTF16ToUTF8(const std::u16string& str) { + return mbgl::util::convertUTF16ToUTF8(str); +} + +} // namespace jni diff --git a/platform/default/utf.cpp b/platform/default/utf.cpp index 8bc8ea7314..f0f9d3e67a 100644 --- a/platform/default/utf.cpp +++ b/platform/default/utf.cpp @@ -1,13 +1,16 @@ #include <mbgl/util/utf.hpp> -#include <locale> -#include <codecvt> +#include <boost/locale/encoding_utf.hpp> namespace mbgl { namespace util { -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); +std::u16string convertUTF8ToUTF16(const std::string& str) { + return boost::locale::conv::utf_to_utf<char16_t>(str); +} + +std::string convertUTF16ToUTF8(const std::u16string& str) { + return boost::locale::conv::utf_to_utf<char>(str); } } // namespace util diff --git a/platform/qt/src/utf.cpp b/platform/qt/src/utf.cpp index d8bf2ca0b3..069c7bca39 100644 --- a/platform/qt/src/utf.cpp +++ b/platform/qt/src/utf.cpp @@ -5,7 +5,7 @@ namespace mbgl { namespace util { -std::u16string utf8_to_utf16::convert(std::string const& utf8) { +std::u16string convertUTF8ToUTF16(std::string const& utf8) { auto utf16 = QString::fromUtf8(utf8.data(), utf8.length()); // Newers Qt have QString::toStdU16String(), but this is how it is diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index f7b6d949bd..6d20afeb8d 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -123,7 +123,7 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters, u8string = platform::lowercase(u8string); } - ft.formattedText->addSection(applyArabicShaping(util::utf8_to_utf16::convert(u8string)), + ft.formattedText->addSection(applyArabicShaping(util::convertUTF8ToUTF16(u8string)), section.fontScale ? *section.fontScale : 1.0, section.fontStack ? FontStackHasher()(*section.fontStack) : baseFontStackHash); diff --git a/src/mbgl/util/i18n.cpp b/src/mbgl/util/i18n.cpp index 66c9e027a7..d9b0c20796 100644 --- a/src/mbgl/util/i18n.cpp +++ b/src/mbgl/util/i18n.cpp @@ -609,7 +609,7 @@ bool charInSupportedScript(char16_t chr) { } bool isStringInSupportedScript(const std::string& input) { - auto u16string = util::utf8_to_utf16::convert(input); + auto u16string = util::convertUTF8ToUTF16(input); for (char16_t chr : u16string) { if (!charInSupportedScript(chr)) { return false; diff --git a/src/mbgl/util/utf.hpp b/src/mbgl/util/utf.hpp index c13b094371..d870fb9331 100644 --- a/src/mbgl/util/utf.hpp +++ b/src/mbgl/util/utf.hpp @@ -5,10 +5,8 @@ namespace mbgl { namespace util { -class utf8_to_utf16 { -public: - static std::u16string convert(std::string const&); -}; +std::u16string convertUTF8ToUTF16(const std::string&); +std::string convertUTF16ToUTF8(const std::u16string&); } // namespace util } // namespace mbgl |