Changeset 7320 in orxonox.OLD for trunk/src/lib/util
- Timestamp:
- Apr 17, 2006, 1:12:25 PM (19 years ago)
- Location:
- trunk/src/lib/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/substring.cc
r7319 r7320 41 41 split[0] = splitter; 42 42 split[1] = '\0'; 43 SubString::splitLine(this->strings, this->offsets, 44 string, split); 43 SubString::splitLine(this->strings, string, split); 45 44 } 46 45 … … 52 51 SubString::SubString(const std::string& string, bool whiteSpaces) 53 52 { 54 SubString::splitLine(this->strings, this->offsets, 55 string); 53 SubString::splitLine(this->strings, string); 56 54 } 57 55 … … 66 64 SubString::SubString(const std::string& string, const std::string& splitters, char escapeChar,char safemode_char, char comment_char) 67 65 { 68 SubString::splitLine(this->strings, this->offsets, 69 string, splitters, escapeChar, safemode_char, comment_char); 66 SubString::splitLine(this->strings, string, splitters, escapeChar, safemode_char, comment_char); 70 67 } 71 68 … … 113 110 SubString& SubString::operator=(const SubString& subString) 114 111 { 115 this->offsets = subString.offsets;116 112 this->strings = subString.strings; 117 113 return *this; … … 160 156 unsigned int SubString::split(const std::string& string, char splitter) 161 157 { 162 this->offsets.clear();163 158 this->strings.clear(); 164 159 char split[2]; 165 160 split[0] = splitter; 166 161 split[1] = '\0'; 167 SubString::splitLine(this->strings, this->offsets,string, split);162 SubString::splitLine(this->strings, string, split); 168 163 return strings.size(); 169 164 } … … 178 173 unsigned int SubString::split(const std::string& string, bool whiteSpaces) 179 174 { 180 this->offsets.clear();181 175 this->strings.clear(); 182 SubString::splitLine(this->strings, this->offsets,string);176 SubString::splitLine(this->strings, string); 183 177 return strings.size(); 184 178 } … … 195 189 unsigned int SubString::split(const std::string& string, const std::string& splitters, char escapeChar,char safemode_char, char comment_char) 196 190 { 197 this->offsets.clear();198 191 this->strings.clear(); 199 SubString::splitLine(this->strings, this->offsets, 200 string, splitters, escapeChar, safemode_char); 192 SubString::splitLine(this->strings, string, splitters, escapeChar, safemode_char); 201 193 return strings.size(); 202 194 } … … 248 240 { 249 241 return SubString(*this, subSetBegin, subSetEnd); 250 }251 252 253 /**254 * @brief get a particular substring's offset255 * @param i the ID of the substring to get the offset from256 * @returns the offset or NULL if an invalid ID was given257 */258 unsigned int SubString::getOffset(unsigned int i) const259 {260 if( i < this->offsets.size() && i >= 0)261 return this->offsets[i];262 else263 return 0;264 242 } 265 243 … … 283 261 * 284 262 */ 285 SPLIT_LINE_STATE SubString::splitLine(std::vector<std::string>& ret, std::vector<unsigned int>& offsets, 286 const std::string& line, const std::string& delimiters, 287 char escape_char, char safemode_char, char comment_char, 263 SPLIT_LINE_STATE SubString::splitLine(std::vector<std::string>& ret, 264 const std::string& line, 265 const std::string& delimiters, 266 char escape_char, 267 char safemode_char, 268 char comment_char, 288 269 SPLIT_LINE_STATE start_state) 289 270 { … … 317 298 { 318 299 ret.push_back(token); 319 offsets.push_back(i);320 300 token.clear(); 321 301 } … … 330 310 { 331 311 ret.push_back(token); 332 offsets.push_back(i);333 312 token.clear(); 334 313 } … … 384 363 { 385 364 ret.push_back(token); 386 offsets.push_back(i);387 365 token.clear(); 388 366 } … … 405 383 { 406 384 ret.push_back(token); 407 offsets.push_back(i);408 385 token.clear(); 409 386 } -
trunk/src/lib/util/substring.h
r7319 r7320 48 48 unsigned int split(const std::string& string, bool whiteSpaces); 49 49 unsigned int split(const std::string& string, const std::string& splitters, char escapeChar ='\\', char safemode_char = '"', char comment_char = '\0'); 50 std::string join(const std::string& delimiter ) const;50 std::string join(const std::string& delimiter = " ") const; 51 51 //////////////////////////////////////// 52 52 … … 57 57 // retrieve Information from within 58 58 inline unsigned int size() const { return this->strings.size(); }; 59 const std::string& getString(unsigned int i) const { return (i < this->strings.size()) ? this->strings[i] : emptyString; } 60 ; // safety-precaution 59 const std::string& getString(unsigned int i) const { return (i < this->strings.size()) ? this->strings[i] : emptyString; }; 61 60 const std::string& operator[](unsigned int i) const { return this->getString(i); }; 62 unsigned int getOffset(unsigned int i) const;63 61 64 62 // the almighty algorithm. 65 static SPLIT_LINE_STATE splitLine(std::vector<std::string>& ret,std::vector<unsigned int>& offsets, 66 const std::string& line, const std::string& delimiters = " \t\r\n", 67 char escape_char = '\\', char safemode_char = '"', char comment_char = '\0', 63 static SPLIT_LINE_STATE splitLine(std::vector<std::string>& ret, 64 const std::string& line, 65 const std::string& delimiters = " \t\r\n", 66 char escape_char = '\\', 67 char safemode_char = '"', 68 char comment_char = '\0', 68 69 SPLIT_LINE_STATE start_state = SL_NORMAL); 69 70 // debugging. … … 72 73 private: 73 74 std::vector<std::string> strings; //!< strings produced from a single string splitted in multiple strings 74 std::vector<unsigned int> offsets; //!< offsets of the beginning of the input-string to the beginning of each substring.75 75 76 76 static const std::string emptyString;
Note: See TracChangeset
for help on using the changeset viewer.