[#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:33225] Re: printf "%0x"

From: Nobuyoshi Nakada <nobu@...>
Date: 2008-01-20 20:45:17 UTC
List: ruby-dev #33225
なかだです。

At Mon, 21 Jan 2008 02:50:50 +0900,
Tanaka Akira wrote in [ruby-dev:33224]:
> printf の %0x に負の整数を与えると、値によって .. がついたり
> つかなかったりします。
> 
> % ./ruby -ve '[-0x40000000, -0x40000001].each {|v| printf "%0x\n", v }'
> ruby 1.9.0 (2008-01-19 revision 0) [i686-linux]
> ..fc0000000
> fbfffffff

それ以外にも、精度を指定すると妙な感じです。

$ ruby19 -ve 'printf "|%1$.4x|%1$04x|%1$6.4x|\n", -1'
ruby 1.9.0 (2008-01-19 revision 15119) [i686-linux]
|f..f|f..f|  f..f|

test/ruby/test_sprintf.rbには%bのテストしかないのですが、負の値
で".."がつかないというのはテストのほうがおかしくないでしょうか。


* sprintf.c (remove_sign_bits): returns pointer to the first char to
  be used, instead of copying.

* sprintf.c (rb_str_format): negative indicator dots should come
  before sign digits always.  [ruby-dev:33224]

Index: sprintf.c
===================================================================
--- sprintf.c	(revision 15146)
+++ sprintf.c	(working copy)
@@ -47,10 +47,6 @@ remove_sign_bits(char *str, int base)
 	}
     }
-    if (t > s) {
-	while (*t) *s++ = *t++;
-	*s = '\0';
-    }
 
-    return str;
+    return t;
 }
 
@@ -509,8 +505,9 @@ rb_str_format(int argc, const VALUE *arg
 	  case 'u':
 	    {
+		volatile VALUE tmp1;
 		volatile VALUE val = GETARG();
-		char fbuf[32], nbuf[64], *s, *t;
+		char fbuf[32], nbuf[64], *s;
 		const char *prefix = 0;
-		int sign = 0;
+		int sign = 0, dots = 0;
 		char sc = 0;
 		long v = 0;
@@ -613,17 +610,17 @@ rb_str_format(int argc, const VALUE *arg
 			sprintf(fbuf, "%%l%c", c);
 			sprintf(nbuf, fbuf, v);
+			s = nbuf;
 		    }
 		    else {
 			s = nbuf;
 			if (v < 0) {
-			    strcpy(s, "..");
-			    s += 2;
+			    dots = 1;
 			}
 			sprintf(fbuf, "%%l%c", *p == 'X' ? 'x' : *p);
-			sprintf(s, fbuf, v);
+			sprintf(++s, fbuf, v);
 			if (v < 0) {
 			    char d = 0;
 
-			    remove_sign_bits(s, base);
+			    s = remove_sign_bits(s, base);
 			    switch (base) {
 			      case 16:
@@ -633,10 +630,8 @@ rb_str_format(int argc, const VALUE *arg
 			    }
 			    if (d && *s != d) {
-				memmove(s+1, s, strlen(s)+1);
-				*s = d;
+				*--s = d;
 			    }
 			}
 		    }
-		    s = nbuf;
 		}
 		else {
@@ -659,5 +654,4 @@ rb_str_format(int argc, const VALUE *arg
 		    }
 		    else {
-                        volatile VALUE tmp1;
 			if (!RBIGNUM_SIGN(val)) {
 			    val = rb_big_clone(val);
@@ -667,24 +661,17 @@ rb_str_format(int argc, const VALUE *arg
 			s = RSTRING_PTR(tmp);
 			if (*s == '-') {
+			    dots = 1;
 			    if (base == 10) {
 				rb_warning("negative number for %%u specifier");
 			    }
-			    remove_sign_bits(++s, base);
-			    tmp = rb_str_new(0, 3+strlen(s));
-			    t = RSTRING_PTR(tmp);
-			    if (!(flags&(FPREC|FZERO))) {
-				strcpy(t, "..");
-				t += 2;
-			    }
+			    s = remove_sign_bits(++s, base);
 			    switch (base) {
 			      case 16:
-				if (s[0] != 'f') strcpy(t++, "f"); break;
+				if (s[0] != 'f') *--s = 'f'; break;
 			      case 8:
-				if (s[0] != '7') strcpy(t++, "7"); break;
+				if (s[0] != '7') *--s = '7'; break;
 			      case 2:
-				if (s[0] != '1') strcpy(t++, "1"); break;
+				if (s[0] != '1') *--s = '1'; break;
 			    }
-			    strcpy(t, s);
-			    s  = RSTRING_PTR(tmp);
 			}
 		    }
@@ -693,4 +680,8 @@ rb_str_format(int argc, const VALUE *arg
 		pos = -1;
 		len = strlen(s);
+		if (dots) {
+		    prec -= 2;
+		    width -= 2;
+		}
 
 		if (*p == 'X') {
@@ -722,4 +713,8 @@ rb_str_format(int argc, const VALUE *arg
 		}
 		CHECK(prec - len);
+		if (dots) {
+		    memcpy(&buf[blen], "..", 2);
+		    blen += 2;
+		}
 		if (!bignum && v < 0) {
 		    char c = sign_bits(base, p);
Index: test/ruby/test_sprintf.rb
===================================================================
--- test/ruby/test_sprintf.rb	(revision 15146)
+++ test/ruby/test_sprintf.rb	(working copy)
@@ -20,15 +20,15 @@ class TestSprintf < Test::Unit::TestCase
     assert_equal("0001", sprintf("%04b", 1))
     assert_equal("0010", sprintf("%04b", 2))
-    assert_equal("1111", sprintf("%04b", -1))
+    assert_equal("..11", sprintf("%04b", -1))
 
     assert_equal("0000", sprintf("%.4b", 0))
     assert_equal("0001", sprintf("%.4b", 1))
     assert_equal("0010", sprintf("%.4b", 2))
-    assert_equal("1111", sprintf("%.4b", -1))
+    assert_equal("..11", sprintf("%.4b", -1))
 
     assert_equal("  0000", sprintf("%6.4b", 0))
     assert_equal("  0001", sprintf("%6.4b", 1))
     assert_equal("  0010", sprintf("%6.4b", 2))
-    assert_equal("  1111", sprintf("%6.4b", -1))
+    assert_equal("  ..11", sprintf("%6.4b", -1))
 
     assert_equal(" 0b0", sprintf("%#4b", 0))
@@ -40,15 +40,15 @@ class TestSprintf < Test::Unit::TestCase
     assert_equal("0b01", sprintf("%#04b", 1))
     assert_equal("0b10", sprintf("%#04b", 2))
-    assert_equal("0b11", sprintf("%#04b", -1))
+    assert_equal("0b..1", sprintf("%#04b", -1))
 
     assert_equal("0b0000", sprintf("%#.4b", 0))
     assert_equal("0b0001", sprintf("%#.4b", 1))
     assert_equal("0b0010", sprintf("%#.4b", 2))
-    assert_equal("0b1111", sprintf("%#.4b", -1))
+    assert_equal("0b..11", sprintf("%#.4b", -1))
 
     assert_equal("0b0000", sprintf("%#6.4b", 0))
     assert_equal("0b0001", sprintf("%#6.4b", 1))
     assert_equal("0b0010", sprintf("%#6.4b", 2))
-    assert_equal("0b1111", sprintf("%#6.4b", -1))
+    assert_equal("0b..11", sprintf("%#6.4b", -1))
 
     assert_equal("+0", sprintf("%+b", 0))


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

In This Thread