From 5c46bef7176b6d8c784516eff6cc1915cf9b28a1 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 28 May 2014 19:57:01 -0700 Subject: fallback to boost::locale on linux --- include/llmr/util/utf.hpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 include/llmr/util/utf.hpp (limited to 'include/llmr/util/utf.hpp') 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 + +// g++/libstdc++ is missing c++11 codecvt support +#ifdef __linux__ +#include +#else +#include +#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(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, char32_t> utf32conv_; +}; + +#endif + +}} + +#endif -- cgit v1.2.1