Class: FFI::Pointer

Inherits:
Object
  • Object
show all
Includes:
Chef::Mixin::WideString
Defined in:
lib/chef/win32/unicode.rb

Instance Method Summary collapse

Methods included from Chef::Mixin::WideString

#utf8_to_wide, #wide_to_utf8, #wstring

Instance Method Details

#read_utf16stringObject


52
53
54
55
56
# File 'lib/chef/win32/unicode.rb', line 52

def read_utf16string
  offset = 0
  offset += 2 while get_bytes(offset, 2) != "\x00\x00"
  get_bytes(0, offset).force_encoding("utf-16le").encode("utf-8")
end

#read_wstring(num_wchars = nil) ⇒ Object


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/chef/win32/unicode.rb', line 36

def read_wstring(num_wchars = nil)
  if num_wchars.nil?
    # Find the length of the string
    length = 0
    last_char = nil
    while last_char != "\000\000"
      length += 1
      last_char = get_bytes(0, length * 2)[-2..-1]
    end

    num_wchars = length
  end

  wide_to_utf8(get_bytes(0, num_wchars * 2))
end