From: "K.Kosako" Date: 2001-12-05T15:10:49+09:00 Subject: [ruby-dev:15360] Re: Regexp in UTF-8 (Re: Regexp literal and Regexp.new()) TAKAHASHI Masayoshiさんの<200112050430.NAA14218@mx.inac.co.jp>から > UTF-8の正規表現で、[]がうまく動かないようです。 > シングルバイト換算になってしまってるのかな? と思いきや > そうでもなさそうですし。 > > スクリプト: > str = "soci\303\251t\303\251" > reg = Regexp.new("[\303\251-\303\254]", nil, "u") > p str.gsub(reg, "?") > reg = Regexp.new("[\303\251]", nil, "u") > p str.gsub(reg, "?") > reg = Regexp.new("\303\251", nil, "u") > p str.gsub(reg, "?") この問題については、多分これで直っていると思います。 --- regex.c.orig Tue Oct 30 17:42:21 2001 +++ regex.c Wed Dec 5 15:07:01 2001 @@ -477,7 +477,7 @@ } while(0) #define WC2MBC1ST(c) \ - ((c<0x100)?(c):((current_mbctype != MBCTYPE_UTF8)?(((c)>>8)&0xff):utf8_firstbyte(c))) + ((current_mbctype != MBCTYPE_UTF8) ? ((c<0x100) ? (c) : (((c)>>8)&0xff)) : utf8_firstbyte(c)) static unsigned int utf8_firstbyte(c) -- 小迫@ソフネック 渋谷区恵比寿1-15-1