e$B@.@%$G$9!#e(B
Tietew wrote:
C:…> ruby -e’puts “\u{3042 2603}”.encode(“utf-16le”)’
e$B$H$+$d$k$H2?$b=P$^$;$s$M!#e(B
e$B$9$G$K%o%$%IJ8;zNs$K$J$C$F$$$k$N$re(B MultiByteToWideChar e$B$K$+$1$F$b%5%]!<e(B
e$B%H$7$F$$$J$$$_$?$$$G$9!#e(B
e$B$`!"$=$&$J$N$G$9$+!#e(B
e$B$"$H!"EvA3$G$9$,e(B
C:…>ruby -e’puts “e$B$”$$$&$($*e(B".encode(“EUC-JP”)’
e$B!"!V!"!"!"%r!"%#!"%'e(B
e$B$3$s$J$N$b$@$a$G$9$M!#$d$O$j$3$3$Oe(B trascode e$B$N;EAH$_$r;H$C$?J}$,$h$$$N$Ge(B
e$B$O$J$$$+$H;W$$$^$9!#e(B
e$B$3$l$O;EMM$N$D$b$j$@$C$?$N$G$9$,!"$&!<$s!"$I$&$J$s$@$m$&!#e(B
Windows
e$B$K8B$C$F$O!“0J2<$,$G$-$A$c$&$N$b%”%j$+$J$!!"$H$b;W$$;O$a$F$-$^$7$?!#e(B
e$BB>$N4D6-$H$N7s$M9g$$$r9M$($k$HLB$$$b$"$j$^$9$,!#e(B
ruby19 -e’print"\u{2603}";print"\xA9".force_encoding(“iso-8859-1”);
print"\xa4\xa2\xa4\xa4".force_encoding
(“eucjp”)’
[e$B@c%@%k%^e(B][Copyright]e$B$"$$e(B
(e$B:#$N$H$3$mA4J8;z%;%C%H$Oe(B UTF-16LE e$B$KJQ49$G$-$^$9$h$M!)e(B)
e$B$$$(!“JQ49$G$-$k$b$N$r?t$($?$[$&$,Aa$/$F!“e(B
ISO 8859 e$B%7%j!<%:$HF|K\8l!“4Z9q8l!“e(BUTF-8, UTF-{16,32}{BE,LE}
e$B$@$1$G$9!#e(B
e$BCf9q7O!“BfOQ7O!”%?%$!”%&%/%i%$%J$”$?$j$OL5M}$G$9$M!”$”$He(B UTF-7
e$B$b!#e(B
e$B%a%8%c!<$J$H$3$m$@$He(B ASCII-8BIT e$B$,L5M}$G$9!#e(B
e$B$"$H$OF~NO7O!“e(BReadConsoleInputW() e$B$He(B GetCommandLineW() e$B$+!De(B
-EUTF-8 e$B$H$+$G5/F0$5$l$?>l9g$K8B$C$F;HMQ$9$k!”$H$+@)8f$7$J$$$HBLL$G$9$he(B
e$B$M$d$C$Q!#e(B
e$B$^$5$+!"e(BWindows e$B$N%3%^%s%I%W%m%s%W%H$G!“e(B
locale e$B$H0[$J$kJ8;zNs$r@8$GBG$DM&<T$O$$$J$$$H;W$&$s$G$9$,!“e(B
ruby19 -EEUC-JP -e’puts”\xa4\xa2”’ > foo.txt
e$B$N$h$&$K%(%9%1!<%W$7$F$@$H$J$$$H$b8@$$@Z$l$^$;$s$+$M$’!#e(B
Vista64 e$B$G$bBg>fIW$@$H!"$"$HCN$j$?$$$N$Oe(B Win9x e$B$G$9$+$M!#e(B
Win98SE e$B$G<B9T$7$h$&$H$7$?$N$G$9$,!"e(BVS2008 e$B$G%3%s%Q%$%k$7$?$ie(B
e$B%U%!%$%k$K$O?7$7$$%P!<%8%g%s$Ne(B Windows e$B$,I,MW$G$9!#e(B
Windows e$B$r%"%C%W%0%l!<%I$7$F$/$@$5$$!#e(B
e$B$H$+8@$o$l$F<B9T$G$-$^$;$s$G$7$?!#$C$F$+$=$s$J%(%i!<$r=P$95!G=$"$C$?$s$@!#e(B
VC++6 e$B$I$3$K;EIq$C$?$s$@$C$1!D!De(B
VC++6 e$B$G:n$k$HF0$/$N$G$9$+$M$’!&!&!&!)e(B
e$B0J2<!"e(Btranscode e$B$rMQ$$$?%Q%C%A$G$9!#e(B
Index: include/ruby/encoding.h
— include/ruby/encoding.h (revision 17818)
+++ include/ruby/encoding.h (working copy)
@@ -192,6 +192,7 @@
return ENC_DUMMY_P(ENC_FROM_ENCODING(enc));
}
+int rb_transcode_convertible(const char* from_encoding, const char*
to_encoding);
VALUE rb_str_transcode(VALUE str, VALUE to);
#endif /* RUBY_ENCODING_H */
Index: include/ruby/win32.h
— include/ruby/win32.h (revision 17818)
+++ include/ruby/win32.h (working copy)
@@ -547,6 +547,7 @@
int rb_w32_fclose(FILE*);
size_t rb_w32_read(int, void *, size_t);
size_t rb_w32_write(int, const void *, size_t);
+long rb_console_write_unicode(unsigned long, int);
int rb_w32_utime(const char *, const struct utimbuf *);
int WINAPI rb_w32_Sleep(unsigned long msec);
int rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD
timeout);
Index: io.c
— io.c (revision 17818)
+++ io.c (working copy)
@@ -14,6 +14,7 @@
#include “ruby/ruby.h”
#include “ruby/io.h”
#include “ruby/signal.h”
+#include “ruby/win32.h”
#include “vm_core.h”
#include <ctype.h>
#include <errno.h>
@@ -689,6 +690,11 @@
{
long len, n, r, l, offset = 0;
+#ifdef _WIN32
- len = rb_console_write_unicode(str, fptr->fd);
- if (len >= 0) return len;
+#endif
- /*
* If an external encoding was specified and it differs from
* the strings encoding then we must transcode before writing.
Index: transcode.c
===================================================================
— transcode.c (revision 17818)
+++ transcode.c (working copy)
@@ -119,6 +119,14 @@
return (rb_transcoder *)val;
}
+/*
-
-
/
+int
+rb_transcode_convertible(const char from_encoding, const char*
to_encoding)
+{
- return transcode_dispatch(from_encoding, to_encoding) ? TRUE :
FALSE;
+}
/*
- Transcoding engine logic
Index: win32/win32.c
===================================================================
— win32/win32.c (revision 17818)
+++ win32/win32.c (working copy)
@@ -12,6 +12,7 @@
#include “ruby/ruby.h”
#include “ruby/signal.h”
+#include “ruby/encoding.h”
#include “dln.h”
#include <fcntl.h>
#include <process.h>
@@ -3933,6 +3934,28 @@
return rb_w32_send(fd, buf, size, 0);
}
+long
+rb_console_write_unicode(VALUE str, int fd)
+{
- static int disable;
- HANDLE handle;
- DWORD dwMode, reslen;
-
- if (disable) return -1L;
-
- handle = (HANDLE)_osfhnd(fd);
- if (!GetConsoleMode(handle, &dwMode))
- return -1L;
-
- str = rb_str_transcode(str, rb_str_new2(“UTF-16LE”));
- if (!WriteConsoleW(handle, (LPWSTR)RSTRING_PTR(str),
RSTRING_LEN(str)/2, &reslen, NULL)) {
- if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
-
disable = TRUE;
- return -1L;
- }
- return (long)reslen;
+}
-
static int
unixtime_to_filetime(time_t time, FILETIME *ft)
{