diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-12-20 15:06:56 -0200 |
---|---|---|
committer | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2017-01-20 18:50:45 +0100 |
commit | 181b3635f17101672c05af3e0800d7841fd259e8 (patch) | |
tree | c24b830459b7ac11c844c1d369a99579685d9ebb /platform/qt | |
parent | cbf28083e61a1bda85765db610ae93291d077086 (diff) | |
download | qtlocation-mapboxgl-181b3635f17101672c05af3e0800d7841fd259e8.tar.gz |
[core][Qt] Use Qt for UTF16, since `codecvt` is not always available
Diffstat (limited to 'platform/qt')
-rw-r--r-- | platform/qt/qt.cmake | 1 | ||||
-rw-r--r-- | platform/qt/src/utf.cpp | 17 |
2 files changed, 18 insertions, 0 deletions
diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index 3382a9ac6b..bd7c863f98 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -48,6 +48,7 @@ set(MBGL_QT_FILES PRIVATE platform/qt/src/string_stdlib.cpp PRIVATE platform/qt/src/timer.cpp PRIVATE platform/qt/src/timer_impl.hpp + PRIVATE platform/qt/src/utf.cpp ) include_directories( diff --git a/platform/qt/src/utf.cpp b/platform/qt/src/utf.cpp new file mode 100644 index 0000000000..d8bf2ca0b3 --- /dev/null +++ b/platform/qt/src/utf.cpp @@ -0,0 +1,17 @@ +#include <mbgl/util/utf.hpp> + +#include <QString> + +namespace mbgl { +namespace util { + +std::u16string utf8_to_utf16::convert(std::string const& utf8) { + auto utf16 = QString::fromUtf8(utf8.data(), utf8.length()); + + // Newers Qt have QString::toStdU16String(), but this is how it is + // implemented. Do it here to keep compatibility with older versions. + return std::u16string(reinterpret_cast<const char16_t*>(utf16.utf16()), utf16.length()); +} + +} // namespace util +} // namespace mbgl |