Module: Shellwords
- Defined in:
- lib/ruber/utils.rb
Class Method Summary (collapse)
-
+ (<String>) split_with_quotes(str)
Similar to
Shellwords.split
, but attempts to include quotes in the returned array for strings containing spaces.
Class Method Details
+ (<String>) split_with_quotes(str)
Similar to Shellwords.split
, but attempts to include quotes in the returned
array for strings containing spaces.
Since it’s impossible to find out from the output of Shellwords#split
whether a string was
quoted with signle or double quotes, the following approach is taken: if the
string contains double quotes, it’s sourrounded with single quotes; otherwise
double quotes are used.
TODO: improve on the above algorithm. whitespaces quoted according to the above algorithm
445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/ruber/utils.rb', line 445 def self.split_with_quotes str res = split str res.map! do |s| unless s.include? ' ' then s else quote = s.include?('"') ? "'" : '"' quote + s + quote end end res end |