diff dep/animia/src/util/osx.cc @ 189:649786bae914

*: etc. code cleanup I've removed most macros and stuff dep/animia: [UNTESTED] use raw C++ instead of Objective-C++
author Paper <mrpapersonic@gmail.com>
date Wed, 06 Dec 2023 19:42:33 -0500
parents c413e475f496
children 2d5823df870f
line wrap: on
line diff
--- a/dep/animia/src/util/osx.cc	Wed Dec 06 13:44:36 2023 -0500
+++ b/dep/animia/src/util/osx.cc	Wed Dec 06 19:42:33 2023 -0500
@@ -3,23 +3,9 @@
 #include <string>
 #include <memory>
 
-#ifdef HAVE_COREFOUNDATION
-#include <CoreFoundation/CoreFoundation.h>
-#endif
-
 namespace animia::internal::osx::util {
 
 #ifdef HAVE_COREFOUNDATION
-/* I don't want to have to call CFRelease */
-template<typename T>
-struct CFDeleter {
-	using pointer = T;
-	void operator()(pointer p) { CFRelease(p); }
-}
-
-template<typename T>
-typedef CFReference = std::unique_ptr<T, CFDeleter>;
-
 /* all of these LaunchServices things use *internal functions* that are subject
  * to change. Granted, it's not very likely that these will change very much
  * because I'm fairly sure Apple uses them lots in their own internal code.
@@ -93,6 +79,17 @@
 
 	return true;
 }
+
+bool StringFromCFString(CFStringRef string, std::string& result) {
+	if (!string)
+		return false;
+
+	result.resize(CFStringGetMaximumSizeForEncoding(CFStringGetLength(str.get()), kCFStringEncodingUTF8) + 1);
+	if (!CFStringGetCString(str.get(), &result.front(), result.length(), result.length()))
+		return false;
+
+	return true;
+}
 #endif // HAVE_COREFOUNDATION
 
 static bool GetProcessArgs(pid_t pid, std::string& args) {