diff options
author | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-09-23 14:30:02 +0300 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-09-26 10:55:47 +0300 |
commit | 30ffbe9b8d49d8d8a2820f7b452ebc1d1531f298 (patch) | |
tree | 015177b4ed23075672df65e86a55675da94a6b79 /platform | |
parent | 7c2a7a263f9b3e90dd807ddd6d1dcbb783dec29b (diff) | |
download | qtlocation-mapboxgl-30ffbe9b8d49d8d8a2820f7b452ebc1d1531f298.tar.gz |
[core][android] Remove unaccent from platform interfaces
The unaccent is used only within collator, thus, there is no
need to have separate platform interface for it.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/core-files.json | 4 | ||||
-rw-r--r-- | platform/android/src/text/collator.cpp | 12 | ||||
-rw-r--r-- | platform/android/src/unaccent.cpp | 18 | ||||
-rw-r--r-- | platform/default/src/mbgl/text/collator.cpp | 43 | ||||
-rw-r--r-- | platform/default/src/mbgl/text/unaccent.cpp | 43 | ||||
-rw-r--r-- | platform/linux/config.cmake | 2 |
6 files changed, 45 insertions, 77 deletions
diff --git a/platform/android/core-files.json b/platform/android/core-files.json index 362098dd9b..9d502bf33e 100644 --- a/platform/android/core-files.json +++ b/platform/android/core-files.json @@ -86,7 +86,6 @@ "platform/android/src/gl_functions.cpp", "platform/android/src/thread.cpp", "platform/android/src/timer.cpp", - "platform/android/src/unaccent.cpp", "platform/default/src/mbgl/gfx/headless_backend.cpp", "platform/default/src/mbgl/gfx/headless_frontend.cpp", "platform/default/src/mbgl/gl/headless_backend.cpp", @@ -103,8 +102,7 @@ "mbgl/gfx/headless_backend.hpp": "platform/default/include/mbgl/gfx/headless_backend.hpp", "mbgl/gfx/headless_frontend.hpp": "platform/default/include/mbgl/gfx/headless_frontend.hpp", "mbgl/gl/headless_backend.hpp": "platform/default/include/mbgl/gl/headless_backend.hpp", - "mbgl/map/map_snapshotter.hpp": "platform/default/include/mbgl/map/map_snapshotter.hpp", - "mbgl/text/unaccent.hpp": "platform/default/include/mbgl/text/unaccent.hpp" + "mbgl/map/map_snapshotter.hpp": "platform/default/include/mbgl/map/map_snapshotter.hpp" }, "private_headers": { "android_renderer_backend.hpp": "platform/android/src/android_renderer_backend.hpp", diff --git a/platform/android/src/text/collator.cpp b/platform/android/src/text/collator.cpp index acb4f36ee1..1cd6f3cab0 100644 --- a/platform/android/src/text/collator.cpp +++ b/platform/android/src/text/collator.cpp @@ -2,8 +2,6 @@ #include <mbgl/text/language_tag.hpp> #include <mbgl/util/platform.hpp> -#include <mbgl/text/unaccent.hpp> - #include <jni/jni.hpp> #include "../attach_env.hpp" @@ -144,12 +142,10 @@ public: // Because of the difference in locale-awareness, this means turning on case-sensitivity // can _potentially_ change compare results for strings that don't actually have any case // differences. - jni::Local<jni::String> jlhs = jni::Make<jni::String>(*env, useUnaccent ? - platform::unaccent(lhs) : - lhs); - jni::Local<jni::String> jrhs = jni::Make<jni::String>(*env, useUnaccent ? - platform::unaccent(rhs) : - rhs); + jni::Local<jni::String> jlhs = useUnaccent ? android::StringUtils::unaccent(*env, jni::Make<jni::String>(*env, lhs)) + : jni::Make<jni::String>(*env, lhs); + jni::Local<jni::String> jrhs = useUnaccent ? android::StringUtils::unaccent(*env, jni::Make<jni::String>(*env, rhs)) + : jni::Make<jni::String>(*env, rhs); jni::jint result = android::Collator::compare(*env, collator, jlhs, jrhs); diff --git a/platform/android/src/unaccent.cpp b/platform/android/src/unaccent.cpp deleted file mode 100644 index 8da0ce4931..0000000000 --- a/platform/android/src/unaccent.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include <mbgl/text/unaccent.hpp> -#include <string> -#include "attach_env.hpp" -#include "text/collator_jni.hpp" -#include <jni/jni.hpp> - -namespace mbgl { -namespace platform { - -std::string unaccent(const std::string& str) { - android::UniqueEnv env = android::AttachEnv(); - jni::Local<jni::String> input = jni::Make<jni::String>(*env, str); - jni::Local<jni::String> unaccented = android::StringUtils::unaccent(*env, input); - return jni::Make<std::string>(*env, unaccented); -} - -} // namespace platform -} // namespace mbgl 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); } } diff --git a/platform/default/src/mbgl/text/unaccent.cpp b/platform/default/src/mbgl/text/unaccent.cpp deleted file mode 100644 index 37b9a0d9ca..0000000000 --- a/platform/default/src/mbgl/text/unaccent.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include <mbgl/util/platform.hpp> -#include <libnu/unaccent.h> -#include <mbgl/text/unaccent.hpp> - -#include <cstring> -#include <sstream> - -namespace mbgl { namespace platform { - -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 platform -} // namespace mbgl diff --git a/platform/linux/config.cmake b/platform/linux/config.cmake index 55e6e3c192..3a0fd91d36 100644 --- a/platform/linux/config.cmake +++ b/platform/linux/config.cmake @@ -54,8 +54,6 @@ macro(mbgl_platform_core) PRIVATE platform/default/src/mbgl/layermanager/layer_manager.cpp PRIVATE platform/default/src/mbgl/text/local_glyph_rasterizer.cpp PRIVATE platform/default/src/mbgl/util/thread_local.cpp - PRIVATE platform/default/src/mbgl/text/unaccent.cpp - PRIVATE platform/default/include/mbgl/text/unaccent.hpp PRIVATE platform/default/src/mbgl/util/utf.cpp PRIVATE platform/default/src/mbgl/util/format_number.cpp |