Parent

UnicodeEx::UTF8

UTF-8 subclass of String

Public Class Methods

from_w(utf16_string) click to toggle source

Returns an UTF-8 string from an UTF-16 string.

  • utf16_string — UTF-16 String
# File WinEx.rb, line 284
                def self.from_w(utf16_string)
                        # (!)
                end
to_w(utf8_string) click to toggle source

Returns an UTF-16 String.

  • file_name — UTF-8 String
 utf16 = UnicodeEx::UTF8.to_w('Hello')
# File WinEx.rb, line 277
                def self.to_w(utf8_string)
                        #return Unicode::UTF8.new(utf8_string).to_w
                        return UTF8.new(utf8_string).to_w
                end

Public Instance Methods

length() click to toggle source

Return the number of UTF-8 characters.

# File UnicodeEx.rb, line 12
                def length
                        return self.unpack('U*').length
                end
to_w() click to toggle source

Returns an UTF-16 String.

 text = UnicodeEx::UTF8.new('Hello')
 utf16 = text.to_w
# File WinEx.rb, line 262
                def to_w()
                        # Declare API calls
                        multiByteToWideChar = Win32API.new('Kernel32','MultiByteToWideChar',['I','L','P','I','P','I'], 'I')
                        # Get the buffer size
                        buffer_size = multiByteToWideChar.call(WinEx::CP_UTF8, 0, self, self.bytes, nil, 0)
                        # Reserve memory for the return string
                        utf16_string = '  ' * buffer_size
                        # Make the call
                        ret = multiByteToWideChar.call(WinEx::CP_UTF8, 0, self, self.bytes, utf16_string, self.length)
                        return utf16_string
                end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.