[core][android][darwin] Move platform specific Collator impls from expression
Platform specific Collator implementations should not be part of an expression APIs.
This commit is contained in:
24
include/mbgl/i18n/collator.hpp
Normal file
24
include/mbgl/i18n/collator.hpp
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/image.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
/*
|
||||
4
platform/android/src/jni_native.cpp
Executable file → Normal file
4
platform/android/src/jni_native.cpp
Executable file → Normal file
@@ -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 {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
#include "collator_jni.hpp"
|
||||
#include "../i18n/collator_jni.hpp"
|
||||
|
||||
/*
|
||||
android::NumberFormat is the JNI wrapper
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
24
src/mbgl/style/expression/collator.cpp
Normal file
24
src/mbgl/style/expression/collator.cpp
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user