From 6610a6370b9702d6dbd107716d5df3227be42e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Fri, 22 Aug 2014 12:37:23 +0200 Subject: [PATCH 1/4] use platform-specific NSString for case changes on OS X/iOS refs #309 --- common/platform_default.cpp | 25 +++++++++++++++++++++++++ common/platform_nsstring.mm | 21 +++++++++++++++++++++ include/mbgl/platform/platform.hpp | 6 ++++++ ios/mapbox-gl-cocoa | 2 +- linux/mapboxgl-app.gyp | 1 + macosx/mapboxgl-app.gyp | 1 + src/renderer/symbol_bucket.cpp | 5 ++--- 7 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 common/platform_default.cpp create mode 100644 common/platform_nsstring.mm diff --git a/common/platform_default.cpp b/common/platform_default.cpp new file mode 100644 index 000000000..1acbfa850 --- /dev/null +++ b/common/platform_default.cpp @@ -0,0 +1,25 @@ +#include + +#include + +namespace mbgl { +namespace platform { + +std::string uppercase(const std::string& string) { + // TODO: Use a proper Unicode Special Casing-aware algorithm. + const auto &convert = std::use_facet>(std::locale()); + std::string converted = string; + convert.toupper(&converted[0], &converted[0] + converted.size()); + return converted; +} + +std::string lowercase(const std::string& string) { + // TODO: Use a proper Unicode Special Casing-aware algorithm. + const auto &convert = std::use_facet>(std::locale()); + std::string converted = string; + convert.tolower(&converted[0], &converted[0] + converted.size()); + return converted; +} + +} +} diff --git a/common/platform_nsstring.mm b/common/platform_nsstring.mm new file mode 100644 index 000000000..9119f2a8f --- /dev/null +++ b/common/platform_nsstring.mm @@ -0,0 +1,21 @@ +#import + +#include + +namespace mbgl { +namespace platform { + +std::string uppercase(const std::string &string) { + NSString *nsstring = [[NSString alloc] initWithBytesNoCopy:const_cast(string.data()) length:string.size() encoding:NSUTF8StringEncoding freeWhenDone:NO]; + nsstring = [nsstring uppercaseString]; + return { [nsstring cStringUsingEncoding:NSUTF8StringEncoding], [nsstring lengthOfBytesUsingEncoding:NSUTF8StringEncoding] }; +} + +std::string lowercase(const std::string &string) { + NSString *nsstring = [[NSString alloc] initWithBytesNoCopy:const_cast(string.data()) length:string.size() encoding:NSUTF8StringEncoding freeWhenDone:NO]; + nsstring = [nsstring lowercaseString]; + return { [nsstring cStringUsingEncoding:NSUTF8StringEncoding], [nsstring lengthOfBytesUsingEncoding:NSUTF8StringEncoding] }; +} + +} +} \ No newline at end of file diff --git a/include/mbgl/platform/platform.hpp b/include/mbgl/platform/platform.hpp index 43c6ce4f5..22405a4cf 100644 --- a/include/mbgl/platform/platform.hpp +++ b/include/mbgl/platform/platform.hpp @@ -28,6 +28,12 @@ std::shared_ptr request_http(const std::string &url, std::function callback, std::shared_ptr loop = nullptr); +// Uppercase a string, potentially using platform-specific routines. +std::string uppercase(const std::string &string); + +// Lowercase a string, potentially using platform-specific routines. +std::string lowercase(const std::string &string); + // Cancels an HTTP request. void cancel_request_http(const std::shared_ptr &req); diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa index e1c709a8d..9631c7d6d 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit e1c709a8de0b69aa6bfbcd9ea4faf981b6e799b2 +Subproject commit 9631c7d6d9cf2a52a43820f6f54df90627b48759 diff --git a/linux/mapboxgl-app.gyp b/linux/mapboxgl-app.gyp index 7b703ed75..e19768caf 100644 --- a/linux/mapboxgl-app.gyp +++ b/linux/mapboxgl-app.gyp @@ -12,6 +12,7 @@ './main.cpp', '../common/settings_json.cpp', '../common/settings_json.hpp', + '../common/platform_default.cpp', '../common/glfw_view.hpp', '../common/glfw_view.cpp', '../common/curl_request.cpp', diff --git a/macosx/mapboxgl-app.gyp b/macosx/mapboxgl-app.gyp index 480dc2a11..da5c68ea3 100644 --- a/macosx/mapboxgl-app.gyp +++ b/macosx/mapboxgl-app.gyp @@ -12,6 +12,7 @@ './main.mm', '../common/settings_nsuserdefaults.hpp', '../common/settings_nsuserdefaults.mm', + '../common/platform_nsstring.mm', '../common/glfw_view.hpp', '../common/glfw_view.cpp', '../common/foundation_request.h', diff --git a/src/renderer/symbol_bucket.cpp b/src/renderer/symbol_bucket.cpp index e8c0fd182..fa12538e4 100644 --- a/src/renderer/symbol_bucket.cpp +++ b/src/renderer/symbol_bucket.cpp @@ -75,11 +75,10 @@ std::vector SymbolBucket::processFeatures(const VectorTileLayer & if (text) { std::string u8string = util::replaceTokens(properties.text.field, feature.properties); - auto &convert = std::use_facet>(std::locale()); if (properties.text.transform == TextTransformType::Uppercase) { - convert.toupper(&u8string[0], &u8string[0] + u8string.size()); + u8string = platform::uppercase(u8string); } else if (properties.text.transform == TextTransformType::Lowercase) { - convert.tolower(&u8string[0], &u8string[0] + u8string.size()); + u8string = platform::lowercase(u8string); } ft.label = ucs4conv.convert(u8string); From b68a2a4f7631c2b4556421b3d55d46bfe7b553f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Fri, 22 Aug 2014 14:54:09 +0200 Subject: [PATCH 2/4] add uppercase/lowercase symbols to headless test --- test/test.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test.gyp b/test/test.gyp index 07709ecc8..fd7725bb0 100644 --- a/test/test.gyp +++ b/test/test.gyp @@ -201,6 +201,7 @@ "./headless.cpp", "../common/headless_view.hpp", "../common/headless_view.cpp", + "../common/platform_default.cpp", "./fixtures/fixture_request.cpp", "./fixtures/fixture_log.hpp", "./fixtures/fixture_log.cpp", From 4b7f861a6477b5f53c18e1eb1d72079b260b8841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Fri, 22 Aug 2014 15:17:43 +0200 Subject: [PATCH 3/4] use submodule version for ios build --- ios/mapbox-gl-cocoa | 2 +- scripts/travis_script.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa index 9631c7d6d..cf1f1da00 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit 9631c7d6d9cf2a52a43820f6f54df90627b48759 +Subproject commit cf1f1da000a8a5f2867d70b3828bd5b692445d89 diff --git a/scripts/travis_script.sh b/scripts/travis_script.sh index 4f02c5b7e..aaa8b54c0 100755 --- a/scripts/travis_script.sh +++ b/scripts/travis_script.sh @@ -20,7 +20,8 @@ elif [[ ${TRAVIS_OS_NAME} == "osx" ]]; then # # build iOS # - git clone --depth 1 https://github.com/mapbox/mapbox-gl-cocoa ios/mapbox-gl-cocoa + git submodule init + git submodule update make iproj-cli xcodebuild -project ./build/ios/mapbox-gl-cocoa/app/mapboxgl-app.xcodeproj -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO fi From f566b6595b009c1b0896d2e5a55324c4ab4e3b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Fri, 22 Aug 2014 15:17:53 +0200 Subject: [PATCH 4/4] increase build concurrency --- scripts/travis_script.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/travis_script.sh b/scripts/travis_script.sh index aaa8b54c0..6aaabfed6 100755 --- a/scripts/travis_script.sh +++ b/scripts/travis_script.sh @@ -16,12 +16,12 @@ elif [[ ${TRAVIS_OS_NAME} == "osx" ]]; then # build OS X # make xproj-cli - xcodebuild -project ./build/macosx/mapboxgl-app.xcodeproj + xcodebuild -project ./build/macosx/mapboxgl-app.xcodeproj -jobs 4 # # build iOS # git submodule init git submodule update make iproj-cli - xcodebuild -project ./build/ios/mapbox-gl-cocoa/app/mapboxgl-app.xcodeproj -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO + xcodebuild -project ./build/ios/mapbox-gl-cocoa/app/mapboxgl-app.xcodeproj -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO -jobs 4 fi