diff options
Diffstat (limited to 'platform/default/src/mbgl/text/collator.cpp')
-rw-r--r-- | platform/default/src/mbgl/text/collator.cpp | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/platform/default/src/mbgl/text/collator.cpp b/platform/default/src/mbgl/text/collator.cpp index 400fa4d94d..2d85b2d466 100644 --- a/platform/default/src/mbgl/text/collator.cpp +++ b/platform/default/src/mbgl/text/collator.cpp @@ -1,7 +1,10 @@ #include <mbgl/style/expression/collator.hpp> #include <mbgl/util/platform.hpp> #include <libnu/strcoll.h> -#include <mbgl/text/unaccent.hpp> +#include <libnu/unaccent.h> + +#include <cstring> +#include <sstream> /* The default implementation of Collator ignores locale. @@ -16,6 +19,40 @@ but would require bundling locale data. */ +namespace { +std::string unaccent(const std::string& str) +{ + std::stringstream output; + char const *itr = str.c_str(), *nitr; + char const *end = itr + str.length(); + char lo[5] = { 0 }; + + for (; itr < end; itr = nitr) + { + uint32_t code_point = 0; + char const* buf = nullptr; + + nitr = _nu_tounaccent(itr, end, nu_utf8_read, &code_point, &buf, nullptr); + if (buf != nullptr) + { + do + { + buf = NU_CASEMAP_DECODING_FUNCTION(buf, &code_point); + if (code_point == 0) break; + output.write(lo, nu_utf8_write(code_point, lo) - lo); + } + while (code_point != 0); + } + else + { + output.write(itr, nitr - itr); + } + } + + return output.str(); +} +} // namespace + namespace mbgl { namespace style { namespace expression { @@ -40,10 +77,10 @@ public: return nu_strcasecoll(lhs.c_str(), rhs.c_str(), nu_utf8_read, nu_utf8_read); } else if (caseSensitive && !diacriticSensitive) { - return nu_strcoll(platform::unaccent(lhs).c_str(), platform::unaccent(rhs).c_str(), + return nu_strcoll(unaccent(lhs).c_str(), unaccent(rhs).c_str(), nu_utf8_read, nu_utf8_read); } else { - return nu_strcasecoll(platform::unaccent(lhs).c_str(), platform::unaccent(rhs).c_str(), + return nu_strcasecoll(unaccent(lhs).c_str(), unaccent(rhs).c_str(), nu_utf8_read, nu_utf8_read); } } |