[#32945] Shift_JIS variants and UTF-16 support — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

22 messages 2008/01/07
[#32953] Re: Shift_JIS variants and UTF-16 support — Martin Duerst <duerst@...> 2008/01/07

中村さん、こんにちは。

[#32955] Re: Shift_JIS variants and UTF-16 support — Yukihiro Matsumoto <matz@...> 2008/01/07

まつもと ゆきひろです

[#32959] Re: Shift_JIS variants and UTF-16 support — "NARUSE, Yui" <naruse@...> 2008/01/07

成瀬です。

[#32960] Re: Shift_JIS variants and UTF-16 support — Yukihiro Matsumoto <matz@...> 2008/01/07

まつもと ゆきひろです

[#32992] ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — "NARUSE, Yui" <naruse@...>

成瀬です。

18 messages 2008/01/08
[#32994] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — Yukihiro Matsumoto <matz@...> 2008/01/09

まつもと ゆきひろです

[#32995] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — Martin Duerst <duerst@...> 2008/01/09

At 18:13 08/01/09, Yukihiro Matsumoto wrote:

[#33011] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — "NARUSE, Yui" <naruse@...> 2008/01/11

成瀬です。

[#33012] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — Yukihiro Matsumoto <matz@...> 2008/01/11

まつもと ゆきひろです

[#33014] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — "NARUSE, Yui" <naruse@...> 2008/01/11

成瀬です。

[#33015] Re: ASCII is alias of US-ASCII; replica of dummy encoding is not a dummy — Yukihiro Matsumoto <matz@...> 2008/01/11

まつもと ゆきひろです

[#33239] Re: [ruby-cvs:22386] Ruby:r15149 (trunk): * string.c (rb_str_each_char): move forward. — Tanaka Akira <akr@...>

In article <200801210259.m0L2x3CW017171@ci.ruby-lang.org>,

11 messages 2008/01/21
[#33240] Re: [ruby-cvs:22386] Ruby:r15149 (trunk): * string.c (rb_str_each_char): move forward. — Nobuyoshi Nakada <nobu@...> 2008/01/21

なかだです。

[#33303] Time#strftimeのエンコーディング — rubikitch@...

るびきちです。

13 messages 2008/01/23
[#33305] Re: Time#strftimeのエンコーディング — Yukihiro Matsumoto <matz@...> 2008/01/23

まつもと ゆきひろです

[#33368] summary of script encoding — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

22 messages 2008/01/25
[#33375] Re: summary of script encoding — Yukihiro Matsumoto <matz@...> 2008/01/25

まつもと ゆきひろです

[#33376] Re: summary of script encoding — "U.Nakamura" <usa@...> 2008/01/25

こんにちは、なかむら(う)です。

[#33387] HashからStructを作る — rubikitch@...

るびきちです。

19 messages 2008/01/25
[#33455] Re: HashからStructを作る — Yukihiro Matsumoto <matz@...> 2008/01/28

まつもと ゆきひろです

[#33505] Re: HashからStructを作る — rubikitch@... 2008/01/29

From: Yukihiro Matsumoto <matz@ruby-lang.org>

[#33507] Re: HashからStructを作る — Yukihiro Matsumoto <matz@...> 2008/01/29

まつもと ゆきひろです

[#33508] Re: HashからStructを作る — rubikitch@... 2008/01/29

From: Yukihiro Matsumoto <matz@ruby-lang.org>

[#33433] Win32OLE: set encoding to OLE string — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

16 messages 2008/01/28

[#33461] Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...>

=1B$B?9ED$H?=3D$7$^$9!#=1B(B

19 messages 2008/01/28
[#33473] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — Nobuyoshi Nakada <nobu@...> 2008/01/28

なかだです。

[#33503] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...> 2008/01/29

森田です。

[#33514] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — Nobuyoshi Nakada <nobu@...> 2008/01/29

なかだです。

[#33518] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...> 2008/01/30

森田です。

[#33545] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — Ryutaro Amano <wn9r-amn@...> 2008/01/31

天野竜太郎と申します。

[#33546] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...> 2008/01/31

森田です。

[#33547] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — Ryutaro Amano <wn9r-amn@...> 2008/01/31

天野です。

[#33551] Re: Failed to make ruby-1.8.6-p111 on MacOSX 10.5(Leopard) — MORITA Hideyuki <h-morita@...> 2008/01/31

森田です。

[#33488] 現在の script encoding の値を得る方法は? — Hidetoshi NAGAI <nagai@...>

永井@知能.九工大です.

20 messages 2008/01/29
[#33491] Re: 現在の script encoding の値を得る方法は? — Yukihiro Matsumoto <matz@...> 2008/01/29

まつもと ゆきひろです

[#33500] Re: 現在の script encoding の値を得る方法は? — Hidetoshi NAGAI <nagai@...> 2008/01/29

永井@知能.九工大です.

[#33501] Re: 現在の script encoding の値を得る方法は? — "NARUSE, Yui" <naruse@...> 2008/01/29

成瀬です。

[#33515] Re: 現在の script encoding の値を得る方法は? — Hidetoshi NAGAI <nagai@...> 2008/01/30

永井@知能.九工大です.

[#33516] Re: 現在の script encoding の値を得る方法は? — "NARUSE, Yui" <naruse@...> 2008/01/30

成瀬です。

[#33519] Re: 現在の script encoding の値を得る方法は? — Hidetoshi NAGAI <nagai@...> 2008/01/30

永井@知能.九工大です.

[#33522] Re: 現在の script encoding の値を得る方法は? — "NARUSE, Yui" <naruse@...> 2008/01/30

成瀬です。

[ruby-dev:33317] Re: Time#strftimeのエンコーディング

From: Nobuyoshi Nakada <nobu@...>
Date: 2008-01-23 10:32:03 UTC
List: ruby-dev #33317
なかだです。

At Wed, 23 Jan 2008 16:43:38 +0900,
Kazuhiro NISHIYAMA wrote in [ruby-dev:33316]:
> > とりあえずformat.encodingを無視するのはまずかろうと思われるので、
> > 前者にしておきました。strftimeが非ASCIIを返すことがあるとしても、
> > strftimeの終了時にはすでにformatと混じってしまっているわけで、ど
> > うしたもんでしょうね。
> 
> strftime(format.encode(locale)).encode(format.encoding)
> という感じでstrftimeにはlocaleのencodingでわたして
> Time#strftimeの返値はformatのencodingになっていると
> うれしい気がするのですが、どうでしょうか?

こんなとこですか。

$ ./ruby --arch=.i386-mingw32 -Ke -ve 'p Time.now.strftime("\xc6\xfc\xcb\xdc/%Z")'
ruby 1.9.0 (2008-01-23 revision 15187) [i386-mingw32]
"日本/東京 (標準時)"


Index: time.c
===================================================================
--- time.c	(revision 15187)
+++ time.c	(working copy)
@@ -11,4 +11,5 @@
 
 #include "ruby/ruby.h"
+#include "ruby/encoding.h"
 #include <sys/types.h>
 #include <time.h>
@@ -2072,4 +2073,5 @@ time_strftime(VALUE time, VALUE format)
     long len;
     VALUE str;
+    rb_encoding *enc, *lenc;
 
     GetTimeval(time, tobj);
@@ -2081,6 +2083,75 @@ time_strftime(VALUE time, VALUE format)
     fmt = RSTRING_PTR(format);
     len = RSTRING_LEN(format);
+    enc = rb_enc_get(format);
+    lenc = rb_locale_encoding();
     if (len == 0) {
 	rb_warning("strftime called with empty format string");
+	str = rb_str_new(0, 0);
+    }
+    else if (enc != lenc && !rb_enc_str_asciionly_p(format)) {
+	VALUE strenc = rb_enc_from_encoding(enc), tmp;
+	const char *p = fmt, *pe = fmt + len, *start = p;
+	char *s;
+	int c, n;
+
+	str = rb_enc_str_new(0, 0, enc);
+	while (p < pe) {
+	    int n2 = 0;
+	    start = p;
+	    while ((c = rb_enc_ascget(p, pe, &n, enc)) != 0 && c != '%' &&
+		   (p += c < 0 ? rb_enc_mbclen(p, pe, enc) : n) < pe);
+	    switch (c) {
+	      case 0:
+		p += n;
+		break;
+	      case '%':
+		if (p+n >= pe) {
+		    p = pe;
+		}
+		else if (rb_enc_ascget(p+n, pe, &n2, enc) == '%') {
+		    p += n;
+		    n = n2;
+		    c = -1;
+		}
+		break;
+	    }
+	    rb_str_cat(str, start, p - start);
+	    p += n;
+	    switch (c) {
+	      case 0:
+		while ((c = rb_enc_ascget(p, pe, &n, enc)) == 0 &&
+		       (p += n) < pe);
+		break;
+	      case '%':
+		start = p;
+		len = 1;
+		while ((c = rb_enc_ascget(p, pe, &n, enc)) > 0) {
+		    p += n;
+		    ++len;
+		    if (ISALPHA(c)) break;
+		}
+		s = buf = ALLOC_N(char, len+1);
+		*s++ = '%';
+		p = start;
+		while ((c = rb_enc_ascget(p, pe, &n, enc)) > 0) {
+		    *s++ = c;
+		    p += n;
+		    if (ISALPHA(c)) break;
+		}
+		*s = '\0';
+		s = buf;
+		buf = buffer;
+		len = rb_strftime(&buf, s, &tobj->tm);
+		free(s);
+		tmp = rb_enc_str_new(buf, len, lenc);
+		if (buf != buffer) {
+		    free(buf);
+		    buf = buffer;
+		}
+		tmp = rb_funcall(tmp, rb_intern("encode"), 1, strenc);
+		rb_str_append(str, tmp);
+		break;
+	    }
+	}
     }
     else if (strlen(fmt) < len) {
@@ -2088,5 +2159,5 @@ time_strftime(VALUE time, VALUE format)
 	const char *p = fmt, *pe = fmt + len;
 
-	str = rb_str_new(0, 0);
+	str = rb_enc_str_new(0, 0, enc);
 	while (p < pe) {
 	    len = rb_strftime(&buf, p, &tobj->tm);
@@ -2100,12 +2171,10 @@ time_strftime(VALUE time, VALUE format)
 	    if (p > fmt) rb_str_cat(str, fmt, p - fmt);
 	}
-	return str;
     }
     else {
 	len = rb_strftime(&buf, RSTRING_PTR(format), &tobj->tm);
+	str = rb_enc_str_new(buf, len, enc);
+	if (buf != buffer) free(buf);
     }
-    str = rb_str_new(buf, len);
-    if (buf != buffer) free(buf);
-    rb_enc_copy(str, format);
     return str;
 }


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread