summaryrefslogtreecommitdiff
path: root/include/llmr/util/utf.hpp
diff options
context:
space:
mode:
authorDane Springmeyer <dane@mapbox.com>2014-05-28 19:57:01 -0700
committerDane Springmeyer <dane@mapbox.com>2014-05-28 19:57:01 -0700
commit5c46bef7176b6d8c784516eff6cc1915cf9b28a1 (patch)
tree9b94e13a6832bc94be6bcac0c53b0ca376469643 /include/llmr/util/utf.hpp
parentc85a0c3da2f296e8c78aa58a01e2bf83259a421d (diff)
downloadqtlocation-mapboxgl-5c46bef7176b6d8c784516eff6cc1915cf9b28a1.tar.gz
fallback to boost::locale on linux
Diffstat (limited to 'include/llmr/util/utf.hpp')
-rw-r--r--include/llmr/util/utf.hpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/include/llmr/util/utf.hpp b/include/llmr/util/utf.hpp
new file mode 100644
index 0000000000..fb9ab2048b
--- /dev/null
+++ b/include/llmr/util/utf.hpp
@@ -0,0 +1,44 @@
+#ifndef LLMR_UTIL_UTF
+#define LLMR_UTIL_UTF
+
+#include <memory>
+
+// g++/libstdc++ is missing c++11 codecvt support
+#ifdef __linux__
+#include <boost/locale.hpp>
+#else
+#include <codecvt>
+#endif
+
+namespace llmr {
+
+namespace util {
+
+#ifdef __linux__
+
+class utf8_to_utf32 {
+ public:
+ explicit utf8_to_utf32()
+ : utf32conv_() {}
+ std::u32string convert(std::string const& utf8) {
+ return boost::locale::conv::utf_to_utf<char32_t>(utf8)
+ }
+};
+#else
+
+class utf8_to_utf32 {
+ public:
+ explicit utf8_to_utf32()
+ : utf32conv_() {}
+ std::u32string convert(std::string const& utf8) {
+ return utf32conv_.from_bytes(utf8);
+ }
+ private:
+ std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv_;
+};
+
+#endif
+
+}}
+
+#endif