diff options
author | Dane Springmeyer <dane@mapbox.com> | 2014-05-28 19:57:01 -0700 |
---|---|---|
committer | Dane Springmeyer <dane@mapbox.com> | 2014-05-28 19:57:01 -0700 |
commit | 5c46bef7176b6d8c784516eff6cc1915cf9b28a1 (patch) | |
tree | 9b94e13a6832bc94be6bcac0c53b0ca376469643 | |
parent | c85a0c3da2f296e8c78aa58a01e2bf83259a421d (diff) | |
download | qtlocation-mapboxgl-5c46bef7176b6d8c784516eff6cc1915cf9b28a1.tar.gz |
fallback to boost::locale on linux
-rw-r--r-- | include/llmr/util/utf.hpp | 44 | ||||
-rw-r--r-- | src/map/tile_parser.cpp | 11 |
2 files changed, 48 insertions, 7 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 diff --git a/src/map/tile_parser.cpp b/src/map/tile_parser.cpp index 7d83239609..70085b309c 100644 --- a/src/map/tile_parser.cpp +++ b/src/map/tile_parser.cpp @@ -12,8 +12,7 @@ #include <llmr/text/glyph_store.hpp> #include <llmr/util/std.hpp> - -#include <codecvt> +#include <llmr/util/utf.hpp> using namespace llmr; @@ -172,9 +171,7 @@ std::unique_ptr<Bucket> TileParser::createTextBucket(const VectorTileLayer& laye std::unique_ptr<TextBucket> bucket = std::make_unique<TextBucket>( tile.textVertexBuffer, tile.triangleElementsBuffer, bucket_desc, placement); - - std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> ucs4conv; - + util::utf8_to_utf32 ucs4conv; // Determine and load glyph ranges { @@ -194,7 +191,7 @@ std::unique_ptr<Bucket> TileParser::createTextBucket(const VectorTileLayer& laye continue; } - const std::u32string string = ucs4conv.from_bytes(toString(it_prop->second)); + const std::u32string string = ucs4conv.convert(toString(it_prop->second)); // Loop through all characters of this text and collect unique codepoints. for (uint32_t chr : string) { @@ -224,7 +221,7 @@ std::unique_ptr<Bucket> TileParser::createTextBucket(const VectorTileLayer& laye continue; } - const std::u32string string = ucs4conv.from_bytes(toString(it_prop->second)); + const std::u32string string = ucs4conv.convert(toString(it_prop->second)); // TODO: Shape label // TODO: Place label |