Class: CoreFoundation::CFStringRef
- Inherits:
-
FFI::Pointer
- Object
- FFI::Pointer
- CoreFoundation::CFStringRef
- Defined in:
- lib/macos/core_foundation.rb
Instance Method Summary collapse
-
#length ⇒ CFIndex
The length of the referenced CFString.
-
#max_size ⇒ CFIndex
The maximum size of the buffer that will hold the string.
-
#to_s ⇒ String
The CFString, converted to a UTF-8 string.
Instance Method Details
#length ⇒ CFIndex
Returns the length of the referenced CFString.
49 50 51 |
# File 'lib/macos/core_foundation.rb', line 49 def length CoreFoundation.CFStringGetLength(self) end |
#max_size ⇒ CFIndex
Returns the maximum size of the buffer that will hold the string.
54 55 56 |
# File 'lib/macos/core_foundation.rb', line 54 def max_size CoreFoundation.CFStringGetMaximumSizeForEncoding(length, CFStringEncoding[:UTF8]) end |
#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 |