[#15625] rb_hash_initialize — Takaaki Tateishi <ttate@...>

立石です.

22 messages 2002/01/04
[#15627] Re: rb_hash_initialize — matz@... (Yukihiro Matsumoto) 2002/01/04

まつもと ゆきひろです

[#15628] Re: rb_hash_initialize — Takaaki Tateishi <ttate@...> 2002/01/04

立石です.

[#15685] undefined method `inherited' for false (NameError) — WATANABE Hirofumi <eban@...>

わたなべです。

13 messages 2002/01/15
[#15686] Re: undefined method `inherited' for false (NameError) — nobu.nakada@... 2002/01/15

なかだです。

[#15757] 文字列→整数変換 — nobu.nakada@...

なかだです。

30 messages 2002/01/25

[#15830] [ 提案 ] puts, print 等を IO から分離 — UENO Katsuhiro <unnie@...>

うえのです。

14 messages 2002/01/31

[ruby-dev:15811] Re: [PATCH] improve on \G

From: nobu.nakada@...
Date: 2002-01-30 04:34:33 UTC
List: ruby-dev #15811
なかだです。

At Wed, 30 Jan 2002 08:56:05 +0900,
matz@ruby-lang.org (Yukihiro Matsumoto) wrote:
> |> M17Nの方はどうしようかなあ。isleadを使えば実現できるか。
> |
> |isleadだとマルチバイトの先頭かどうかですよね。それだけじゃUTF8
> |しかできません。必要なのは2バイト目以降にありうる値かどうかの判
> |定なので。
> 
> 名前が不適切かもしれませんが、isleadは1バイト目にしか現れな
> いバイトかどうかを判定します。

あ、ほんとだ、失礼。マルチバイトに限らないわけですね。

あと姑息な高速化。issjis2()がいまいちですが、これだけ昔からいい
手を思いつかなくて。


Index: m17n.c
===================================================================
RCS file: /cvs/ruby/src/ruby/Attic/m17n.c,v
retrieving revision 1.1.2.2
diff -u -2 -p -r1.1.2.2 m17n.c
--- m17n.c	2001/03/05 03:37:34	1.1.2.2
+++ m17n.c	2002/01/30 04:28:23
@@ -22,4 +22,6 @@
 #define uchar unsigned char
 
+#define CHAR_IN_RANGE(c, l, h) ((uchar)(c) - (uchar)(l) <= (uchar)(h) - (uchar)(l))
+
 static int num_encodings = 1;
 m17n_encoding **m17n_encoding_table = 0;
@@ -405,6 +407,5 @@ eucjp_islead(c, enc)
     const m17n_encoding *enc;
 {
-    if (0xa1 <= c && c <= 0xfe) return 0;
-    return 1;
+    return !CHAR_IN_RANGE(c, 0xa1, 0xfe);
 }
 
@@ -472,6 +473,6 @@ jis_mbcput(c, p, enc)
 }
 
-#define issjis1(c) ((0x81<=(c) && (c)<=0x9f) || (0xe0<=(c) && (c)<=0xfc))
-#define issjis2(c) ((0x40<=(c) && (c)<=0x7e) || (0x80<=(c) && (c)<=0xfc))
+#define issjis1(c) CHAR_IN_RANGE((c)^0x20, 0x81^0x20, 0xfc^0x20)
+#define issjis2(c) (CHAR_IN_RANGE((c), 0x40, 0xfc) && (c)!=0x7f)
 
 static int
@@ -566,6 +567,5 @@ utf8_islead(c, enc)
     const m17n_encoding *enc;
 {
-    if (c < 0x80 || (c & 0xc0) == 0xc0) return 1;
-    return 0;
+    return (c & 0xc0) != 0x80;
 }
 


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

In This Thread