diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-01-26 10:11:30 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-01-26 10:11:30 +0000 |
commit | 8b222cea6bcd69b6a854be03f2362c5961b43a03 () | |
tree | 2124a2269263f682fd31d7a6ac1e7d56b8219082 /lib/shellwords.rb | |
parent | 91758efa95b07503a880815ce9d108df6df067e0 (diff) |
* lib/shellwords.rb: Embed rdoc style comments.
* lib/shellwords.rb (shellwords): Use String#lstrip!. * lib/shellwords.rb (shellwords): Recognize an object that responds to to_str() by using String.new(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | lib/shellwords.rb | 60 |
1 files changed, 36 insertions, 24 deletions
@@ -1,41 +1,52 @@ -# shellwords.rb -# original is shellwords.pl # -# Usage: -# require 'shellwords' -# words = Shellwords.shellwords(line) # -# or -# -# require 'shellwords' -# include Shellwords -# words = shellwords(line) module Shellwords def shellwords(line) - unless line.kind_of?(String) - raise ArgumentError, "Argument must be String class object." - end - line = line.sub(/\A\s+/, '') words = [] - while line != '' field = '' - while true - if line.sub!(/\A"(([^"\\]|\\.)*)"/, '') then #" - snippet = $1 - snippet.gsub!(/\\(.)/, '\1') - elsif line =~ /\A"/ then #" raise ArgumentError, "Unmatched double quote: #{line}" - elsif line.sub!(/\A'([^']*)'/, '') then #' snippet = $1 - elsif line =~ /\A'/ then #' raise ArgumentError, "Unmatched single quote: #{line}" elsif line.sub!(/\A\\(.)/, '') then snippet = $1 - elsif line.sub!(/\A([^\s\\'"]+)/, '') then #' snippet = $1 else - line.sub!(/\A\s+/, '') break end field.concat(snippet) @@ -44,5 +55,6 @@ module Shellwords end words end module_function :shellwords end |