Berger, Daniel
2008-Nov-13 14:50 UTC
[Win32utils-devel] Making multi_to_wide and wide_to_multi smarter
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? Thanks, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments.
Heesob Park
2008-Nov-14 01:22 UTC
[Win32utils-devel] Making multi_to_wide and wide_to_multi smarter
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. Regards, Park Heesob
Daniel Berger
2008-Nov-14 23:54 UTC
[Win32utils-devel] Making multi_to_wide and wide_to_multi smarter
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