青山です。

$KCODE 依存がありました。送り直し。


=begin
$Date: 2000/06/18 00:06:20 $

== EXPAND AND UNEXPAND TABS LIBRARY

text/tabs.rb

Version 0.1.0

Wakou Aoyama <wakou / fsinet.or.jp>

== EXAMPLE

        require "text/tabs"
        string_without_tabs = Text::Tabs::expand(string_with_tabs)
        string_with_tabs    = Text::Tabs::unexpand(string_without_tabs)

=end

module Text
  module Tabs
    def Tabs::expand(string, tab_stop = 8)
      cursor = 0
      string.gsub(/([^\t]*)(\t+)/) do
        cursor += Regexp::last_match[1].length
        add_space = Regexp::last_match[2].length * tab_stop
        add_space -= (cursor + add_space) % tab_stop
        cursor += add_space
        Regexp::last_match[1] + " " * add_space
      end
    end

    def Tabs::unexpand(string, tab_stop = 8)
      Tabs::expand(string).gsub(/.{#{tab_stop}}/onm) do |match|
        match.sub(/ +\z/, "\t")
      end
    end
  end
end

=begin

== HISTORY

=== Version 0.1.0 - wakou

2000/06/18 00:06:20

- first release.

=end


-- 
青山 和光 Wakou Aoyama <wakou / fsinet.or.jp>