Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
107 bj 1
package StringProcessor;
2
 
3
# ************************************************************
4
# Description   : Perform various algorithms on strings
5
# Author        : Chad Elliott
6
# Create Date   : 3/07/2003
7
# ************************************************************
8
 
9
# ************************************************************
10
# Pragmas
11
# ************************************************************
12
 
13
use strict;
14
 
15
# ************************************************************
16
# Subroutine Section
17
# ************************************************************
18
 
19
sub extractType {
20
  my($self) = shift;
21
  my($name) = shift;
22
  my($type) = $name;
23
 
24
  if ($name =~ /(.*)(Project|Workspace)Creator/) {
25
    $type = $1;
26
  }
27
 
28
  return lc($type);
29
}
30
 
31
 
32
sub process_special {
33
  my($self) = shift;
34
  my($line) = shift;
35
 
36
  ## Replace all escaped double quotes and escaped backslashes
37
  ## with special characters
38
  my($escaped) = ($line =~ s/\\\\/\01/g);
39
  $escaped |= ($line =~ s/\\"/\02/g);
40
 
41
  ## Un-escape all other characters
42
  $line =~ s/\\(.)/$1/g;
43
 
44
  ## Remove any non-escaped double quotes
45
  $line =~ s/"//g;
46
 
47
  ## Put the escaped double quotes and backslashes back in
48
  if ($escaped) {
49
    $line =~ s/\02/"/g;
50
    $line =~ s/\01/\\/g;
51
  }
52
 
53
  return $line;
54
}
55
 
56
 
57
sub create_array {
58
  my($self)  = shift;
59
  my($line)  = shift;
60
  my(@array) = ();
61
 
62
  ## Replace all escaped double and single quotes with special characters
63
  my($escaped) = ($line =~ s/\\\"/\01/g);
64
  $escaped |= ($line =~ s/\\\'/\02/g);
65
  $escaped |= ($line =~ s/\\ /\03/g);
66
  $escaped |= ($line =~ s/\\\t/\04/g);
67
 
68
  foreach my $part (grep(!/^\s*$/,
69
                         split(/(\"[^\"]+\"|\'[^\']+\'|\s+)/, $line))) {
70
    ## Remove enclosing double and single quotes
71
    $part =~ s/^"(.*)"$/$1/;
72
    $part =~ s/^'(.*)'$/$1/;
73
 
74
    ## Put any escaped double or single quotes back into the string.
75
    if ($escaped) {
76
      $part =~ s/\01/\"/g;
77
      $part =~ s/\02/\'/g;
78
      $part =~ s/\03/ /g;
79
      $part =~ s/\04/\t/g;
80
    }
81
 
82
    ## Push it onto the array
83
    push(@array, $part);
84
  }
85
 
86
  return \@array;
87
}
88
 
89
 
90
sub crlf {
91
  #my($self) = shift;
92
  return "\n";
93
}
94
 
95
 
96
sub windows_crlf {
97
  #my($self) = shift;
98
  if ($^O eq 'MSWin32' || $^O eq 'os2' ||
99
      ($^O eq 'cygwin' &&
100
       ($] < 5.008 || (defined $ENV{PERLIO} && $ENV{PERLIO} eq 'crlf')))) {
101
    return "\n";
102
  }
103
  else {
104
    return "\r\n";
105
  }
106
}
107
 
108
1;