aboutsummaryrefslogtreecommitdiff
path: root/include/cru
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru')
-rw-r--r--include/cru/base/Osx.h26
-rw-r--r--include/cru/base/Range.h12
-rw-r--r--include/cru/base/String.h14
-rw-r--r--include/cru/base/platform/osx/Convert.h17
-rw-r--r--include/cru/base/platform/osx/Exception.h14
-rw-r--r--include/cru/platform/osx/Convert.h2
-rw-r--r--include/cru/platform/osx/Exception.h3
7 files changed, 52 insertions, 36 deletions
diff --git a/include/cru/base/Osx.h b/include/cru/base/Osx.h
new file mode 100644
index 00000000..711da9a3
--- /dev/null
+++ b/include/cru/base/Osx.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#ifndef CRU_PLATFORM_OSX
+#error "This header can only be included on OSX."
+#endif
+
+#include <CoreFoundation/CoreFoundation.h>
+
+namespace cru {
+template <typename CFClassRef>
+class CFWrapper {
+ public:
+ CFClassRef ref;
+
+ explicit CFWrapper(CFClassRef ref) { this->ref = ref; }
+ ~CFWrapper() {
+ if (this->ref) CFRelease(this->ref);
+ }
+
+ CFClassRef* release() {
+ auto ref = this->ref;
+ this->ref = nullptr;
+ return ref;
+ }
+};
+} // namespace cru
diff --git a/include/cru/base/Range.h b/include/cru/base/Range.h
index edc2ec55..ade1979a 100644
--- a/include/cru/base/Range.h
+++ b/include/cru/base/Range.h
@@ -1,6 +1,10 @@
#pragma once
#include "Base.h"
+#ifdef CRU_PLATFORM_OSX
+#include <CoreFoundation/CoreFoundation.h>
+#endif
+
namespace cru {
struct Range final {
constexpr static Range FromTwoSides(Index start, Index end) {
@@ -36,6 +40,14 @@ struct Range final {
return Range::FromTwoSides(coerce(GetStart()), coerce(GetEnd()));
}
+#ifdef CRU_PLATFORM_OSX
+ CFRange ToCFRange() const { return CFRangeMake(this->position, this->count); }
+
+ static Range FromCFRange(const CFRange& range) {
+ return Range(range.location, range.length);
+ }
+#endif
+
Index position = 0;
Index count = 0;
};
diff --git a/include/cru/base/String.h b/include/cru/base/String.h
index 21a3db51..49c96c4a 100644
--- a/include/cru/base/String.h
+++ b/include/cru/base/String.h
@@ -14,6 +14,11 @@
#include <type_traits>
#include <vector>
+#ifdef CRU_PLATFORM_OSX
+#include <CoreFoundation/CoreFoundation.h>
+#include <cru/base/Osx.h>
+#endif
+
namespace cru {
class StringView;
@@ -237,6 +242,11 @@ class CRU_BASE_API String {
}
#endif
+#ifdef CRU_PLATFORM_OSX
+ CFWrapper<CFStringRef> ToCFStringRef() const;
+ static String FromCFStringRef(CFStringRef string);
+#endif
+
template <typename... T>
String Format(T&&... args) const;
@@ -380,6 +390,10 @@ class CRU_BASE_API StringView {
std::string ToUtf8() const;
Buffer ToUtf8Buffer(bool end_zero = true) const;
+#ifdef CRU_PLATFORM_OSX
+ CFWrapper<CFStringRef> ToCFStringRef() const;
+#endif
+
private:
const char16_t* ptr_;
Index size_;
diff --git a/include/cru/base/platform/osx/Convert.h b/include/cru/base/platform/osx/Convert.h
deleted file mode 100644
index 6250190e..00000000
--- a/include/cru/base/platform/osx/Convert.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#pragma once
-
-#ifndef CRU_PLATFORM_OSX
-#error "This file can only be included on osx."
-#endif
-
-#include "../../String.h"
-
-#include <CoreFoundation/CoreFoundation.h>
-
-namespace cru::platform::osx {
-CFStringRef Convert(const String& string);
-String Convert(CFStringRef string);
-
-CFRange Convert(const Range& range);
-Range Convert(const CFRange& range);
-} // namespace cru::platform::osx
diff --git a/include/cru/base/platform/osx/Exception.h b/include/cru/base/platform/osx/Exception.h
deleted file mode 100644
index c1037cc6..00000000
--- a/include/cru/base/platform/osx/Exception.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#pragma once
-
-#ifndef CRU_PLATFORM_OSX
-#error "This file can only be included on osx."
-#endif
-
-#include "../Exception.h"
-
-namespace cru::platform::osx {
-class OsxException : public PlatformException {
- public:
- using PlatformException::PlatformException;
-};
-} // namespace cru::platform::osx
diff --git a/include/cru/platform/osx/Convert.h b/include/cru/platform/osx/Convert.h
deleted file mode 100644
index 7994af44..00000000
--- a/include/cru/platform/osx/Convert.h
+++ /dev/null
@@ -1,2 +0,0 @@
-#pragma once
-#include "cru/base/platform/osx/Convert.h"
diff --git a/include/cru/platform/osx/Exception.h b/include/cru/platform/osx/Exception.h
deleted file mode 100644
index d3c2aee0..00000000
--- a/include/cru/platform/osx/Exception.h
+++ /dev/null
@@ -1,3 +0,0 @@
-#pragma once
-#include "cru/base/platform/osx/Exception.h"
-#include "cru/platform/Exception.h"