Class: CoreFoundation::CFStringRef
- Inherits:
-
FFI::Pointer
- Object
- FFI::Pointer
- CoreFoundation::CFStringRef
- Defined in:
- lib/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.
47 48 49 |
# File 'lib/core_foundation.rb', line 47 def length CoreFoundation.CFStringGetLength(self) end |
#max_size ⇒ CFIndex
Returns the maximum size of the buffer that will hold the string.
52 53 54 |
# File 'lib/core_foundation.rb', line 52 def max_size CoreFoundation.CFStringGetMaximumSizeForEncoding(length, CFStringEncoding[:UTF8]) end |
#to_s ⇒ String
Returns the CFString, converted to a UTF-8 string.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/core_foundation.rb', line 57 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 |