Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/ffi/win32/extensions.rb
Instance Method Summary collapse
-
#read_wide_string ⇒ Object
Read a wide character string up until the first double null, and delete any remaining null characters.
-
#wincode ⇒ Object
Convenience method for converting strings to UTF-16LE for wide character functions that require it.
-
#wstrip ⇒ Object
Read a wide character string up until the first double null, and delete any remaining null characters.
Instance Method Details
#read_wide_string ⇒ Object
Read a wide character string up until the first double null, and delete any remaining null characters.
130 131 132 |
# File 'lib/ffi/win32/extensions.rb', line 130 def read_wide_string self[/^.*?(?=\x00{2})/].delete(0.chr) end |
#wincode ⇒ Object
Convenience method for converting strings to UTF-16LE for wide character functions that require it.
112 113 114 |
# File 'lib/ffi/win32/extensions.rb', line 112 def wincode (tr(File::SEPARATOR, File::ALT_SEPARATOR) + 0.chr).encode("UTF-16LE") end |
#wstrip ⇒ Object
Read a wide character string up until the first double null, and delete any remaining null characters. If this fails (typically because there are only null characters) then nil is returned instead.
120 121 122 123 124 125 |
# File 'lib/ffi/win32/extensions.rb', line 120 def wstrip force_encoding("UTF-16LE").encode("UTF-8", invalid: :replace, undef: :replace) .split("\x00")[0].encode(Encoding.default_external) rescue nil end |