-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Currently we use CFStringGetCharacterAtIndex and iterate over the CF String to construct the String. This is obviously inefficient, and we should use CFStringGetCharacters instead.
Some example code which I haven't quite got working yet:
mutable struct CFRange
length::Int
location::Int
end
function _cfstring_get_characters(cfstr::Cstring, range::CFRange)
charbuf = Vector{UInt8}(undef, range.length)
ccall(:CFStringGetCharacters, Ptr{UInt32}, (Cstring, Ptr{Cvoid}, Ptr{Cvoid}), cfstr, pointer_from_objref(range), charbuf)
return charbuf
end
function _string_from_cfstring(cfstr::Cstring, encoding::Unsigned = K_CFSTRING_ENCODING_MACROMAN)
strlen = _cfstring_get_length(cfstr)
maxsz = _cfstring_get_maximum_size_for_encoding(strlen, encoding)
return _cfstring_get_characters(cfstr, CFRange(maxsz, 0))
endThen, we will simple be able to write
function _string_from_cf_string(cfstr::Cstring)
charbuf = _string_from_cfstring(cfstr)
return String(charbuf)
end