Class: Ole::Types::Lpwstr

Inherits:
String
  • Object
show all
Defined in:
lib/ole/types/base.rb,
lib/ole/types/base.rb

Overview

for VT_LPWSTR

Constant Summary collapse

FROM_UTF16 =
Iconv.new 'utf-8', 'utf-16le'
TO_UTF16 =
Iconv.new 'utf-16le', 'utf-8'

Class Method Summary collapse

Methods inherited from String

#each_chunk

Class Method Details

.dump(str) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/ole/types/base.rb', line 61

def self.dump str
	# need to append nulls?
	data = str.encode(Encoding::UTF_16LE)
	# not sure if this is the recommended way to do it, but I want to treat
	# the resulting utf16 data as regular bytes, not characters.
	data.force_encoding Encoding::ASCII_8BIT
	data
end

.load(str) ⇒ Object



57
58
59
# File 'lib/ole/types/base.rb', line 57

def self.load str
	new str.encode(Encoding::UTF_8, Encoding::UTF_16LE).chomp(0.chr)
end