From 460c9cfb184785bc04ba51f9976e0cebc8c96ddc Mon Sep 17 00:00:00 2001 From: huangming Date: Thu, 22 Jan 2004 20:57:54 +0000 Subject: Merged From Trunk 01-22-04 --- modules/StringProcessor.pm | 64 ++++++++++++++++------------------------------ 1 file 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; } -- cgit v1.2.1