#
# StringUtil.rb
#
#   $Author: hiroya $
#   $Date: 2000/11/23 01:53:10 $
#   Copyright (C) 2000 Hiroya KUBO
#

module StringUtil
  def getSharedPrefix(list)
    matched = nil
    list.each do |str|
      if(matched == nil)
	matched = str
      else
	while( matched != "" && str.index(matched) != 0 )
	  matched = matched[0...matched.length-1]
	end
      end
    end
    return matched
  end

  def removePrefix(prefix, list)
    ret = []
    length = prefix.length;
    list.each do |str|
      if(str.index(prefix) == 0)
	ret.push(str[length..str.length-1])
      end
    end
    return ret
  end

  def show(list)
    list.each do |str|
      print "* ", str, "\r\n";
    end
  end
  
  module_function :getSharedPrefix
  module_function :removePrefix
  module_function :show
end



