[#1219] ruby animal — OZAWA Sakuro <crouton@...>

小澤さく@塩尻Internetです.

18 messages 1996/12/09

[#1256] ruby 0.99.4-961212 available — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです.

21 messages 1996/12/12
[#1257] Re: ruby 0.99.4-961212 available — Yasuo OHBA <jammy@...> 1996/12/12

大庭@SHLJapanです.

[#1258] Re: ruby 0.99.4-961212 available — matz@... (Yukihiro Matsumoto) 1996/12/12

まつもと ゆきひろです.

[#1259] Re: ruby 0.99.4-961212 available — WATANABE Hirofumi <watanabe@...> 1996/12/12

わたなべです.

[#1261] Re: ruby 0.99.4-961212 available — matz@... (Yukihiro Matsumoto) 1996/12/12

まつもと ゆきひろです.

[#1290] ruby 0.99.4-961217 will be available — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです.

32 messages 1996/12/17
[#1300] Re: ruby 0.99.4-961217 will be available — sinara@... 1996/12/17

原です。

[#1305] Re: ruby 0.99.4-961217 will be available — matz@... (Yukihiro Matsumoto) 1996/12/17

まつもと ゆきひろです.

[#1308] Re: ruby 0.99.4-961217 will be available — gougi@... (Shigeru Gougi) 1996/12/17

ごうぎ@TCIです。

[#1341] Re: ruby 0.99.4-961217 will be available — matz@... (Yukihiro Matsumoto) 1996/12/18

まつもと ゆきひろです.

[#1342] Re: ruby 0.99.4-961217 will be available — sinara@... 1996/12/18

原です。

[#1345] [BUG?] access string out of range — sinara@... 1996/12/18

原です。

[#1330] Re: Rational and Complex — Shin-ichiro Hara <sinara@...>

原です。

30 messages 1996/12/17
[#1335] Re: Rational and Complex — sinara@... 1996/12/18

原です。

[#1359] Re: Rational and Complex 1996/12/18

けいじゅ@SHLジャパンです.

[#1423] 配列への grep — (Dezawa Shin-ichiro) <dezawa@...>

出沢です

14 messages 1996/12/23

[#1469] wish ... — Noritugu Nakamura <nnakamur@...>

25 messages 1996/12/24
[#1470] Re: wish ... — matz@... (Yukihiro Matsumoto) 1996/12/24

まつもと ゆきひろです.

[ruby-list:1153] Re: Japanese and tr

From: Shin-ichiro Hara <sinara@...>
Date: 1996-12-01 10:30:00 UTC
List: ruby-list #1153
原です。

jtr を Perl 離れさせて書いてみました。

class String
  def upto(s)
    if length < 2 or self[0..-2] == s[0..-2]
      for c in self[-1] .. s[-1]
        yield(if length < 2 then '' else self[0..-2] end + c.chr)
      end
    end
  end

  def each_ch
    split(/(.-.)|/).each { |r|
      if r =~ /(.)-(.)/
        $1.upto($2) { |c| yield c }
      elsif r =~ /./
        yield r
      end
    }
  end
  
  def expand_ch
    a = []
    each_ch { |c| a.push c }
    a
  end
  
  def jtr(from, to)
    afrom = from.expand_ch
    ato = to.expand_ch
    self.split(//).collect{ |c|
      if i = afrom.index(c)
        if i < ato.size then ato[i] else ato[-1] end
      else
        c
      end
    }.join("")
  end
end


これを書いてて気がついたんですが、s = 'a' のとき、s[0..-2] も 'a'
になってますね。s[0..-2] は ''、s[0..-3] は nil などとするのは
どうでしょう。(上で length < 2 が必要なくなる。)

それから 'あ' .. 'お' みたいな Range をうまく定義するにはどうした
らいいでしょうか。
----------------------------------------------------------
                                                  原信一郎

In This Thread

Prev Next