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