[#8168] {literal}#[]= — EGUCHI Osamu <eguchi@...>

えぐち@エスアンドイーです。

16 messages 1999/11/01
[#8172] Re: {literal}#[]= — matz@... (Yukihiro Matsumoto) 1999/11/01

まつもと ゆきひろです

[#8176] Multiple self assignment — Kazuhiro Yoshida <moriq.kazuhiro@...>

もりきゅうです。

35 messages 1999/11/01
[#8178] Re: Multiple self assignment — matz@... (Yukihiro Matsumoto) 1999/11/01

まつもと ゆきひろです

[#8212] Re: Multiple self assignment — Kazuhiro Yoshida <moriq.kazuhiro@...> 1999/11/02

もりきゅうです。

[#8213] Re: Multiple self assignment — matz@... (Yukihiro Matsumoto) 1999/11/03

まつもと ゆきひろです

[#8232] 例外を処理する 2 項演算子 — Kazunori NISHI <kazunori@...> 1999/11/05

西@九大です。

[#8233] Re: 例外を処理する 2 項演算子 — matz@... (Yukihiro Matsumoto) 1999/11/05

まつもと ゆきひろです

[#8236] Re: 例外を処理する 2 項演算子 — Kazuhiro Yoshida <moriq.kazuhiro@...> 1999/11/05

もりきゅうです。

[#8266] Re: 例外を処理する 2 項演算子 — EGUCHI Osamu <eguchi@...> 1999/11/07

えぐち@エスアンドイー です。

[#8269] Re: 例外を処理する 2 項演算子 — gotoken@... (GOTO Kentaro) 1999/11/07

In message "[ruby-dev:8266] Re: 例外を処理する 2 項演算子"

[#8271] Re: 例外を処理する 2 項演算子 — matz@... (Yukihiro Matsumoto) 1999/11/08

まつもと ゆきひろです

[#8274] Re: 例外を処理する 2 項演算子 — keiju@... (石塚圭樹) 1999/11/08

けいじゅ@日本ラショナルソフトウェアです.

[#8204] Re: [ruby-list:18281] Re: アクセス制御について — Shugo Maeda <shugo@...>

前田です。

12 messages 1999/11/02
[#8205] Re: [ruby-list:18281] Re: アクセス制御について — Shin-ichiro Hara <sinara@...> 1999/11/02

原です。

[#8315] Re: [ruby-list:18601] Re: [REQ] [].grep(pat){} ==> [].grep(pat).collect{} — Kazunori NISHI <kazunori@...>

西@九大です。

37 messages 1999/11/15
[#8316] Re: [ruby-list:18601] Re: [REQ] [].grep(pat){} ==> [].grep(pat).collect{} — matz@... (Yukihiro Matsumoto) 1999/11/15

まつもと ゆきひろです

[#8369] Re: [REQ] [].grep(pat){} ==> [].grep(pat).collect{} — Koji Arai <JCA02266@...> 1999/11/18

新井です。

[#8374] Re: [REQ] [].grep(pat){} ==> [].grep(pat).collect{} — matz@... (Yukihiro Matsumoto) 1999/11/18

まつもと ゆきひろです

[#8384] Re: [REQ] [].grep(pat){} ==> [].grep(pat).collect{} — Koji Arai <JCA02266@...> 1999/11/19

新井です。

[#8405] 1.4.3 (Re: Re: [REQ] [].grep(pat){} ==> [].grep(pat).collect{}) — matz@... (Yukihiro Matsumoto) 1999/11/24

[#8319] Re: Exception handling — Jun Adachi <adachi@...>

安達@沖データと申します。

21 messages 1999/11/16
[#8350] Re: Exception handling — Kazunori NISHI <kazunori@...> 1999/11/17

西@九大です。

[#8446] [REQ] {enumerable, integer, range}.rand — Kazunori NISHI <kazunori@...>

西@九大です。

37 messages 1999/11/29
[#8449] Re: [REQ] {enumerable, integer, range}.rand — matz@... (Yukihiro Matsumoto) 1999/11/30

まつもと ゆきひろです

[#8463] Re: [REQ] {enumerable, integer, range}.rand — Kazunori NISHI <kazunori@...> 1999/11/30

西@九大です。

[#8474] Re: [REQ] {enumerable, integer, range}.rand — matz@... (Yukihiro Matsumoto) 1999/12/01

まつもと ゆきひろです

[#8476] Re: [REQ] {enumerable, integer, range}.rand — Kazunori NISHI <kazunori@...> 1999/12/01

西@九大です。

[#8487] Re: [REQ] {enumerable, integer, range}.rand — matz@... (Yukihiro Matsumoto) 1999/12/02

まつもと ゆきひろです

[#8494] Re: [REQ] {enumerable, integer, range}.rand — Kazunori NISHI <kazunori@...> 1999/12/02

西@九大です。

[#8451] new Hash (Re: [ruby-list:19043]) — Wakou Aoyama <wakou@...>

青山です。

18 messages 1999/11/30

[ruby-dev:8166] jcode.rb for UTF-8

From: WATANABE Hirofumi <Hirofumi.Watanabe@...>
Date: 1999-11-01 06:00:22 UTC
List: ruby-dev #8166
わたなべです.

jcode.rb を UTF-8 対応してみました(ちょっと怪しい部分もあるけど).
ついでに each_char というメソッドも追加.

# jcode.rb - ruby code to handle japanese (EUC/SJIS/UTF-8) string

$vsave, $VERBOSE = $VERBOSE, FALSE
class String
  printf STDERR, "feel free for some warnings:\n" if $VERBOSE

  PATTERN_SJIS = '[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]'
  PATTERN_EUC = '[\xa1-\xfe][\xa1-\xfe]'
  PATTERN_UTF8 = '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]'

  RE_SJIS = Regexp.new(PATTERN_SJIS, 'n')
  RE_EUC = Regexp.new(PATTERN_EUC, 'n')
  RE_UTF8 = Regexp.new(PATTERN_UTF8, 'n')

  SUCC = {}
  SUCC['s'] = Hash.new(1)
  for i in 0 .. 0x3f
    SUCC['s'][i.chr] = 0x40 - i
  end
  SUCC['s']["\x7e"] = 0x80 - 0x7e
  SUCC['s']["\xfd"] = 0x100 - 0xfd
  SUCC['s']["\xfe"] = 0x100 - 0xfe
  SUCC['s']["\xff"] = 0x100 - 0xff
  SUCC['e'] = Hash.new(1)
  for i in 0 .. 0xa0
    SUCC['e'][i.chr] = 0xa1 - i
  end
  SUCC['e']["\xfe"] = 2
  SUCC['u'] = Hash.new(1)
  for i in 0 .. 0x7f
    SUCC['u'][i.chr] = 0x80 - i
  end
  SUCC['u']["\xbf"] = 0x100 - 0xbf

  def mbchar?
    case $KCODE[0]
    when ?s, ?S
      self =~ RE_SJIS
    when ?e, ?E
      self =~ RE_EUC
    when ?u, ?U
      self =~ RE_UTF8
    else
      nil
    end
  end

  def end_regexp
    case $KCODE[0]
    when ?s, ?S
      /#{PATTERN_SJIS}$/o
    when ?e, ?E
      /#{PATTERN_EUC}$/o
    when ?u, ?U
      /#{PATTERN_UTF8}$/o
    else
      /.$/o
    end
  end

  alias original_succ! succ!
  private :original_succ!

  alias original_succ succ
  private :original_succ

  def succ!
    reg = end_regexp
    if self =~ reg
      succ_table = SUCC[$KCODE[0,1].downcase]
      begin
	self[-1] += succ_table[self[-1]]
	self[-2] += 1 if self[-1] == 0
      end while self !~ reg
      self
    else
      original_succ!
    end
  end

  def succ
    (str = self.dup).succ! or str
  end

  def upto(to)
    return if self > to

    curr = self
    loop do
      yield curr
      return if curr == to
      curr = curr.succ
      return if curr.length > to.length
    end
    return nil
  end

  private

  def _expand_ch str
    a = []
    str.scan(/(.|\n)-(.|\n)|(.|\n)/) do |r|
      if $3
	a.push $3
      elsif $1.length != $2.length
 	next
      elsif $1.length == 1
 	$1[0].upto($2[0]) { |c| a.push c.chr }
      else
 	$1.upto($2) { |c| a.push c }
      end
    end
    a
  end

  def expand_ch_hash from, to
    h = {}
    afrom = _expand_ch(from)
    ato = _expand_ch(to)
    afrom.each_with_index do |x,i| h[x] = ato[i] || ato[-1] end
    h
  end

  def bsquote(str)
    str.gsub(/\\/, '\\\\\\\\')
  end

  HashCache = {}
  TrPatternCache = {}
  DeletePatternCache = {}
  SqueezePatternCache = {}

  public

  def tr!(from, to)
    return self.delete!(from) if to.length == 0

    pattern = TrPatternCache[from] ||= /[#{bsquote(from)}]/
    if from[0] == ?^
      last = /.$/.match(to)[0]
      self.gsub!(pattern, last)
    else
      h = HashCache[from + "::" + to] ||= expand_ch_hash(from, to)
      self.gsub!(pattern) do |c| h[c] end
    end
  end

  def tr(from, to)
    (str = self.dup).tr!(from, to) or str
  end

  def delete!(del)
    self.gsub!(DeletePatternCache[del] ||= /[#{bsquote(del)}]+/, '')
  end

  def delete(del)
    (str = self.dup).delete!(del) or str
  end

  def squeeze!(del=nil)
    pattern =
      if del
	SqueezePatternCache[del] ||= /([#{bsquote(del)}])\1+/
      else
	/(.|\n)\1+/
      end
    self.gsub!(pattern, '\1')
  end

  def squeeze(del=nil)
    (str = self.dup).squeeze!(del) or str
  end

  def tr_s!(from, to)
    return self.delete!(from) if to.length == 0

    pattern = SqueezePatternCache[from] ||= /([#{bsquote(from)}])\1+"/
    if from[0] == ?^
      last = /.$/.match(to)[0]
      self.gsub!(pattern, last)
    else
      h = HashCache[from + "::" + to] ||= expand_ch_hash(from, to)
      self.gsub!(pattern) do h[$1] end
    end
  end

  def tr_s(from, to)
    (str = self.dup).tr_s!(from,to) or str
  end

  def chop!
    self.gsub!(/(?:.|\r?\n)\z/, '')
  end

  def chop
    (str = self.dup).chop! or str
  end

  def jlength
    self.gsub(/[^\Wa-zA-Z_\d]/, ' ').length
  end
  alias jsize jlength

  def jcount(str)
    self.delete("^#{str}").jlength
  end

  def each_char
    if iterator?
      scan(/./) do |x|
        yield x
      end
    else
      scan(/./)
    end
  end

end
$VERBOSE = $vsave

In This Thread

Prev Next