summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/darwin/src/collator.mm64
-rw-r--r--platform/ios/config.cmake1
-rw-r--r--platform/macos/config.cmake1
3 files changed, 66 insertions, 0 deletions
diff --git a/platform/darwin/src/collator.mm b/platform/darwin/src/collator.mm
new file mode 100644
index 0000000000..5a87ab3c9a
--- /dev/null
+++ b/platform/darwin/src/collator.mm
@@ -0,0 +1,64 @@
+#include <mbgl/style/expression/collator.hpp>
+
+#include <sstream>
+
+#import <Foundation/Foundation.h>
+
+namespace mbgl {
+namespace style {
+namespace expression {
+
+class Collator::Impl {
+public:
+ Impl(bool caseSensitive, bool diacriticSensitive, optional<std::string> locale_)
+ : options((caseSensitive ? 0 : NSCaseInsensitiveSearch) |
+ (diacriticSensitive ? 0 : NSDiacriticInsensitiveSearch))
+ , locale(locale_ ?
+ [[NSLocale alloc] initWithLocaleIdentifier:@((*locale_).c_str())] :
+ [NSLocale currentLocale])
+ {}
+
+ bool operator==(const Impl& other) const {
+ return options == other.options &&
+ [[locale localeIdentifier] isEqualToString:[other.locale localeIdentifier]];
+ }
+
+ int compare(const std::string& lhs, const std::string& rhs) const {
+ NSString* nsLhs = @(lhs.c_str());
+ NSString* nsRhs = @(rhs.c_str());
+ // Limiting the compare range to the length of the LHS seems weird, but
+ // experimentally we've checked that if LHS is a prefix of RHS compare returns -1
+ // https://developer.apple.com/documentation/foundation/nsstring/1414561-compare
+ NSRange compareRange = NSMakeRange(0, nsLhs.length);
+
+ return [nsLhs compare:nsRhs options:options range:compareRange locale:locale];
+ }
+
+ std::string resolvedLocale() const {
+ return [locale localeIdentifier].UTF8String;
+ }
+private:
+ NSStringCompareOptions options;
+ NSLocale* locale;
+};
+
+
+Collator::Collator(bool caseSensitive, bool diacriticSensitive, optional<std::string> locale_)
+ : impl(std::make_shared<Impl>(caseSensitive, diacriticSensitive, std::move(locale_)))
+{}
+
+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();
+}
+
+} // namespace expression
+} // namespace style
+} // namespace mbgl
diff --git a/platform/ios/config.cmake b/platform/ios/config.cmake
index 8c1d12e6f2..a607fbdf35 100644
--- a/platform/ios/config.cmake
+++ b/platform/ios/config.cmake
@@ -29,6 +29,7 @@ macro(mbgl_platform_core)
PRIVATE platform/darwin/mbgl/storage/reachability.h
PRIVATE platform/darwin/mbgl/storage/reachability.m
PRIVATE platform/darwin/src/CFHandle.hpp
+ PRIVATE platform/darwin/src/collator.mm
PRIVATE platform/darwin/src/local_glyph_rasterizer.mm
PRIVATE platform/darwin/src/logging_nslog.mm
PRIVATE platform/darwin/src/nsthread.mm
diff --git a/platform/macos/config.cmake b/platform/macos/config.cmake
index 23012c6dcf..20ac7bc242 100644
--- a/platform/macos/config.cmake
+++ b/platform/macos/config.cmake
@@ -14,6 +14,7 @@ macro(mbgl_platform_core)
PRIVATE platform/darwin/mbgl/storage/reachability.h
PRIVATE platform/darwin/mbgl/storage/reachability.m
PRIVATE platform/darwin/src/CFHandle.hpp
+ PRIVATE platform/darwin/src/collator.mm
PRIVATE platform/darwin/src/local_glyph_rasterizer.mm
PRIVATE platform/darwin/src/logging_nslog.mm
PRIVATE platform/darwin/src/nsthread.mm