summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhuangming <huangminghuang@users.noreply.github.com>2004-01-22 20:57:54 +0000
committerhuangming <huangminghuang@users.noreply.github.com>2004-01-22 20:57:54 +0000
commit460c9cfb184785bc04ba51f9976e0cebc8c96ddc (patch)
treea79aeb3260a62a235b52b0a464864b2f6d4f9beb
parent285ccc1ad248734d2a70ffbaac9275d719fabc83 (diff)
downloadMPC-unlabeled-1.3.34.tar.gz
Merged From Trunk 01-22-04unlabeled-1.3.34
-rw-r--r--modules/StringProcessor.pm64
1 files changed, 22 insertions, 42 deletions
diff --git a/modules/StringProcessor.pm b/modules/StringProcessor.pm
index 97a5ab96..66e9d783 100644
--- a/modules/StringProcessor.pm
+++ b/modules/StringProcessor.pm
@@ -59,50 +59,30 @@ sub process_special {
sub create_array {
- my($self) = shift;
- my($line) = shift;
- my(@array) = ();
- my($length) = length($line);
- my($prev) = 0;
- my($double) = 0;
- my($single) = 0;
-
- for(my $i = 0; $i <= $length; $i++) {
- my($ch) = substr($line, $i, 1);
- if (!$double && !$single && ($ch eq '' || $ch =~ /\s/)) {
- my($val) = substr($line, $prev, $i - $prev);
- $val =~ s/^\s+//;
- $val =~ s/\s+$//;
- if ($val =~ /^\"(.*)\"$/) {
- $val = $1;
- }
- elsif ($val =~ /^\'(.*)\'$/) {
- $val = $1;
- }
-
- ## Only add the value to the array if the string isn't empty
- if ($val ne '') {
- push(@array, $val);
- }
- for(; $i < $length; $i++) {
- if (substr($line, $i, 1) !~ /\s/) {
- $i--;
- last;
- }
- }
- $prev = $i + 1;
- }
- elsif ($double && $ch eq "\\" && $i + 1 < $length) {
- substr($line, $i, 1) = '';
- $length--;
- }
- elsif ($ch eq '"') {
- $double ^= 1;
- }
- elsif ($ch eq "'") {
- $single ^= 1;
+ my($self) = shift;
+ my($line) = shift;
+ my(@array) = ();
+
+ ## Replace all escaped double and single quotes with special characters
+ my($escaped) = ($line =~ s/\\\"/\01/g);
+ $escaped |= ($line =~ s/\\\'/\02/g);
+
+ foreach my $part (grep(!/^\s*$/,
+ split(/(\"[^\"]+\"|\'[^\']+\'|\s+)/, $line))) {
+ ## Remove enclosing double and single quotes
+ $part =~ s/^"(.*)"$/$1/;
+ $part =~ s/^'(.*)'$/$1/;
+
+ ## Put any escaped double or single quotes back into the string.
+ if ($escaped) {
+ $part =~ s/\01/\"/g;
+ $part =~ s/\02/\'/g;
}
+
+ ## Push it onto the array
+ push(@array, $part);
}
+
return \@array;
}