Still CFStringGetCStringPtr whenever possible
@@ -118,6 +118,9 @@ unsafe fn get_str_value(dict: CFDictionaryRef, key: &[u8]) -> Option<String> {
let len_utf16 = cfs::CFStringGetLength(v);
let len_bytes = len_utf16 as usize * 2; // Two bytes per UTF-16 codepoint.
+ let v_ptr = cfs::CFStringGetCStringPtr(v, cfs::kCFStringEncodingUTF8);
+ if v_ptr.is_null() {
+ // Fallback on CFStringGetString to read the underlying bytes from the CFString.
let mut buf = vec![0; len_bytes];
let success = cfs::CFStringGetCString(
v,
@@ -131,6 +134,9 @@ unsafe fn get_str_value(dict: CFDictionaryRef, key: &[u8]) -> Option<String> {
} else {
None
}
+ } else {
+ utils::cstr_to_rust_with_size(v_ptr, Some(len_bytes))
+ }
})
}
