Class: ICU::UCharPointer

Inherits:
FFI::MemoryPointer
  • Object
show all
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

Constructor Details

#initialize(size) ⇒ UCharPointer

Returns a new instance of UCharPointer.



17
18
19
# File 'lib/ffi-icu/uchar.rb', line 17

def initialize(size)
  super UCHAR_TYPE, size
end

Class Method Details

.from_string(str) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/ffi-icu/uchar.rb', line 7

def self.from_string(str)
  str   = str.encode("UTF-8") if str.respond_to? :encode
  bytes = str.unpack("U*")

  ptr = new bytes.size
  ptr.put_array_of_uint16 0, bytes

  ptr
end

Instance Method Details

#resized_to(new_size) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/ffi-icu/uchar.rb', line 21

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



29
30
31
32
33
34
# File 'lib/ffi-icu/uchar.rb', line 29

def string(length = nil)
  length ||= size / TYPE_SIZE

  wstring = get_array_of_uint16(0, length)
  wstring.pack("U*")
end