aboutsummaryrefslogtreecommitdiff
path: root/src/base/String.cpp
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-06-15 01:02:30 +0800
committerYuqian Yang <crupest@crupest.life>2025-06-15 01:02:30 +0800
commitd868d7b0d463ede80b761f87f10d4e25f52989c3 (patch)
treeeb61e339f15b6b8b4cc1a246b4281631e701d6e0 /src/base/String.cpp
parent7ac84c9d200d43f50155ce1e8316ada12043f7a8 (diff)
downloadcru-d868d7b0d463ede80b761f87f10d4e25f52989c3.tar.gz
cru-d868d7b0d463ede80b761f87f10d4e25f52989c3.tar.bz2
cru-d868d7b0d463ede80b761f87f10d4e25f52989c3.zip
Remove some files of OSX. Symbol Point is conflict and needs to be
fixed.
Diffstat (limited to 'src/base/String.cpp')
-rw-r--r--src/base/String.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/base/String.cpp b/src/base/String.cpp
index 47b64373..40d0b766 100644
--- a/src/base/String.cpp
+++ b/src/base/String.cpp
@@ -12,7 +12,10 @@
#include <cmath>
#include <cstring>
#include <functional>
-#include <string_view>
+
+#ifdef CRU_PLATFORM_OSX
+#include <CoreFoundation/CoreFoundation.h>
+#endif
namespace cru {
template <typename C>
@@ -669,4 +672,29 @@ String ToUpper(StringView s) {
for (auto c : s) result.push_back(ToUpper(c));
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