Heesob Park wrote:
> 2008/10/2 Berger, Daniel <Daniel.Berger at qwest.com>:
>>> -----Original Message-----
>>> From: win32utils-devel-bounces at rubyforge.org
>>> [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of
>>> Berger, Daniel
>>> Sent: Thursday, October 02, 2008 8:12 AM
>>> To: Development and ideas for win32utils projects
>>> Subject: Re: [Win32utils-devel] Problems with win32-dir and
>>> create_junction
>> <snip>
>>
>>> Do you think we should automatically strip the trailing
>>> "\000\000" in the multi_to_wide method then? I think this
>>> would work because I modified wide_to_multi to automatically
>>> append "\000\000" to the incoming string if they weren't
>>> already there.
>> On second thought, I think that might cause wide character functions to
>> fail.
>>
> I think it would be better to define new method for getting the
> wide_string length
> than to use String#size method.
I have a very alpha "UString" class I've got in CVS (in the "shards" project,
not win32utils) where I've been tinkering with a Windows-only subclass of
String. It redefines methods like length, size, etc. I've pasted what I've done
so far below.
Or do you think that's overkill?
Regards,
Dan
# ustring.rb - ALPHA
class UString < String
include Windows::Unicode
include Windows::MSVCRT::String
VERSION = '0.1.0'
ACP = CP_ACP
UTF7 = CP_UTF7
UTF8 = CP_UTF8
attr_accessor :encoding
alias :at :[]
def initialize(string, encoding = UTF8)
ustring = multi_to_wide(string, encoding)
@encoding = encoding
super(ustring)
end
def inspect
wide_to_multi(self, @encoding)
end
def to_s
wide_to_multi(self, @encoding)
end
def to_str
wide_to_multi(self, @encoding)
end
# Length in chars
def length
wcslen(self)
end
# Size in bytes
def size
strlen(wide_to_multi(self, @encoding))
end
# Returns the character (not the numeric value)
def [](n)
wide_to_multi(self, @encoding).at(n, 1)
end
end