Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/AutoItX3/au3.rb

Overview

Added some methods to the build-in String class.

Instance Method Summary collapse

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.



37
38
39
# File 'lib/AutoItX3/au3.rb', line 37

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.



43
44
45
46
47
# File 'lib/AutoItX3/au3.rb', line 43

def normal!(encoding = "UTF-8")
  encode!(encoding, :invalid => :replace, :undef => :replace, :replace => "")
  gsub!("\0", "")
  gsub!("\r\n", "\n")
end

#wideObject 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.



21
22
23
# File 'lib/AutoItX3/au3.rb', line 21

def wide
  (self + "\0").encode("UTF-16LE")
end

#wide!Object

Self-modifying version of #wide.



27
28
29
30
# File 'lib/AutoItX3/au3.rb', line 27

def wide!
  self << "\0"
  encode!("UTF-16LE")
end