[Win32utils-devel] Making multi_to_wide and wide_to_multi smarter
phasis at gmail.com
Thu Nov 13 20:22:19 EST 2008
2008/11/13 Berger, Daniel <Daniel.Berger at qwest.com>:
> 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.
In multi_to_wide, you can use IsTextUnicode(str,str.size,nil) to
detect it is unicode or not.
More information about the win32utils-devel