aboutsummaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
Diffstat (limited to 'src/base')
-rw-r--r--src/base/CMakeLists.txt1
-rw-r--r--src/base/Osx.cpp21
-rw-r--r--src/base/String.cpp24
3 files changed, 22 insertions, 24 deletions
diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt
index 1c65e865..00f35772 100644
--- a/src/base/CMakeLists.txt
+++ b/src/base/CMakeLists.txt
@@ -36,6 +36,7 @@ if (UNIX AND NOT EMSCRIPTEN)
endif()
if (APPLE)
+ target_sources(CruBase PRIVATE Osx.cpp)
find_library(CORE_FOUNDATION CoreFoundation REQUIRED)
target_link_libraries(CruBase PUBLIC ${CORE_FOUNDATION})
endif()
diff --git a/src/base/Osx.cpp b/src/base/Osx.cpp
new file mode 100644
index 00000000..6b8d0bd9
--- /dev/null
+++ b/src/base/Osx.cpp
@@ -0,0 +1,21 @@
+#include "cru/base/Osx.h"
+
+namespace cru {
+CFWrapper<CFStringRef> ToCFStringRef(StringView string) {
+ return CFWrapper<CFStringRef>(CFStringCreateWithBytes(
+ nullptr, reinterpret_cast<const UInt8*>(string.data()),
+ string.size() * sizeof(std::uint16_t), kCFStringEncodingUTF16, false));
+}
+
+String FromCFStringRef(CFStringRef string) {
+ auto length = CFStringGetLength(string);
+
+ String result;
+
+ for (int i = 0; i < length; i++) {
+ result.AppendCodePoint(CFStringGetCharacterAtIndex(string, i));
+ }
+
+ return result;
+}
+} // namespace cru
diff --git a/src/base/String.cpp b/src/base/String.cpp
index 40d0b766..e9623201 100644
--- a/src/base/String.cpp
+++ b/src/base/String.cpp
@@ -673,28 +673,4 @@ String ToUpper(StringView s) {
return result;
}
-
-#ifdef CRU_PLATFORM_OSX
-CFWrapper<CFStringRef> StringView::ToCFStringRef() const {
- return CFWrapper<CFStringRef>(CFStringCreateWithBytes(
- nullptr, reinterpret_cast<const UInt8*>(this->data()),
- this->size() * sizeof(std::uint16_t), kCFStringEncodingUTF16, false));
-}
-
-CFWrapper<CFStringRef> String::ToCFStringRef() const {
- return StringView(*this).ToCFStringRef();
-}
-
-String String::FromCFStringRef(CFStringRef string) {
- auto length = CFStringGetLength(string);
-
- String result;
-
- for (int i = 0; i < length; i++) {
- result.AppendCodePoint(CFStringGetCharacterAtIndex(string, i));
- }
-
- return result;
-}
-#endif
} // namespace cru