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

Comparing:
trunk/OOPSE-3.0/src/utils/StringUtils.cpp (file contents), Revision 1590 by gezelter, Mon Oct 18 16:29:53 2004 UTC vs.
branches/new_design/OOPSE-3.0/src/utils/StringUtils.cpp (file contents), Revision 1824 by tim, Thu Dec 2 03:12:25 2004 UTC

# Line 1 | Line 1
1   #include "utils/StringUtils.hpp"
2  
3 < using namespace std;
4 < using namespace oopse;
5 <
6 < string UpperCase(const string& S) {
7 <  string uc = S;
3 > namespace oopse {
4 > std::string UpperCase(const std::string& S) {
5 >  std::string uc = S;
6    unsigned int n = uc.size();
7    for (unsigned int j = 0; j < n; j++) {  
8      char sj = uc[j];
# Line 13 | Line 11 | string UpperCase(const string& S) {
11    return uc;
12   }
13  
14 < string LowerCase(const string& S) {
15 <  string lc = S;
14 > std::string LowerCase(const std::string& S) {
15 >  std::string lc = S;
16    unsigned int n = lc.size();
17    for (unsigned int j = 0; j < n; j++) {
18      char sj = lc[j];
# Line 23 | Line 21 | string LowerCase(const string& S) {
21    return lc;
22   }
23  
24 < int findBegin(istream theStream, char* startText ){
24 > char* trimSpaces(char *str) {
25 >  size_t len;
26 >  char *right, *left;
27 >
28 >  if (strlen(str) == 0) return(str);
29 >  
30 >  /* Trim whitespace from left side */
31 >  for (left = str; isspace(*left); left++);
32 >
33 >  /* Trim whitespace from right side */
34 >  if ((len = strlen(left)))
35 >    {
36 >      right = left + (len - 1);
37 >      
38 >      while (isspace(*right))
39 >        {
40 >          *right = '\0';
41 >          right--;
42 >        }
43 >    }
44 >
45 >  /* Only do the str copy if there were spaces to the left */
46 >  if (left != str)
47 >    strcpy(str, left);
48 >  
49 >  return (str);
50 > }
51 >
52 > int findBegin(std::istream &theStream, char* startText ){
53    const int MAXLEN = 1024;
54    char readLine[MAXLEN];  
55    int foundText = 0;
# Line 32 | Line 58 | int findBegin(istream theStream, char* startText ){
58    char* eof_test;
59  
60    // rewind the stream
61 <  theStream.seekg (0, ios::beg);
61 >  theStream.seekg (0, std::ios::beg);
62    lineNum = 0;
63    
64    if (!theStream.eof()) {
# Line 50 | Line 76 | int findBegin(istream theStream, char* startText ){
76               "stream ended unexpectedly.\n", lineNum);
77        return -1;
78      }
79 <
79 >    
80      the_token = strtok( readLine, " ,;\t" );
81 <
82 <    if (!strcasecmp("begin", the_token)) {
83 <      the_token = TrimSpaces(strtok( NULL, " ,;\t" ));
84 <      foundText = !strcasecmp( startText, the_token );
85 <    }
86 <
81 >    if ( the_token != NULL)
82 >      if (!strcasecmp("begin", the_token)) {
83 >        the_token = strtok( NULL, " ,;\t" );
84 >        if ( the_token != NULL){
85 >          foundText = !strcasecmp( startText, the_token );
86 >        }
87 >      }
88 >    
89      if (!foundText) {
90        if (!theStream.eof()) {
91          theStream.getline(readLine, MAXLEN);
# Line 65 | Line 93 | int findBegin(istream theStream, char* startText ){
93        } else {
94          printf( "Error fast forwarding stream at line %d: "
95                  "stream ended unexpectedly.\n", lineNum);
96 <        return -1;
96 >        return -1;
97        }
98      }
99    }
# Line 92 | Line 120 | int countTokens(char *line, char *delimiters) {
120    return(ntokens);
121   }
122  
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
123   int isEndLine(char *line) {
124    char *working_line;
125    char *foo;
# Line 128 | Line 128 | int isEndLine(char *line) {
128    
129    foo = strtok(working_line, " ,;\t");
130  
131 < if (!strcasecmp(foo, "end")) return 1;
131 >  if (foo != NULL) {
132 >
133 >    if (!strcasecmp(foo, "end")) return 1;
134 >
135 >  }
136  
137   return 0;
138   }
139 +
140 +
141 + std::string getPrefix(const std::string& str) {
142 +  return str.substr(0, str.rfind('.'));
143 + }
144 +
145 + std::string getSuffix(const std::string& str) {
146 +    return str.substr(0, str.find('.'));
147 + }
148 +
149 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines