From: matz@... (Yukihiro Matsumoto) Date: 1998-03-03T12:50:04+09:00 Subject: [ruby-list:6899] Re: inspect (mb string) まつもと ゆきひろです In message "[ruby-list:6860] inspect (mb string)" on 98/03/02, 青山 和光 writes: | |p [255,252,24,255,252,32,255,252,35,255,252,39].pack("c*") | |こんなのの出力がおかしかったので、inspect の日本語の扱いを jcode.rb |に移してみました。 jcodeをrequireしないと日本語を全く表示しないと言うのは寂しい ので,String#inspectの扱いをちょっと厳しくしてみました. まあ,現在の仕様でも普段は困らないと思いますが,気になる人は どうぞ. Index: regex.h =================================================================== RCS file: /home/cvsroot/ruby/regex.h,v retrieving revision 1.1.1.2 diff -u -1 -r1.1.1.2 regex.h --- regex.h 1998/01/16 12:19:12 1.1.1.2 +++ regex.h 1998/03/03 03:39:47 @@ -184,7 +184,21 @@ (re_syntax_options & RE_MBCTYPE_EUC \ - ? ((unsigned char) (c) >= 0x80) \ - : (re_syntax_options & RE_MBCTYPE_SJIS \ - ? (( 0x80 <= (unsigned char) (c) \ + ? ( 0xa1 <= (unsigned char) (c) \ + && (unsigned char) (c) <= 0xfe) \ + : (re_syntax_options & RE_MBCTYPE_SJIS \ + ? (( 0x81 <= (unsigned char) (c) \ && (unsigned char) (c) <= 0x9f) \ - || (0xe0 <= (unsigned char) (c))) \ + || ((0xe0 <= (unsigned char) (c)) \ + && (unsigned char) (c) <= 0xef)) \ + : 0)) + +#undef ismbchar2 +#define ismbchar2(c) \ + (re_syntax_options & RE_MBCTYPE_EUC \ + ? ( 0xa1 <= (unsigned char) (c) \ + && (unsigned char) (c) <= 0xfe) \ + : (re_syntax_options & RE_MBCTYPE_SJIS \ + ? (( 0x40 <= (unsigned char) (c) \ + && (unsigned char) (c) <= 0x7e) \ + || ((0x80 <= (unsigned char) (c)) \ + && (unsigned char) (c) <= 0xfc)) \ : 0)) Index: string.c =================================================================== RCS file: /home/cvsroot/ruby/string.c,v retrieving revision 1.1.1.2.2.7 diff -u -1 -r1.1.1.2.2.7 string.c --- string.c 1998/02/20 08:28:47 1.1.1.2.2.7 +++ string.c 1998/03/03 03:45:59 @@ -1377,3 +1377,3 @@ UCHAR c = *p++; - if (ismbchar(c) && p < pend) { + if (ismbchar(c) && p < pend && ismbchar2(*p)) { CHECK(2);