1 package StringProcessor
;
3 # ************************************************************
4 # Description : Perform various algorithms on strings
5 # Author : Chad Elliott
6 # Create Date : 3/07/2003
7 # ************************************************************
9 # ************************************************************
11 # ************************************************************
15 # ************************************************************
17 # ************************************************************
19 sub parse_assignment
{
20 my($self, $line, $values) = @_;
22 ## In MPC, a scope can have spaces in it. However, it can not end
24 ## Line may have embedded new lines, so using 's' modifier.
25 if ($line =~ /^((\w+[-\s\w]+\w::)*\w+)\s*([\-+]?=)\s*(.*)?/s) {
26 my $op = ($3 eq '+=' ?
1 : $3 eq '-=' ?
-1 : 0);
27 push(@
$values, $op, $self->resolve_alias(lc($1)), $4);
36 my($self, $name) = @_;
39 if ($name =~ /(.*)(Project|Workspace)Creator/) {
48 my($self, $line) = @_;
50 ## Replace all escaped double quotes and escaped backslashes
51 ## with special characters
52 my $escaped = ($line =~ s/\\\\/\01/g);
53 $escaped |= ($line =~ s/\\"/\02/g);
55 ## Remove any non-escaped double quotes
58 ## Un-escape all other characters. Using eval allows the user to pass
59 ## escaped characters that will be converted to their actual character
60 ## counterpart (i.e., \n, \f, etc).
61 if (index($line, '\\') != -1) {
62 eval("\$line = \"$line\"");
65 ## Put the escaped double quotes and backslashes back in
76 my($self, $line) = @_;
79 ## Replace all escaped double and single quotes with special
80 ## characters. We need to distinguish between doubly escaped quotes
81 ## (<%equote%>) and escaped quotes (\"). We also need to retain the
82 ## escaped escape characters.
83 my $escaped = ($line =~ s/\\\\\"/\01/g);
84 $escaped |= ($line =~ s/\\\'/\02/g);
85 $escaped |= ($line =~ s/\\ /\03/g);
86 $escaped |= ($line =~ s/\\\t/\04/g);
87 $escaped |= ($line =~ s/\\\"/\05/g);
88 $escaped |= ($line =~ s/\\\\/\06/g);
89 $escaped |= ($line =~ s/\n/\07/g);
91 foreach my $part (grep(!/^\s*$/,
92 split(/(\"[^\"]+\"|\'[^\']+\'|\s+)/, $line))) {
93 ## Remove enclosing double and single quotes
94 $part =~ s/^"(.*)"$/$1/;
95 $part =~ s/^'(.*)'$/$1/;
97 ## Put any escaped escaped characters back into the string, but
98 ## processed to take out one of the escape sequences.
100 $part =~ s/\01/\\"/g;
109 ## Push it onto the array
124 ## Windows and cygwin require a carriage return and line feed.
125 ## However, at some point cygwin changed the way it does output and can
126 ## be controlled through an environment variable.
127 return ($^O
eq 'MSWin32' ||
129 ($] < 5.008 || (defined $ENV{PERLIO
} && $ENV{PERLIO
} eq 'crlf'))) ?
141 my($str, $array) = @_;
142 foreach my $target (@
$array) {
143 return 1 if ($str eq $target);
149 # Push each element of @$list on to @$into, unless it's already in @$into.
150 my($into, $list) = @_;
151 foreach my $in (@
$list) {
152 push(@
$into, $in) if (!fgrep
($in, $into));