Method: CoreFoundation::CFStringRef#to_s
- Defined in:
- lib/macos/core_foundation.rb
#to_s ⇒ String
Returns the CFString, converted to a UTF-8 string.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/macos/core_foundation.rb', line 59 def to_s buffer = FFI::MemoryPointer.new(:char, max_size) used_bytes = FFI::MemoryPointer.new(CFIndex) CoreFoundation.CFStringGetBytes(self, CFRange.make(location:0, length:length), CFStringEncoding[:UTF8], 0, false, buffer, buffer.size, used_bytes) used_bytes = if CFIndex == CoreFoundation.find_type(:long_long) used_bytes.read_long_long else used_bytes.read_long end buffer.read_string(used_bytes).force_encoding(Encoding::UTF_8) end |