Class: WideString
- Inherits:
-
String
- Object
- String
- WideString
- Includes:
- Windows::MSVCRT::String, Windows::Unicode
- Defined in:
- lib/windows/wide_string.rb
Overview
This is a class that simplifies wide string handling. It is NOT meant for general consumption, but for internal use by the Win32Utils Team. Use at your own risk.
Constant Summary collapse
- ACP =
CP_ACP
- UTF7 =
CP_UTF7
- UTF8 =
CP_UTF8
Instance Attribute Summary collapse
-
#encoding ⇒ Object
Get or set the encoding of the wide string object.
Instance Method Summary collapse
-
#initialize(string, encoding = UTF8) ⇒ WideString
constructor
Creates a new wide
string
with the givenencoding
, or UTF8 if no encoding is specified. -
#length ⇒ Object
The length of the wide string in chars.
-
#size ⇒ Object
The size of the wide string in bytes.
-
#to_multi ⇒ Object
(also: #to_s, #to_str, #inspect)
Returns the multibyte version of the wide string.
-
#to_multi! ⇒ Object
Replaces the wide string with a multibyte version.
-
#wstrip ⇒ Object
Strips the trailing two null characters from the string.
Constructor Details
#initialize(string, encoding = UTF8) ⇒ WideString
Creates a new wide string
with the given encoding
, or UTF8 if no encoding is specified.
23 24 25 26 |
# File 'lib/windows/wide_string.rb', line 23 def initialize(string, encoding = UTF8) super(multi_to_wide(string, encoding)) @encoding = encoding end |
Instance Attribute Details
#encoding ⇒ Object
Get or set the encoding of the wide string object
18 19 20 |
# File 'lib/windows/wide_string.rb', line 18 def encoding @encoding end |
Instance Method Details
#length ⇒ Object
The length of the wide string in chars.
52 53 54 |
# File 'lib/windows/wide_string.rb', line 52 def length wcslen(self) * 2 end |
#size ⇒ Object
The size of the wide string in bytes.
57 58 59 |
# File 'lib/windows/wide_string.rb', line 57 def size wcslen(self) end |
#to_multi ⇒ Object Also known as: to_s, to_str, inspect
Returns the multibyte version of the wide string.
30 31 32 |
# File 'lib/windows/wide_string.rb', line 30 def to_multi wide_to_multi(self, @encoding) end |
#to_multi! ⇒ Object
Replaces the wide string with a multibyte version.
36 37 38 |
# File 'lib/windows/wide_string.rb', line 36 def to_multi! self.replace(wide_to_multi(self, @encoding)) end |
#wstrip ⇒ Object
Strips the trailing two null characters from the string.
46 47 48 |
# File 'lib/windows/wide_string.rb', line 46 def wstrip self[0..-3] if string[-2..-1] == "\000\000" end |