decklink: Use libobs CFString utils

This commit is contained in:
Marvin Scholz 2018-09-16 17:54:50 +02:00
parent 26a96c618f
commit 94b30ec05a

View File

@ -1,22 +1,17 @@
#include "../platform.hpp" #include "../platform.hpp"
#include <util/apple/cfstring-utils.h>
bool DeckLinkStringToStdString(decklink_string_t input, std::string& output) bool DeckLinkStringToStdString(decklink_string_t input, std::string& output)
{ {
const CFStringRef string = static_cast<CFStringRef>(input); const CFStringRef string = static_cast<CFStringRef>(input);
const CFIndex length = CFStringGetLength(string);
const CFIndex maxLength = CFStringGetMaximumSizeForEncoding(length,
kCFStringEncodingASCII) + 1;
char * const buffer = new char[maxLength]; char *buffer = cfstr_copy_cstr(string, kCFStringEncodingASCII);
const bool result = CFStringGetCString(string, buffer, maxLength, if (buffer)
kCFStringEncodingASCII);
if (result)
output = std::string(buffer); output = std::string(buffer);
delete[] buffer; bfree(buffer);
CFRelease(string); CFRelease(string);
return result; return (buffer != NULL);
} }