summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2017-03-01 17:01:22 -0800
committerBruno de Oliveira Abinader <bruno@mapbox.com>2017-03-02 11:40:03 -0800
commitc2bb0b4911505c7a1a5a78c02d3785856f42ee99 (patch)
tree44be7cb71d3a1b009cac92466cebd4af510d2164 /include
parent8108e1b59cdc97d6ad191acf9e084b8292069a11 (diff)
downloadqtlocation-mapboxgl-c2bb0b4911505c7a1a5a78c02d3785856f42ee99.tar.gz
[core] Safeguard ICU UChar usage
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/util/traits.hpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/mbgl/util/traits.hpp b/include/mbgl/util/traits.hpp
index 9d6f947cd2..5b9401aad7 100644
--- a/include/mbgl/util/traits.hpp
+++ b/include/mbgl/util/traits.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <cstdint>
#include <type_traits>
namespace mbgl {
@@ -9,4 +10,19 @@ constexpr auto underlying_type(T t) -> typename std::underlying_type_t<T> {
return typename std::underlying_type_t<T>(t);
}
+template <typename T> struct is_utf16char_like: std::false_type {};
+template <typename T> struct is_utf16char_like<const T>: is_utf16char_like<T> {};
+template <> struct is_utf16char_like<char16_t>: std::true_type {};
+template <> struct is_utf16char_like<wchar_t>: std::true_type {};
+template <> struct is_utf16char_like<uint16_t>: std::true_type {};
+
+template <typename T> using is_utf16char_like_pointer = std::integral_constant<bool, std::is_pointer<T>::value
+ && is_utf16char_like<typename std::remove_pointer<T>::type>::value>;
+
+template <class OutPointer, class InChar>
+typename std::enable_if<is_utf16char_like<InChar>::value && is_utf16char_like_pointer<OutPointer>::value, OutPointer>::type utf16char_cast(InChar *in)
+{
+ return reinterpret_cast<OutPointer>(in);
+}
+
} // namespace mbgl