[#22195] IO::for_io and TCPServer#bind — GOTOU Yuuzou <gotoyuzo@...>

test_drb が IPv4 射影アドレスが有効な環境でないと動かないこ

16 messages 2003/12/09
[#22198] Re: IO::for_io and TCPServer#bind — matz@... (Yukihiro Matsumoto) 2003/12/09

まつもと ゆきひろです

[#22205] yet another inconsistency about EOF between StringIO and IO — Tanaka Akira <akr@...17n.org>

StringIO の

24 messages 2003/12/10
[#22206] Re: yet another inconsistency about EOF between StringIO and IO — nobu.nakada@... 2003/12/10

なかだです。

[#22214] Re: yet another inconsistency about EOF between StringIO and IO — Tanaka Akira <akr@...17n.org> 2003/12/10

In article <200312100725.hBA7P8Ac011112@sharui.nakada.kanuma.tochigi.jp>,

[#22222] Re: yet another inconsistency about EOF between StringIO and IO — nobu.nakada@... 2003/12/10

なかだです。

[#22234] Re: yet another inconsistency about EOF between StringIO and IO — Masahiro Sakai (酒井政裕) <sakai@...> 2003/12/11

さかいといいます。

[#22262] Re: yet another inconsistency about EOF between StringIO and IO — Tanaka Akira <akr@...17n.org> 2003/12/13

In article <20031211.214041.71090239.sakai@tom.sfc.keio.ac.jp>,

[#22328] Re: yet another inconsistency about EOF between StringIO and IO — Tanaka Akira <akr@...17n.org> 2003/12/23

In article <87k751dzyf.fsf@serein.a02.aist.go.jp>,

[#22331] Re: yet another inconsistency about EOF between StringIO and IO — matz@... (Yukihiro Matsumoto) 2003/12/23

まつもと ゆきひろです

[#22334] Re: yet another inconsistency about EOF between StringIO and IO — Tanaka Akira <akr@...17n.org> 2003/12/23

In article <1072167374.096702.13473.nullmailer@picachu.netlab.jp>,

[#22343] Re: yet another inconsistency about EOF between StringIO and IO — matz@... (Yukihiro Matsumoto) 2003/12/23

まつもと ゆきひろです

[#22330] core dump with ungetc — Tanaka Akira <akr@...17n.org>

次のように ungetc を使うと core を吐く場合があります。

14 messages 2003/12/23
[#22332] Re: core dump with ungetc — nobu.nakada@... 2003/12/23

なかだです。

[#22366] `to_s': method `to_s' overridden (TypeError) — Tanaka Akira <akr@...17n.org>

そういえば、次の `to_s': method `to_s' overridden (TypeError) というの

12 messages 2003/12/24

[#22385] Tk.callback_break causes seg-fault or hang-up — Hidetoshi NAGAI <nagai@...>

永井@知能.九工大です.

19 messages 2003/12/24
[#22387] Re: Tk.callback_break causes seg-fault or hang-up — matz@... (Yukihiro Matsumoto) 2003/12/24

まつもと ゆきひろです

[#22393] Re: Tk.callback_break causes seg-fault or hang-up — Hidetoshi NAGAI <nagai@...> 2003/12/24

永井@知能.九工大です.

[#22395] Re: Tk.callback_break causes seg-fault or hang-up — matz@... (Yukihiro Matsumoto) 2003/12/24

まつもと ゆきひろです

[#22396] Re: Tk.callback_break causes seg-fault or hang-up — matz@... (Yukihiro Matsumoto) 2003/12/24

まつもと ゆきひろです

[#22397] Re: Tk.callback_break causes seg-fault or hang-up — Hidetoshi NAGAI <nagai@...> 2003/12/24

永井@知能.九工大です.

[#22418] ruby-1.8.1 build failed on HP-UX 11.11 — MIYAMUKO Katsuyuki <k-miyamuko@...>

みやむこです。

29 messages 2003/12/25
[#22419] Re: ruby-1.8.1 build failed on HP-UX 11.11 — matz@... (Yukihiro Matsumoto) 2003/12/25

まつもと ゆきひろです

[#22420] Re: ruby-1.8.1 build failed on HP-UX 11.11 — matz@... (Yukihiro Matsumoto) 2003/12/25

まつもと ゆきひろです

[#22424] Re: ruby-1.8.1 build failed on HP-UX 11.11 — MIYAMUKO Katsuyuki <k-miyamuko@...> 2003/12/25

みやむこです。

[#22491] Re: ruby-1.8.1 build failed on HP-UX 11.11 — MIYAMUKO Katsuyuki <k-miyamuko@...> 2004/01/05

みやむこです。

[ruby-dev:22301] Re: rough / tabs.rb

From: Minero Aoki <aamine@...>
Date: 2003-12-18 09:52:49 UTC
List: ruby-dev #22301
青木です。

  In mail "[ruby-dev:22271] Re: rough / tabs.rb"
    take_tk <ggb03124@nifty.ne.jp> wrote:

> たけ(tk)です。

> 次のようになってしまったのですが、仕様でしょうか? rough では
> 直っているのかな?

しまった。メールを出すときに何気なく書き換えたところが
間違ってました。申し訳ない。

あと typo らしきところもあったのでそれも直しときました。


> 自作のものと比べてみたのですが、自作のほう(detab)がexpand よりも速いみ
> たいです。
> 
> どういう場合に速くなるのでしょうか?

ぼくの書いたやつは行の先頭にタブが集中してるケースに最適化しま
した。条件を同じにして (detab をモジュールに定義して) 計測すると、
\t が 2 個までは detab の勝ち、3 個だと expand の勝ちって感じです。

ま、でもたけさんの detab のほうが定義がすっきりしているので、
そっちのほうがいいかも。ちょっとだけ変えてとりこんでみました。
ついでにテストも付けておきます。
-------------------------------------------------------------------
青木峰郎

Attachments (2)

tabs.rb (2.68 KB, text/x-ruby)
#
# Copyright (c) 2001 Akinori MUSHA <knu@iDaemons.org>
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $Idaemons: /home/cvs/rb/tabs.rb,v 1.2 2001/05/30 09:37:45 knu Exp $
# $Id: tabs.rb,v 1.1 2001/06/01 18:58:29 knu Exp $

module Tabs
  DEFAULT_TABSTOP = 8

  def expand(text, tabstop = DEFAULT_TABSTOP)
    text.gsub(/(.*?)\t/n) { $1 + ' ' * (tabstop - ($1.size % tabstop)) }
  end

  def unexpand(text, tabstop = DEFAULT_TABSTOP)
    text.gsub(/^[ \t]+/) {|sp|
      t, s = expand(sp, tabstop).length.divmod(tabstop)
      "\t" * t + ' ' * s
    }
  end

  def unexpand_all(text, tabstop = DEFAULT_TABSTOP)
    expand(text, tabstop).map {|line|
      (line.length - (line.length % tabstop) - tabstop).step(0, -tabstop) {|i|
        line[i, tabstop] = line[i, tabstop].sub(/ +\z/, "\t")
      }
      line
    }.join('')
  end

  module_function :expand, :unexpand, :unexpand_all
end

class String
  def expand_tabs(tabstop = Tabs::DEFAULT_TABSTOP)
    Tabs.expand(self, tabstop)
  end

  def expand_tabs!(tabstop = Tabs::DEFAULT_TABSTOP)
    replace(Tabs.expand(self, tabstop))
  end

  def unexpand_tabs(tabstop = Tabs::DEFAULT_TABSTOP)
    Tabs.unexpand(self, tabstop)
  end

  def unexpand_tabs!(tabstop = Tabs::DEFAULT_TABSTOP)
    replace(Tabs.unexpand(self, tabstop))
  end

  def unexpand_tabs_all(tabstop = Tabs::DEFAULT_TABSTOP)
    Tabs.unexpand_all(self, tabstop)
  end

  def unexpand_tabs_all!(tabstop = Tabs::DEFAULT_TABSTOP)
    replace(Tabs.unexpand_all(self, tabstop))
  end
end
test_tabs.rb (4.99 KB, text/x-ruby)
require 'tabs'
require 'test/unit'

class TestTabs < Test::Unit::TestCase
  include Tabs

  def test_expand
    assert_equal '', expand('')
    assert_equal ' ', expand("\t", 1)
    assert_equal '  ', expand("\t", 2)
    assert_equal '   ', expand("\t", 3)
    assert_equal '    ', expand("\t", 4)
    assert_equal '     ', expand("\t", 5)
    assert_equal '      ', expand("\t", 6)
    assert_equal '       ', expand("\t", 7)
    assert_equal '        ', expand("\t", 8)

    #assert_raises(ArgumentError) {
    #  expand(' ', 0)
    #}

    assert_equal ' '*9, expand("\t ", 8)
    assert_equal ' '*10, expand("\t  ", 8)
    assert_equal ' '*11, expand("\t   ", 8)
    assert_equal ' '*12, expand("\t    ", 8)
    assert_equal ' '*13, expand("\t     ", 8)
    assert_equal ' '*14, expand("\t      ", 8)
    assert_equal ' '*15, expand("\t       ", 8)
    assert_equal ' '*16, expand("\t        ", 8)

    assert_equal 'aa  ', expand("aa\t", 4)
    assert_equal 'aa   ', expand("aa\t", 5)
    assert_equal 'aa    ', expand("aa\t", 6)
    assert_equal 'aa     ', expand("aa\t", 7)
    assert_equal 'aa      ', expand("aa\t", 8)

    assert_equal '  ', expand("\t\t", 1)
    assert_equal '   ', expand("\t\t\t", 1)
    assert_equal '    ', expand("\t\t\t\t", 1)
    
    assert_equal "\n", expand("\n")
    assert_equal "\n\n", expand("\n\n")
    assert_equal "  \n", expand("\t\n", 2)
    assert_equal "   \n", expand("\t \n", 2)

    assert_equal 'a', expand("a", 2)
    assert_equal 'a a', expand("a\ta", 2)
    assert_equal 'a a a', expand("a\ta\ta", 2)
    assert_equal 'a a a a', expand("a\ta\ta\ta", 2)
    assert_equal 'a a a a a', expand("a\ta\ta\ta\ta", 2)
  end

  def test_unexpand
    assert_equal '', unexpand('', 0)
    assert_equal '', unexpand('', 1)
    assert_equal '', unexpand('', 2)
    assert_equal '', unexpand('', 3)
    assert_equal '', unexpand('', 4)
    assert_equal '', unexpand('', 5)
    assert_equal '', unexpand('', 6)
    assert_equal '', unexpand('', 7)
    assert_equal '', unexpand('', 8)

    assert_equal ' ', unexpand(' ', 8)
    assert_equal '  ', unexpand('  ', 8)
    assert_equal '   ', unexpand('   ', 8)
    assert_equal '    ', unexpand('    ', 8)
    assert_equal '     ', unexpand('     ', 8)
    assert_equal '      ', unexpand('      ', 8)
    assert_equal '       ', unexpand('       ', 8)

    assert_equal "\t", unexpand(' ', 1)
    assert_equal "\t", unexpand('  ', 2)
    assert_equal "\t", unexpand('   ', 3)
    assert_equal "\t", unexpand('    ', 4)
    assert_equal "\t", unexpand('     ', 5)
    assert_equal "\t", unexpand('      ', 6)
    assert_equal "\t", unexpand('       ', 7)
    assert_equal "\t", unexpand('        ', 8)

    assert_equal "\t", unexpand("\t")
    assert_equal "\t\t", unexpand("\t\t")
    assert_equal "\t\t\t", unexpand("\t\t\t")

    assert_equal "\t\t ", unexpand("\t\t ")
    assert_equal "\t\t\t", unexpand("\t\t  ", 2)
    assert_equal "\t\t\t", unexpand("\t  \t", 2)
    assert_equal "\t\t\t", unexpand("  \t\t", 2)
    assert_equal "\t", unexpand(" \t", 4)
  end

  def test_unexpand_all
    assert_equal "", unexpand_all("")
    assert_equal "", unexpand_all("", 1)
    assert_equal "", unexpand_all("", 2)
    assert_equal "", unexpand_all("", 3)
    assert_equal "", unexpand_all("", 4)
    assert_equal "", unexpand_all("", 5)
    assert_equal "", unexpand_all("", 6)
    assert_equal "", unexpand_all("", 7)
    assert_equal "", unexpand_all("", 8)

    assert_equal "\t", unexpand_all("        ")
    assert_equal "\t", unexpand_all(" ", 1)
    assert_equal "\t", unexpand_all("  ", 2)
    assert_equal "\t", unexpand_all("   ", 3)
    assert_equal "\t", unexpand_all("    ", 4)
    assert_equal "\t", unexpand_all("     ", 5)
    assert_equal "\t", unexpand_all("      ", 6)
    assert_equal "\t", unexpand_all("       ", 7)
    assert_equal "\t", unexpand_all("        ", 8)

    assert_equal "\t", unexpand_all("\t")
    assert_equal "\t\t", unexpand_all("\t\t")
    assert_equal "\t\t\t", unexpand_all("\t\t\t")

    assert_equal "\t\t ", unexpand_all("\t\t ")
    assert_equal "\t\t\t", unexpand_all("\t\t  ", 2)
    assert_equal "\t\t\t", unexpand_all("\t  \t", 2)
    assert_equal "\t\t\t", unexpand_all("  \t\t", 2)
    assert_equal "\t", unexpand_all(" \t", 4)

    assert_equal "a\t", unexpand_all("a   ", 4)
    assert_equal "ab\t", unexpand_all("ab  ", 4)
    assert_equal "abc\t", unexpand_all("abc ", 4)
    assert_equal "abcd", unexpand_all("abcd", 4)

    assert_equal "a\ta\ta", unexpand_all("a   a   a", 4)
    assert_equal "ab\tab\tab", unexpand_all("ab  ab  ab", 4)
    assert_equal "abc\tabc\tabc", unexpand_all("abc abc abc", 4)

    assert_equal "a\t a", unexpand_all("a    a", 4)
    assert_equal "a\t  a", unexpand_all("a     a", 4)
    assert_equal "a\t   a", unexpand_all("a      a", 4)
    assert_equal "a\t\ta", unexpand_all("a       a", 4)
    assert_equal "a\t\t a", unexpand_all("a        a", 4)

    assert_equal "\t123\t\t567\t\t789", unexpand_all("\t123\t    567     789", 4)
    assert_equal "\t123\t\t567\t\t789", unexpand_all("    123     567     789", 4)
  end
end

In This Thread

Prev Next