[Win32utils-devel] Making multi_to_wide and wide_to_multi smarter

Daniel Berger djberg96 at gmail.com
Fri Nov 14 18:54:40 EST 2008


Heesob Park wrote:
> 2008/11/13 Berger, Daniel <Daniel.Berger at qwest.com>:
>> Hi,
>>
>> I noticed this:
>>
>> require 'windows/unicode'
>> include Windows::Unicode
>>
>> s = "hello"
>> s2 = multi_to_wide(s)  # => "h\000e\000l\000l\000o\000\000\000"
>> s3 = multi_to_wide(s2) # => "h\000\000\000"
>>
>> I think it would be better to modify multi_to_wide so that it returns
>> the string as-is if it's already a wide string. Looks like the same
>> issue exists for multiple calls of wide_to_multi, too.
>>
>> The case I hit was with win32-file and win32-file-stat, where passing a
>> wide string to File::Stat.new failed because it was doing its own
>> multi_to_wide call. The double call caused File::Stat.new to fail.
>>
>> I _could_ call wide_to_multi before passing the argument on, but I would
>> rather not have to remember when and where it's necessary. Modifying
>> multi_to_wide feels more elegant.
>>
>> Suggestions?
>>
> In multi_to_wide, you can use IsTextUnicode(str,str.size,nil) to
> detect it is unicode or not.

Ok, I've added that check to multi_to_wide, thanks. I've left wide_to_multi 
alone for now because of some failures that cropped up in tests for win32-file. 
I think they happen because I've stripped out the nulls in one or two places, 
causing IsTextUnicode to return false unexpectedly. I'll look into it in a 
future release.

Anyway, the updated multi_to_wide is now part of the windows-pr 0.9.6 release, 
which I put out tonight.

I've also put out win32-api-1.2.1 finally (got my old laptop back).

Regards,

Dan


More information about the win32utils-devel mailing list