[#7300] resolver を呼ばない UDPsocket#recvfrom — Toshihiko SHIMOKAWA / 下川俊彦 <toshi@...>

あんまり ruby-dev な話でも無いのですが、ちょっとした機能拡張の提案なので、

12 messages 1999/07/12
[#7321] Re: resolver を呼ばない UDPsocket#recvfrom — Toshihiko SHIMOKAWA / 下川俊彦 <toshi@...> 1999/07/15

From: Toshihiko SHIMOKAWA / 下川俊彦 <toshi@csce.kyushu-u.ac.jp>

[#7313] Ruby 1.3.5 — Yukihiro Matsumoto <matz@...>

Ruby 1.3.5 is out, check out:

59 messages 1999/07/15
[#7318] Re: Ruby 1.3.5 — WATANABE Hirofumi <watanabe@...> 1999/07/15

わたなべです.

[#7326] Re: Ruby 1.3.5 — Wakou Aoyama <wakou@...> 1999/07/15

青山です。

[#7331] Re: Ruby 1.3.5 — matz@... (Yukihiro Matsumoto) 1999/07/16

まつもと ゆきひろです

[#7340] Re: Ruby 1.3.5 — Wakou Aoyama <wakou@...> 1999/07/16

青山です。

[#7368] Re: Ruby 1.3.5 — matz@... (Yukihiro Matsumoto) 1999/07/19

まつもと ゆきひろです

[#7373] Re: Ruby 1.3.5 — Shin-ichiro Hara <sinara@...> 1999/07/19

原です。

[#7374] Re: Ruby 1.3.5 — matz@... (Yukihiro Matsumoto) 1999/07/19

まつもと ゆきひろです

[#7382] Re: Ruby 1.3.5 — Wakou Aoyama <wakou@...> 1999/07/19

青山です。

[#7386] Re: Ruby 1.3.5 — matz@... (Yukihiro Matsumoto) 1999/07/21

まつもと ゆきひろです

[#7388] Re: Ruby 1.3.5 — Wakou Aoyama <wakou@...> 1999/07/21

青山です。

[#7387] [PATCH]extconf.rb, tcltklib.c, and rubytest.rb for NetBSD — Ryo HAYASAKA <hayasaka@...21.u-aizu.ac.jp>

早坂@会津大学です。

10 messages 1999/07/21

[#7466] [PATCH] for djgpp — WATANABE Hirofumi <watanabe@...>

わたなべです.

21 messages 1999/07/29
[#7467] Re: [PATCH] for djgpp — Katsuyuki Komatsu <komatsu@...> 1999/07/29

小松です。

[ruby-dev:7418] jcode.rb

From: WATANABE Hirofumi <watanabe@...>
Date: 1999-07-26 04:33:48 UTC
List: ruby-dev #7418
わたなべです.

jcode.rb を高速化しました.
といってもオリジナルには遠くおよばないけど.

# jcode.rb - ruby code to handle japanese (EUC/SJIS) string

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

  def jlength
    self.split(//).length
  end

  alias original_succ succ
  private :original_succ

  def mbchar?
    case $KCODE[0]
    when ?s, ?S
      self =~ /[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]/n
    when ?e, ?E
      self =~ /[\xa1-\xfe][\xa1-\xfe]/n
    else
      false
    end
  end

  def succ
    if self[-2] and self[-2, 2].mbchar?
      s = self.dup
      s[-1] += 1
      s[-1] += 1 unless s[-2, 2].mbchar?
      return s
    else
      original_succ
    end
  end

  def upto(to)
    return if self > to

    curr = self
    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]
	  if (first+c.chr).mbchar?
	    yield self[0..-2]+c.chr
	  end
	end
      end
    else
      loop do
	yield curr
	return if curr == to
	curr = curr.succ
	return if curr.length > to.length
      end
    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

  HashCache = {}

  def expand_ch_hash from, to = ""
    key = from.intern.to_s + ":" + to.intern.to_s
    return HashCache[key] if HashCache.key? key
    afrom = _expand_ch(from)
    h = {}
    if to.length != 0
      ato = _expand_ch(to)
      afrom.each_with_index do |x,i| h[x] = ato[i] || ato[-1] end
    else
      afrom.each do |x| h[x] = true end
    end
    HashCache[key] = h
  end

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

  public

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

    pattern = /[#{bsquote(from)}]/
    if from[0] == ?^
      last = /.$/.match(to)[0]
      self.gsub!(pattern, last)
    else
      h = 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)
    pattern = /[#{bsquote(del)}]+/
    self.gsub!(pattern, '')
  end

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

  def squeeze!(del=nil)
    pattern =
      if 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 = /([#{bsquote(from)}])\1+/
    if from[0] == ?^
      last = /.$/.match(to)[0]
      self.gsub!(pattern, last)
    else
      h = 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!(/(?:.|\n)\z/, '')
  end

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

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

end
$VERBOSE = $vsave

In This Thread

Prev Next