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..cf1f1da00 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit e1c709a8de0b69aa6bfbcd9ea4faf981b6e799b2 +Subproject commit cf1f1da000a8a5f2867d70b3828bd5b692445d89 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/scripts/travis_script.sh b/scripts/travis_script.sh index a13d7531e..f8325e41c 100755 --- a/scripts/travis_script.sh +++ b/scripts/travis_script.sh @@ -17,11 +17,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 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 + xcodebuild -project ./build/ios/mapbox-gl-cocoa/app/mapboxgl-app.xcodeproj -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO -jobs 4 fi diff --git a/src/renderer/symbol_bucket.cpp b/src/renderer/symbol_bucket.cpp index f953f0716..fd8931509 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); 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",