Class: FFI::Pointer
- Inherits:
-
Object
- Object
- FFI::Pointer
- Defined in:
- lib/win32/taskscheduler/sid.rb
Instance Method Summary collapse
Instance Method Details
#read_wstring(num_wchars = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/win32/taskscheduler/sid.rb', line 5 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 |
#wide_to_utf8(wstring) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/win32/taskscheduler/sid.rb', line 21 def wide_to_utf8(wstring) # ensure it is actually UTF-16LE # Ruby likes to mark binary data as ASCII-8BIT wstring = wstring.force_encoding("UTF-16LE") # encode it all as UTF-8 and remove trailing CRLF and NULL characters wstring.encode("UTF-8").strip end |