1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
package StringProcessor;
# ************************************************************
# Description : Perform various algorithms on strings
# Author : Chad Elliott
# Create Date : 3/07/2003
# ************************************************************
# ************************************************************
# Pragmas
# ************************************************************
use strict;
# ************************************************************
# Subroutine Section
# ************************************************************
sub new {
my($class) = shift;
my($self) = bless {
}, $class;
return $self;
}
sub extractType {
my($self) = shift;
my($name) = shift;
my($type) = $name;
if ($name =~ /(.*)(Project|Workspace)Creator/) {
$type = $1;
}
return lc($type);
}
sub process_special {
my($self) = shift;
my($line) = shift;
my($length) = length($line);
for(my $i = 0; $i < $length; $i++) {
my($ch) = substr($line, $i, 1);
if ($ch eq "\\" && $i + 1 < $length) {
substr($line, $i, 1) = '';
$length--;
}
elsif ($ch eq '"') {
substr($line, $i, 1) = '';
$length--;
$i--;
}
}
return $line;
}
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;
}
}
return \@array;
}
1;
|