[win32] support win32_select(0,0,0,msec) (winsock doesn't)
[p5sagit/p5-mst-13.2.git] / lib / Text / ParseWords.pm
index 317597c..62da1d2 100644 (file)
@@ -1,11 +1,13 @@
 package Text::ParseWords;
 
 require 5.000;
-require Exporter;
-require AutoLoader;
 use Carp;
 
-@ISA = qw(Exporter AutoLoader);
+require AutoLoader;
+*AUTOLOAD = \&AutoLoader::AUTOLOAD;
+
+require Exporter;
+@ISA = qw(Exporter);
 @EXPORT = qw(shellwords quotewords);
 @EXPORT_OK = qw(old_shellwords);
 
@@ -35,7 +37,6 @@ This version differs from the original in that it will _NOT_ default
 to using $_ if no arguments are given.  I personally find the old behavior
 to be a mis-feature.
 
-
 &quotewords() works by simply jamming all of @lines into a single
 string in $_ and then pulling off words a bit at a time until $_
 is exhausted.
@@ -88,43 +89,49 @@ sub quotewords {
 # at a time behavior was necessary if the delimiter was going to be a
 # regexp (love to hear it if you can figure out a better way).
 
-    local($delim, $keep, @lines) = @_;
-    local(@words,$snippet,$field,$_);
+    my ($delim, $keep, @lines) = @_;
+    my (@words, $snippet, $field);
+
+    local $_ = join ('', @lines);
 
-    $_ = join('', @lines);
-    while (length($_)) {
+    while (length) {
        $field = '';
+
        for (;;) {
-            $snippet = '';
-           if (s/^"(([^"\\]|\\[\\"])*)"//) {
+           $snippet = '';
+
+           if (s/^"([^"\\]*(\\.[^"\\]*)*)"//) {
                $snippet = $1;
-                $snippet = "\"$snippet\"" if ($keep);
+               $snippet = qq|"$snippet"| if $keep;
            }
-           elsif (s/^'(([^'\\]|\\[\\'])*)'//) {
+           elsif (s/^'([^'\\]*(\\.[^'\\]*)*)'//) {
                $snippet = $1;
-                $snippet = "'$snippet'" if ($keep);
+               $snippet = "'$snippet'" if $keep;
            }
            elsif (/^["']/) {
-               croak "Unmatched quote";
+               croak 'Unmatched quote';
            }
-            elsif (s/^\\(.)//) {
-                $snippet = $1;
-                $snippet = "\\$snippet" if ($keep);
-            }
-           elsif (!length($_) || s/^$delim//) {
-               last;
+           elsif (s/^\\(.)//) {
+               $snippet = $1;
+               $snippet = "\\$snippet" if $keep;
+           }
+           elsif (!length || s/^$delim//) {
+              last;
            }
            else {
-                while (length($_) && !(/^$delim/ || /^['"\\]/)) {
-                  $snippet .=  substr($_, 0, 1);
-                   substr($_, 0, 1) = '';
-                }
+               while (length && !(/^$delim/ || /^['"\\]/)) {
+                  $snippet .= substr ($_, 0, 1);
+                  substr($_, 0, 1) = '';
+               }
            }
+
            $field .= $snippet;
        }
-       push(@words, $field);
+
+       push @words, $field;
     }
-    @words;
+
+    return @words;
 }