ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/utils/StringTokenizer.cpp
(Generate patch)

Comparing trunk/src/utils/StringTokenizer.cpp (file contents):
Revision 1879 by gezelter, Sun Jun 16 15:15:42 2013 UTC vs.
Revision 2073 by gezelter, Sat Mar 7 23:52:07 2015 UTC

# Line 52 | Line 52 | namespace OpenMD {
52      : tokenString_(str), delim_(delim), returnTokens_(false),
53        currentPos_(tokenString_.begin()), end_(tokenString_.end()){
54  
55 <    }
55 >  }
56  
57    StringTokenizer::StringTokenizer(std::string::const_iterator& first, std::string::const_iterator& last,
58                                     const std::string & delim)  
59      : tokenString_(first, last) , delim_(delim), returnTokens_(false),
60        currentPos_(tokenString_.begin()), end_(tokenString_.end()) {
61  
62 <    }
62 >  }
63  
64    StringTokenizer::StringTokenizer(const std::string&str, const std::string&delim,
65                                     bool returnTokens)
66      : tokenString_(str), delim_(delim), returnTokens_(returnTokens),
67        currentPos_(tokenString_.begin()), end_(tokenString_.end()) {
68  
69 <    }
69 >  }
70  
71    bool StringTokenizer::isDelimiter(const char c) {
72      return delim_.find(c) == std::string::npos ? false : true;
# Line 114 | Line 114 | namespace OpenMD {
114      } else {
115        std::string::const_iterator i = currentPos_;
116  
117 <      //walk through the remaining string to check whether it contains non-delimeter or not
117 >      //walk through the remaining string to check whether it contains
118 >      //non-delimeter or not
119        while(i != end_ && isDelimiter(*i)) {
120          ++i;
121        }
# Line 148 | Line 149 | namespace OpenMD {
149      return result;
150    }
151  
152 +  void StringTokenizer::skipToken() {
153 +
154 +    if(currentPos_ != end_) {
155 +      while( currentPos_ != end_ && isDelimiter(*currentPos_)) {
156 +
157 +        if (returnTokens_) {
158 +          *currentPos_++;
159 +          return;
160 +        }
161 +            
162 +        ++currentPos_;
163 +      }
164 +
165 +      while (currentPos_ != end_ && !isDelimiter(*currentPos_)) {
166 +        *currentPos_++;
167 +      }
168 +    }
169 +  }
170 +
171    bool StringTokenizer::nextTokenAsBool() {
172      std::string token = nextToken();
173      std::istringstream iss(token);
# Line 206 | Line 226 | namespace OpenMD {
226      return result;    
227    }
228  
229 < std::vector<std::string>  StringTokenizer::getAllTokens() {
229 >  std::vector<std::string>  StringTokenizer::getAllTokens() {
230      std::vector<std::string> tokens;
231      while (hasMoreTokens()) {
232 <        tokens.push_back(nextToken());
232 >      tokens.push_back(nextToken());
233      }
234      return tokens;
235 < }
235 >  }
236    void StringTokenizer::convertFortranNumber(std::string& fortranNumber) {
237      std::string::iterator i;
238      for(i = fortranNumber.begin(); i != fortranNumber.end(); ++i) {
# Line 222 | Line 242 | namespace OpenMD {
242      }
243    }
244  
245 +  std::string  StringTokenizer::getRemainingString() {
246 +    std::string result;
247 +    std::string::const_iterator tmpIter = currentPos_;
248 +    if(tmpIter != end_) {
249 +      std::insert_iterator<std::string> insertIter(result, result.begin());
250 +      
251 +      while (tmpIter != end_) {
252 +        *insertIter++ = *tmpIter++;
253 +      }
254 +    }
255 +    
256 +    return result;
257 +  }
258 +
259 +  
260   }//end namespace OpenMD
261  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines