30 CFStringRef cfStr = CFStringCreateWithBytes(kCFAllocatorDefault, buf, buflen, kCFStringEncodingUTF8,
false);
31 if (cfStr ==
nullptr) {
32 NDN_THROW(std::runtime_error(
"Failed to create CFString from buffer"));
40 CFStringRef cfStr = CFStringCreateWithCString(kCFAllocatorDefault, str.data(), kCFStringEncodingUTF8);
41 if (cfStr ==
nullptr) {
42 NDN_THROW(std::runtime_error(
"Failed to create CFString from std::string"));
50 const char* cStr = CFStringGetCStringPtr(cfStr, kCFStringEncodingUTF8);
51 if (cStr !=
nullptr) {
57 std::string str(CFStringGetLength(cfStr) + 1,
'\0');
59 if (!CFStringGetCString(cfStr, &str.front(), str.size(), kCFStringEncodingUTF8)) {
60 NDN_THROW(std::runtime_error(
"CFString to std::string conversion failed"));
This file contains utilities to deal with Apple Core Foundation's CFString and related types.
Helper class to wrap CoreFoundation object pointers.
Common includes and macros used throughout the library.
CFReleaser< CFStringRef > fromBuffer(const uint8_t *buf, size_t buflen)
Create a CFString by copying bytes from a raw buffer.
std::string toStdString(CFStringRef cfStr)
Convert a CFString to a std::string.
CFReleaser< CFStringRef > fromStdString(const std::string &str)
Create a CFString by copying characters from a std::string.