summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/platform_default.cpp25
-rw-r--r--common/platform_nsstring.mm21
2 files changed, 46 insertions, 0 deletions
diff --git a/common/platform_default.cpp b/common/platform_default.cpp
new file mode 100644
index 0000000000..1acbfa8508
--- /dev/null
+++ b/common/platform_default.cpp
@@ -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;
+}
+
+}
+}
diff --git a/common/platform_nsstring.mm b/common/platform_nsstring.mm
new file mode 100644
index 0000000000..9119f2a8fe
--- /dev/null
+++ b/common/platform_nsstring.mm
@@ -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] };
+}
+
+}
+} \ No newline at end of file