summaryrefslogtreecommitdiff
path: root/lib/shellwords.rb
diff options
context:
space:
mode:
-rw-r--r--lib/shellwords.rb14
1 files changed, 5 insertions, 9 deletions
@@ -26,22 +26,18 @@ module Shellwords
# See the +Shellwords+ module documentation for an example.
#
def shellwords(line)
- line = String.new(line) rescue
- raise(ArgumentError, "Argument must be a string")
words = []
field = ''
- last = 0
- sep = nil
- line.scan(/\G\s*(?:([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?))(\s+|\z)?/m) do
- last = $~.end(0)
- sep = $~.begin(5)
- field << ($1 || $2 || ($3 || $4).gsub(/\\(?=.)/, ''))
if sep
words << field
field = ''
end
end
- raise ArgumentError, "Unmatched double quote: #{line}" if line[last]
words
end