class ICU::UCharPointer
Constants
- TYPE_SIZE
- UCHAR_TYPE
Public Class Methods
from_string(str, capacity = nil)
click to toggle source
# File lib/ffi-icu/uchar.rb, line 7 def self.from_string(str, capacity = nil) str = str.encode("UTF-8") if str.respond_to? :encode chars = str.unpack("U*") if capacity if capacity < chars.size raise ArgumentError, "capacity is too small for string of #{chars.size} UChars" end ptr = new capacity else ptr = new chars.size end ptr.write_array_of_uint16 chars ptr end
new(size)
click to toggle source
Calls superclass method
# File lib/ffi-icu/uchar.rb, line 26 def initialize(size) super UCHAR_TYPE, size end
Public Instance Methods
resized_to(new_size)
click to toggle source
# File lib/ffi-icu/uchar.rb, line 30 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)
click to toggle source
# File lib/ffi-icu/uchar.rb, line 39 def string(length = nil) length ||= size / TYPE_SIZE wstring = read_array_of_uint16(length) wstring.pack("U*") end