diff options
-rw-r--r-- | include/mbgl/i18n/collator.hpp | 24 | ||||
-rw-r--r-- | include/mbgl/style/expression/collator.hpp | 6 | ||||
-rw-r--r-- | next/CMakeLists.txt | 1 | ||||
-rw-r--r-- | next/platform/android/android.cmake | 4 | ||||
-rw-r--r-- | next/platform/linux/linux.cmake | 2 | ||||
-rw-r--r-- | next/platform/qt/qt.cmake | 2 | ||||
-rw-r--r-- | platform/android/core-files.json | 4 | ||||
-rw-r--r-- | platform/android/src/i18n/collator.cpp (renamed from platform/android/src/text/collator.cpp) | 19 | ||||
-rw-r--r-- | platform/android/src/i18n/collator_jni.hpp (renamed from platform/android/src/text/collator_jni.hpp) | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | platform/android/src/jni_native.cpp | 4 | ||||
-rw-r--r-- | platform/android/src/text/format_number_jni.hpp | 2 | ||||
-rw-r--r-- | platform/darwin/src/collator.mm | 9 | ||||
-rw-r--r-- | platform/default/src/mbgl/i18n/collator.cpp (renamed from platform/default/src/mbgl/text/collator.cpp) | 55 | ||||
-rw-r--r-- | platform/linux/config.cmake | 2 | ||||
-rw-r--r-- | src/core-files.json | 1 | ||||
-rw-r--r-- | src/mbgl/style/expression/collator.cpp | 24 |
16 files changed, 94 insertions, 67 deletions
diff --git a/include/mbgl/i18n/collator.hpp b/include/mbgl/i18n/collator.hpp new file mode 100644 index 0000000000..9db1f804aa --- /dev/null +++ b/include/mbgl/i18n/collator.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include <mbgl/util/optional.hpp> + +#include <memory> +#include <string> + +namespace mbgl { +namespace platform { + +class Collator { +public: + explicit Collator(bool caseSensitive, bool diacriticSensitive, optional<std::string> locale = nullopt); + int compare(const std::string& lhs, const std::string& rhs) const; + std::string resolvedLocale() const; + bool operator==(const Collator& other) const; + +private: + class Impl; + std::shared_ptr<Impl> impl; +}; + +} // namespace platform +} // namespace mbgl diff --git a/include/mbgl/style/expression/collator.hpp b/include/mbgl/style/expression/collator.hpp index 2a79e55556..51ba426fad 100644 --- a/include/mbgl/style/expression/collator.hpp +++ b/include/mbgl/style/expression/collator.hpp @@ -1,10 +1,9 @@ #pragma once -#include <mbgl/util/feature.hpp> +#include <mbgl/i18n/collator.hpp> #include <mbgl/util/optional.hpp> #include <string> -#include <memory> namespace mbgl { namespace style { @@ -20,8 +19,7 @@ public: std::string resolvedLocale() const; private: - class Impl; - std::shared_ptr<Impl> impl; + platform::Collator collator; }; } // namespace expression diff --git a/next/CMakeLists.txt b/next/CMakeLists.txt index dae8ce09a1..bc15f04420 100644 --- a/next/CMakeLists.txt +++ b/next/CMakeLists.txt @@ -596,6 +596,7 @@ add_library( ${MBGL_ROOT}/src/mbgl/style/expression/check_subtype.cpp ${MBGL_ROOT}/src/mbgl/style/expression/coalesce.cpp ${MBGL_ROOT}/src/mbgl/style/expression/coercion.cpp + ${MBGL_ROOT}/src/mbgl/style/expression/collator.cpp ${MBGL_ROOT}/src/mbgl/style/expression/collator_expression.cpp ${MBGL_ROOT}/src/mbgl/style/expression/comparison.cpp ${MBGL_ROOT}/src/mbgl/style/expression/compound_expression.cpp diff --git a/next/platform/android/android.cmake b/next/platform/android/android.cmake index 240d4ccfdf..edc74576dc 100644 --- a/next/platform/android/android.cmake +++ b/next/platform/android/android.cmake @@ -187,8 +187,8 @@ target_sources( ${MBGL_ROOT}/platform/android/src/style/transition_options.hpp ${MBGL_ROOT}/platform/android/src/style/value.cpp ${MBGL_ROOT}/platform/android/src/style/value.hpp - ${MBGL_ROOT}/platform/android/src/text/collator.cpp - ${MBGL_ROOT}/platform/android/src/text/collator_jni.hpp + ${MBGL_ROOT}/platform/android/src/i18n/collator.cpp + ${MBGL_ROOT}/platform/android/src/i18n/collator_jni.hpp ${MBGL_ROOT}/platform/android/src/text/format_number.cpp ${MBGL_ROOT}/platform/android/src/text/format_number_jni.hpp ${MBGL_ROOT}/platform/android/src/text/local_glyph_rasterizer.cpp diff --git a/next/platform/linux/linux.cmake b/next/platform/linux/linux.cmake index 457ff441b8..993d3512e3 100644 --- a/next/platform/linux/linux.cmake +++ b/next/platform/linux/linux.cmake @@ -29,7 +29,7 @@ target_sources( ${MBGL_ROOT}/platform/default/src/mbgl/storage/online_file_source.cpp ${MBGL_ROOT}/platform/default/src/mbgl/storage/sqlite3.cpp ${MBGL_ROOT}/platform/default/src/mbgl/text/bidi.cpp - ${MBGL_ROOT}/platform/default/src/mbgl/text/collator.cpp + ${MBGL_ROOT}/platform/default/src/mbgl/i18n/collator.cpp ${MBGL_ROOT}/platform/default/src/mbgl/text/local_glyph_rasterizer.cpp ${MBGL_ROOT}/platform/default/src/mbgl/util/async_task.cpp ${MBGL_ROOT}/platform/default/src/mbgl/util/compression.cpp diff --git a/next/platform/qt/qt.cmake b/next/platform/qt/qt.cmake index 4d9275aaae..59aa00788f 100644 --- a/next/platform/qt/qt.cmake +++ b/next/platform/qt/qt.cmake @@ -29,6 +29,7 @@ target_sources( ${MBGL_ROOT}/platform/default/src/mbgl/gfx/headless_backend.cpp ${MBGL_ROOT}/platform/default/src/mbgl/gfx/headless_frontend.cpp ${MBGL_ROOT}/platform/default/src/mbgl/gl/headless_backend.cpp + ${MBGL_ROOT}/platform/default/src/mbgl/i18n/collator.cpp ${MBGL_ROOT}/platform/default/src/mbgl/layermanager/layer_manager.cpp ${MBGL_ROOT}/platform/default/src/mbgl/storage/asset_file_source.cpp ${MBGL_ROOT}/platform/default/src/mbgl/storage/default_file_source.cpp @@ -41,7 +42,6 @@ target_sources( ${MBGL_ROOT}/platform/default/src/mbgl/storage/offline_download.cpp ${MBGL_ROOT}/platform/default/src/mbgl/storage/online_file_source.cpp ${MBGL_ROOT}/platform/default/src/mbgl/storage/sqlite3.cpp - ${MBGL_ROOT}/platform/default/src/mbgl/text/collator.cpp ${MBGL_ROOT}/platform/default/src/mbgl/util/compression.cpp ${MBGL_ROOT}/platform/qt/src/async_task.cpp ${MBGL_ROOT}/platform/qt/src/async_task_impl.hpp diff --git a/platform/android/core-files.json b/platform/android/core-files.json index 9d502bf33e..4057b21000 100644 --- a/platform/android/core-files.json +++ b/platform/android/core-files.json @@ -80,7 +80,7 @@ "platform/android/src/style/sources/vector_source.cpp", "platform/android/src/style/transition_options.cpp", "platform/android/src/style/value.cpp", - "platform/android/src/text/collator.cpp", + "platform/android/src/i18n/collator.cpp", "platform/android/src/text/local_glyph_rasterizer.cpp", "platform/android/src/text/format_number.cpp", "platform/android/src/gl_functions.cpp", @@ -185,7 +185,7 @@ "style/sources/vector_source.hpp": "platform/android/src/style/sources/vector_source.hpp", "style/transition_options.hpp": "platform/android/src/style/transition_options.hpp", "style/value.hpp": "platform/android/src/style/value.hpp", - "text/collator_jni.hpp": "platform/android/src/text/collator_jni.hpp", + "text/collator_jni.hpp": "platform/android/src/i18n/collator_jni.hpp", "text/local_glyph_rasterizer_jni.hpp": "platform/android/src/text/local_glyph_rasterizer_jni.hpp" } } diff --git a/platform/android/src/text/collator.cpp b/platform/android/src/i18n/collator.cpp index 1cd6f3cab0..b3dd8e21b3 100644 --- a/platform/android/src/text/collator.cpp +++ b/platform/android/src/i18n/collator.cpp @@ -1,6 +1,5 @@ -#include <mbgl/style/expression/collator.hpp> +#include <mbgl/i18n/collator.hpp> #include <mbgl/text/language_tag.hpp> -#include <mbgl/util/platform.hpp> #include <jni/jni.hpp> @@ -94,8 +93,7 @@ jni::Local<jni::Object<Locale>> Locale::New(jni::JNIEnv& env, const jni::String& } // namespace android -namespace style { -namespace expression { +namespace platform { class Collator::Impl { public: @@ -142,10 +140,12 @@ 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 = 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::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); @@ -190,6 +190,5 @@ std::string Collator::resolvedLocale() const { return impl->resolvedLocale(); } -} // namespace expression -} // namespace style +} // namespace platform } // namespace mbgl diff --git a/platform/android/src/text/collator_jni.hpp b/platform/android/src/i18n/collator_jni.hpp index dd3f845662..612f9b49f3 100644 --- a/platform/android/src/text/collator_jni.hpp +++ b/platform/android/src/i18n/collator_jni.hpp @@ -1,7 +1,5 @@ #pragma once -#include <mbgl/util/image.hpp> - #include <jni/jni.hpp> /* diff --git a/platform/android/src/jni_native.cpp b/platform/android/src/jni_native.cpp index df96ba9759..966dc6a007 100755..100644 --- a/platform/android/src/jni_native.cpp +++ b/platform/android/src/jni_native.cpp @@ -50,10 +50,10 @@ #include "snapshotter/map_snapshotter.hpp" #include "snapshotter/map_snapshot.hpp" #endif -#include "text/collator_jni.hpp" +#include "i18n/collator_jni.hpp" +#include "logger.hpp" #include "text/local_glyph_rasterizer_jni.hpp" #include "text/format_number_jni.hpp" -#include "logger.hpp" namespace mbgl { namespace android { diff --git a/platform/android/src/text/format_number_jni.hpp b/platform/android/src/text/format_number_jni.hpp index 1720038925..1b63012c6e 100644 --- a/platform/android/src/text/format_number_jni.hpp +++ b/platform/android/src/text/format_number_jni.hpp @@ -2,7 +2,7 @@ #include <jni/jni.hpp> -#include "collator_jni.hpp" +#include "../i18n/collator_jni.hpp" /* android::NumberFormat is the JNI wrapper diff --git a/platform/darwin/src/collator.mm b/platform/darwin/src/collator.mm index fe2b46ffa7..0f010c1df8 100644 --- a/platform/darwin/src/collator.mm +++ b/platform/darwin/src/collator.mm @@ -1,12 +1,11 @@ -#include <mbgl/style/expression/collator.hpp> +#include <mbgl/i18n/collator.hpp> #include <sstream> #import <Foundation/Foundation.h> namespace mbgl { -namespace style { -namespace expression { +namespace platform { class Collator::Impl { public: @@ -48,7 +47,6 @@ private: NSLocale* locale; }; - Collator::Collator(bool caseSensitive, bool diacriticSensitive, optional<std::string> locale_) : impl(std::make_shared<Impl>(caseSensitive, diacriticSensitive, std::move(locale_))) {} @@ -65,6 +63,5 @@ std::string Collator::resolvedLocale() const { return impl->resolvedLocale(); } -} // namespace expression -} // namespace style +} // namespace platform } // namespace mbgl diff --git a/platform/default/src/mbgl/text/collator.cpp b/platform/default/src/mbgl/i18n/collator.cpp index 2d85b2d466..f46accff8a 100644 --- a/platform/default/src/mbgl/text/collator.cpp +++ b/platform/default/src/mbgl/i18n/collator.cpp @@ -1,7 +1,6 @@ -#include <mbgl/style/expression/collator.hpp> -#include <mbgl/util/platform.hpp> #include <libnu/strcoll.h> #include <libnu/unaccent.h> +#include <mbgl/i18n/collator.hpp> #include <cstring> #include <sstream> @@ -20,31 +19,24 @@ */ namespace { -std::string unaccent(const std::string& str) -{ +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 }; + char const* end = itr + str.length(); + char lo[5] = {0}; - for (; itr < end; itr = nitr) - { + 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 - { + 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 - { + } while (code_point != 0); + } else { output.write(itr, nitr - itr); } } @@ -54,8 +46,7 @@ std::string unaccent(const std::string& str) } // namespace namespace mbgl { -namespace style { -namespace expression { +namespace platform { class Collator::Impl { public: @@ -65,8 +56,7 @@ public: {} bool operator==(const Impl& other) const { - return caseSensitive == other.caseSensitive && - diacriticSensitive == other.diacriticSensitive; + return caseSensitive == other.caseSensitive && diacriticSensitive == other.diacriticSensitive; } int compare(const std::string& lhs, const std::string& rhs) const { @@ -77,40 +67,35 @@ public: return nu_strcasecoll(lhs.c_str(), rhs.c_str(), nu_utf8_read, nu_utf8_read); } else if (caseSensitive && !diacriticSensitive) { - return nu_strcoll(unaccent(lhs).c_str(), unaccent(rhs).c_str(), - nu_utf8_read, nu_utf8_read); + return nu_strcoll(unaccent(lhs).c_str(), unaccent(rhs).c_str(), nu_utf8_read, nu_utf8_read); } else { - return nu_strcasecoll(unaccent(lhs).c_str(), unaccent(rhs).c_str(), - nu_utf8_read, nu_utf8_read); + return nu_strcasecoll(unaccent(lhs).c_str(), unaccent(rhs).c_str(), nu_utf8_read, nu_utf8_read); } } std::string resolvedLocale() const { return ""; } + private: bool caseSensitive; bool diacriticSensitive; }; - -Collator::Collator(bool caseSensitive, bool diacriticSensitive, optional<std::string> locale_) - : impl(std::make_shared<Impl>(caseSensitive, diacriticSensitive, std::move(locale_))) -{} +int Collator::compare(const std::string& lhs, const std::string& rhs) const { + return impl->compare(lhs, rhs); +} bool Collator::operator==(const Collator& other) const { return *impl == *(other.impl); } -int Collator::compare(const std::string& lhs, const std::string& rhs) const { - return impl->compare(lhs, rhs); -} - std::string Collator::resolvedLocale() const { return impl->resolvedLocale(); } +Collator::Collator(bool caseSensitive, bool diacriticSensitive, optional<std::string> locale) + : impl(std::make_shared<Impl>(caseSensitive, diacriticSensitive, std::move(locale))) {} -} // namespace expression -} // namespace style +} // namespace platform } // namespace mbgl diff --git a/platform/linux/config.cmake b/platform/linux/config.cmake index 3a0fd91d36..01c46c9fcb 100644 --- a/platform/linux/config.cmake +++ b/platform/linux/config.cmake @@ -50,7 +50,7 @@ macro(mbgl_platform_core) PRIVATE platform/default/src/mbgl/util/string_stdlib.cpp PRIVATE platform/default/src/mbgl/util/thread.cpp PRIVATE platform/default/src/mbgl/text/bidi.cpp - PRIVATE platform/default/src/mbgl/text/collator.cpp + PRIVATE platform/default/src/mbgl/i18n/collator.cpp 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 diff --git a/src/core-files.json b/src/core-files.json index d881e6259d..2f609e92ec 100644 --- a/src/core-files.json +++ b/src/core-files.json @@ -178,6 +178,7 @@ "src/mbgl/style/expression/check_subtype.cpp", "src/mbgl/style/expression/coalesce.cpp", "src/mbgl/style/expression/coercion.cpp", + "src/mbgl/style/expression/collator.cpp", "src/mbgl/style/expression/collator_expression.cpp", "src/mbgl/style/expression/comparison.cpp", "src/mbgl/style/expression/compound_expression.cpp", diff --git a/src/mbgl/style/expression/collator.cpp b/src/mbgl/style/expression/collator.cpp new file mode 100644 index 0000000000..185d713150 --- /dev/null +++ b/src/mbgl/style/expression/collator.cpp @@ -0,0 +1,24 @@ +#include <mbgl/style/expression/collator.hpp> + +namespace mbgl { +namespace style { +namespace expression { + +Collator::Collator(bool caseSensitive, bool diacriticSensitive, optional<std::string> locale) + : collator(platform::Collator(caseSensitive, diacriticSensitive, std::move(locale))) {} + +bool Collator::operator==(const Collator& other) const { + return collator == other.collator; +} + +int Collator::compare(const std::string& lhs, const std::string& rhs) const { + return collator.compare(lhs, rhs); +} + +std::string Collator::resolvedLocale() const { + return collator.resolvedLocale(); +} + +} // namespace expression +} // namespace style +} // namespace mbgl |