Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/AutoItX3/au3.rb
Overview
Added some methods to the build-in String class.
Instance Method Summary collapse
-
#normal(encoding = "UTF-8") ⇒ Object
(also: #to_char)
The AutoItX3 API returns wchar_t * (or LPCSWSTR) typed strings instead of the usual char *.
-
#normal!(encoding = "UTF-8") ⇒ Object
Self-modifying version of #normal.
-
#wide ⇒ Object
(also: #to_wchar_t)
The AutoItX3 API requires wchar_t * (or LPCWSTR) typed strings instead of the usual char *.
-
#wide! ⇒ Object
Self-modifying version of #wide.
Instance Method Details
#normal(encoding = "UTF-8") ⇒ Object Also known as: to_char
The AutoItX3 API returns wchar_t * (or LPCSWSTR) typed strings instead of the usual char *. This method should only be used for strings that have been created by #wide or by the au3 API (which uses #wide internally). Keep in mind that this method removes unconvertable characters.
Returns an encoding
encoded string that has been a wchar_t * (LPCWSTR) type.
35 36 37 |
# File 'lib/AutoItX3/au3.rb', line 35 def normal(encoding = "UTF-8") encode(encoding, :invalid => :replace, :undef => :replace, :replace => "").gsub("\0", "").gsub("\r\n", "\n") end |
#normal!(encoding = "UTF-8") ⇒ Object
Self-modifying version of #normal.
41 42 43 44 45 |
# File 'lib/AutoItX3/au3.rb', line 41 def normal!(encoding = "UTF-8") encode!(encoding, :invalid => :replace, :undef => :replace, :replace => "") gsub!("\0", "") gsub!("\r\n", "\n") end |
#wide ⇒ Object Also known as: to_wchar_t
The AutoItX3 API requires wchar_t * (or LPCWSTR) typed strings instead of the usual char *. After some web research I found out that this type is a UTF-16 encoded string, that has to be terminated with a double NUL character; I tried to encode the string UTF-16BE, then UTF-16LE and added the extra NUL to it, and found out it worked. That’s what this method does.
19 20 21 |
# File 'lib/AutoItX3/au3.rb', line 19 def wide (self + "\0").encode("UTF-16LE") end |
#wide! ⇒ Object
Self-modifying version of #wide.
25 26 27 28 |
# File 'lib/AutoItX3/au3.rb', line 25 def wide! self << "\0" encode!("UTF-16LE") end |