ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-2.0/src/utils/StringUtils.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/utils/StringUtils.cpp (file contents):
Revision 1590 by gezelter, Mon Oct 18 16:29:53 2004 UTC vs.
Revision 1598 by chrisfen, Tue Oct 19 18:21:25 2004 UTC

# Line 23 | Line 23 | int findBegin(istream theStream, char* startText ){
23    return lc;
24   }
25  
26 < int findBegin(istream theStream, char* startText ){
26 > char* trimSpaces(char *str) {
27 >  size_t len;
28 >  char *right, *left;
29 >
30 >  if (strlen(str) == 0) return(str);
31 >  
32 >  /* Trim whitespace from left side */
33 >  for (left = str; isspace(*left); left++);
34 >
35 >  /* Trim whitespace from right side */
36 >  if ((len = strlen(left)))
37 >    {
38 >      right = left + (len - 1);
39 >      
40 >      while (isspace(*right))
41 >        {
42 >          *right = '\0';
43 >          right--;
44 >        }
45 >    }
46 >
47 >  /* Only do the str copy if there were spaces to the left */
48 >  if (left != str)
49 >    strcpy(str, left);
50 >  
51 >  return (str);
52 > }
53 >
54 > int findBegin(istream &theStream, char* startText ){
55    const int MAXLEN = 1024;
56    char readLine[MAXLEN];  
57    int foundText = 0;
# Line 50 | Line 78 | int findBegin(istream theStream, char* startText ){
78               "stream ended unexpectedly.\n", lineNum);
79        return -1;
80      }
81 <
81 >    
82      the_token = strtok( readLine, " ,;\t" );
83 <
84 <    if (!strcasecmp("begin", the_token)) {
85 <      the_token = TrimSpaces(strtok( NULL, " ,;\t" ));
86 <      foundText = !strcasecmp( startText, the_token );
87 <    }
88 <
83 >    if ( the_token != NULL)
84 >      if (!strcmp("begin", the_token)) {
85 >        the_token = strtok( NULL, " ,;\t" );
86 >        if ( the_token != NULL){
87 >          foundText = !strcmp( startText, the_token );
88 >        }
89 >      }
90 >    
91      if (!foundText) {
92        if (!theStream.eof()) {
93          theStream.getline(readLine, MAXLEN);
# Line 65 | Line 95 | int findBegin(istream theStream, char* startText ){
95        } else {
96          printf( "Error fast forwarding stream at line %d: "
97                  "stream ended unexpectedly.\n", lineNum);
98 <        return -1;
98 >        return -1;
99        }
100      }
101    }
# Line 92 | Line 122 | char* TrimSpaces(char *str) {
122    return(ntokens);
123   }
124  
95 char* TrimSpaces(char *str) {
96  size_t len;
97  char *right, *left;
98  
99  if (strlen(str) == 0) return(str);
100  
101  /* Trim whitespace from left side */
102  for (left = str; isspace(*left); left++);
103  
104  /* Trim whitespace from right side */
105  if ((len = strlen(left)))
106    {
107      right = left + (len - 1);
108      
109      while (isspace(*right))
110        {
111          *right = '\0';
112          right--;
113        }
114    }
115  
116  /* Only do the str copy if their was spaces to the left */
117  if (left != str)
118    strcpy(str, left);
119  
120  return (str);
121 }
122
125   int isEndLine(char *line) {
126    char *working_line;
127    char *foo;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines