Merge pull request #445 from mapbox/nsstring
Use NSString-specific case change functions on OS X/iOS
This commit is contained in:
25
common/platform_default.cpp
Normal file
25
common/platform_default.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
|
||||
#include <locale>
|
||||
|
||||
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::ctype<char>>(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::ctype<char>>(std::locale());
|
||||
std::string converted = string;
|
||||
convert.tolower(&converted[0], &converted[0] + converted.size());
|
||||
return converted;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
21
common/platform_nsstring.mm
Normal file
21
common/platform_nsstring.mm
Normal file
@@ -0,0 +1,21 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace platform {
|
||||
|
||||
std::string uppercase(const std::string &string) {
|
||||
NSString *nsstring = [[NSString alloc] initWithBytesNoCopy:const_cast<char *>(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<char *>(string.data()) length:string.size() encoding:NSUTF8StringEncoding freeWhenDone:NO];
|
||||
nsstring = [nsstring lowercaseString];
|
||||
return { [nsstring cStringUsingEncoding:NSUTF8StringEncoding], [nsstring lengthOfBytesUsingEncoding:NSUTF8StringEncoding] };
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,12 @@ std::shared_ptr<Request> request_http(const std::string &url,
|
||||
std::function<void(Response *)> callback,
|
||||
std::shared_ptr<uv::loop> 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<Request> &req);
|
||||
|
||||
|
||||
Submodule ios/mapbox-gl-cocoa updated: e1c709a8de...cf1f1da000
@@ -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',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -75,11 +75,10 @@ std::vector<SymbolFeature> SymbolBucket::processFeatures(const VectorTileLayer &
|
||||
if (text) {
|
||||
std::string u8string = util::replaceTokens(properties.text.field, feature.properties);
|
||||
|
||||
auto &convert = std::use_facet<std::ctype<char>>(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);
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user