ruby-changes:30343
From: nobu <ko1@a...>
Date: Tue, 6 Aug 2013 17:02:30 +0900 (JST)
Subject: [ruby-changes:30343] nobu:r42397 (trunk): win32.c: conversion from WCHAR
nobu 2013-08-06 17:02:20 +0900 (Tue, 06 Aug 2013) New Revision: 42397 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42397 Log: win32.c: conversion from WCHAR * win32/win32.c (rb_w32_conv_from_wchar): use WideCharToMultiByte(), as like as mbstr_to_wstr(), in the first step of the convertion from WCHAR. Modified files: trunk/ChangeLog trunk/win32/win32.c _______________________________________________ ruby-cvs mailing list ruby-cvs@r... http://lists.ruby-lang.org/cgi-bin/mailman/listinfo/ruby-cvs Index: ChangeLog =================================================================== --- ChangeLog (revision 42396) +++ ChangeLog (revision 42397) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Aug 6 17:02:17 2013 Nobuyoshi Nakada <nobu@r...> + + * win32/win32.c (rb_w32_conv_from_wchar): use WideCharToMultiByte(), + as like as mbstr_to_wstr(), in the first step of the convertion from + WCHAR. + Tue Aug 6 16:14:32 2013 Shugo Maeda <shugo@r...> * vm_eval.c (eval_string_with_cref): copy cref to limit the scope of Index: win32/win32.c =================================================================== --- win32/win32.c (revision 42396) +++ win32/win32.c (revision 42397) @@ -2040,20 +2040,31 @@ win32_direct_conv(const WCHAR *file, str https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L2040 VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc) { - static rb_encoding *utf16 = (rb_encoding *)-1; VALUE src; + long len = lstrlenW(wstr); + int encindex = ENC_TO_ENCINDEX(enc); - if (utf16 == (rb_encoding *)-1) { - utf16 = rb_enc_find("UTF-16LE"); - if (utf16 == rb_ascii8bit_encoding()) - utf16 = NULL; + if (encindex == ENCINDEX_UTF_16LE) { + return rb_enc_str_new((char *)wstr, len * sizeof(WCHAR), enc); } - if (!utf16) - /* maybe miniruby */ - return Qnil; - - src = rb_enc_str_new((char *)wstr, lstrlenW(wstr) * sizeof(WCHAR), utf16); - return rb_str_encode(src, rb_enc_from_encoding(enc), ECONV_UNDEF_REPLACE, Qnil); + else { +#if SIZEOF_INT < SIZEOF_LONG +# error long should equal to int on Windows +#endif + int clen = rb_long2int(len); + len = WideCharToMultiByte(CP_UTF8, 0, wstr, clen, NULL, 0, NULL, NULL); + src = rb_enc_str_new(0, len, enc); + WideCharToMultiByte(CP_UTF8, 0, wstr, clen, RSTRING_PTR(src), len, NULL, NULL); + } + switch (encindex) { + case ENCINDEX_ASCII: + case ENCINDEX_US_ASCII: + /* assume UTF-8 */ + case ENCINDEX_UTF_8: + /* do nothing */ + return src; + } + return rb_str_conv_enc_opts(src, NULL, enc, ECONV_UNDEF_REPLACE, Qnil); } /* License: Ruby's */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/