aboutsummaryrefslogtreecommitdiff
path: root/src/common/platform/osx/Convert.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-25 17:30:46 +0800
committercrupest <crupest@outlook.com>2022-01-25 17:30:46 +0800
commit2ed65999ef6f3e1156427dd3efe04353ae657882 (patch)
tree1c6618099e42887e96351c87cc8ce6b7c61b01f7 /src/common/platform/osx/Convert.cpp
parenta77fb1aaa4aa765ae51b3cb5a1f8d9c8c233b01a (diff)
downloadcru-2ed65999ef6f3e1156427dd3efe04353ae657882.tar.gz
cru-2ed65999ef6f3e1156427dd3efe04353ae657882.tar.bz2
cru-2ed65999ef6f3e1156427dd3efe04353ae657882.zip
...
Diffstat (limited to 'src/common/platform/osx/Convert.cpp')
-rw-r--r--src/common/platform/osx/Convert.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/common/platform/osx/Convert.cpp b/src/common/platform/osx/Convert.cpp
new file mode 100644
index 00000000..e5105698
--- /dev/null
+++ b/src/common/platform/osx/Convert.cpp
@@ -0,0 +1,29 @@
+#include "cru/common/platform/osx/Convert.hpp"
+
+namespace cru::platform::osx {
+CFStringRef Convert(const String& string) {
+ return CFStringCreateWithBytes(
+ nullptr, reinterpret_cast<const UInt8*>(string.data()),
+ string.size() * sizeof(std::uint16_t), kCFStringEncodingUTF16, false);
+}
+
+String Convert(CFStringRef string) {
+ auto length = CFStringGetLength(string);
+
+ String result;
+
+ for (int i = 0; i < length; i++) {
+ result.AppendCodePoint(CFStringGetCharacterAtIndex(string, i));
+ }
+
+ return result;
+}
+
+CFRange Convert(const Range& range) {
+ return CFRangeMake(range.position, range.count);
+}
+
+Range Convert(const CFRange& range) {
+ return Range(range.location, range.length);
+}
+} // namespace cru::platform::osx