From: WATANABE Hirofumi Date: 1997-04-14T13:35:13+09:00 Subject: [ruby-list:2809] jcode.rb わたなべです. SJIS で for i in 'ア' .. 'ン' print i end print "\n" なんてことすると「ミ」と「ム」の間になぞの文字が出てくるのが 厭でちょっといじってみました. --- ../ruby-1.0-970411/lib/jcode.rb Sat Feb 15 00:50:47 1997 +++ lib/jcode.rb Mon Apr 14 09:56:46 1997 @@ -10,10 +10,21 @@ alias original_succ succ private :original_succ + def mbchar?(c) + if $KCODE =~ /^s/i + c =~ /[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]/n + elsif $KCODE =~ /^e/i + c =~ /[\xa1-\xfe][\xa1-\xfe]/n + else + FALSE + end + end + def succ if self[-2] && self[-2] & 0x80 != 0 s = self.dup s[-1] += 1 + s[-1] += 1 if !mbchar?(s) return s else original_succ @@ -27,8 +38,11 @@ tail = self[-2..-1] if tail.length == 2 and tail =~ /^.$/ then if self[0..-2] == to[0..-2] + first = self[-2].chr for c in self[-1] .. to[-1] - yield self[0..-2]+c.chr + if mbchar?(first+c.chr) + yield self[0..-2]+c.chr + end end end else