Class: ICU::UCharPointer
- Inherits:
-
FFI::MemoryPointer
- Object
- FFI::MemoryPointer
- ICU::UCharPointer
- Defined in:
- lib/ffi-icu/uchar.rb
Constant Summary collapse
- UCHAR_TYPE =
not sure how platform-dependent this is..
:uint16- TYPE_SIZE =
FFI.type_size(UCHAR_TYPE)
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(size) ⇒ UCharPointer
constructor
A new instance of UCharPointer.
- #length_in_uchars ⇒ Object
- #resized_to(new_size) ⇒ Object
- #string(length = nil) ⇒ Object
Constructor Details
#initialize(size) ⇒ UCharPointer
Returns a new instance of UCharPointer.
25 26 27 |
# File 'lib/ffi-icu/uchar.rb', line 25 def initialize(size) super(UCHAR_TYPE, size) end |
Class Method Details
.from_string(str, capacity = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ffi-icu/uchar.rb', line 8 def self.from_string(str, capacity = nil) str = str.encode('UTF-8') if str.respond_to?(:encode) chars = str.unpack('U*') if capacity raise(ArgumentError, "capacity is too small for string of #{chars.size} UChars") if capacity < chars.size ptr = new(capacity) else ptr = new(chars.size) end ptr.write_array_of_uint16(chars) ptr end |
Instance Method Details
#length_in_uchars ⇒ Object
45 46 47 |
# File 'lib/ffi-icu/uchar.rb', line 45 def length_in_uchars size / type_size end |
#resized_to(new_size) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/ffi-icu/uchar.rb', line 29 def resized_to(new_size) raise('new_size must be larger than current size') if new_size < size resized = self.class.new(new_size) resized.put_bytes(0, get_bytes(0, size)) resized end |
#string(length = nil) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/ffi-icu/uchar.rb', line 38 def string(length = nil) length ||= size / TYPE_SIZE wstring = read_array_of_uint16(length) wstring.pack('U*') end |