Changeset 7474 in orxonox.OLD for trunk/src/lib/util/substring.cc
- Timestamp:
- May 2, 2006, 6:24:43 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/substring.cc
r7398 r7474 42 42 * @brief create a SubString from 43 43 * @param string the String to Spilit 44 * @param splitter the Character at which to split string (delimiter) 45 */ 46 SubString::SubString(const std::string& string, char splitter) 47 { 48 char split[2]; 49 split[0] = splitter; 50 split[1] = '\0'; 51 SubString::splitLine(this->strings, string, split); 44 * @param delimiter the Character at which to split string (delimiter) 45 */ 46 SubString::SubString(const std::string& string, char delimiter) 47 { 48 this->split(string, delimiter); 52 49 } 53 50 … … 56 53 * @brief Splits a String into multiple splitters. 57 54 * @param string the String to split 58 * @param splitters multiple set of characters at what to split. (delimiters) 55 * @param delimiters multiple set of characters at what to split. (delimiters) 56 * @param delimiterNeighbours neighbours of the delimiters, that will be erased only when near a delimiter. 59 57 * @param escapeChar The Escape Character that overrides splitters commends and so on... 60 58 * @param safemode_char within these characters splitting won't happen 61 59 * @param comment_char the Comment character. 62 60 */ 63 SubString::SubString(const std::string& string, const std::string& splitters, char escapeChar, char safemode_char, char comment_char) 64 { 65 SubString::splitLine(this->strings, string, splitters, escapeChar, safemode_char, comment_char); 61 SubString::SubString(const std::string& string, 62 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 63 char escapeChar, char safemode_char, char comment_char) 64 { 65 SubString::splitLine(this->strings, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, safemode_char, comment_char); 66 66 } 67 67 … … 196 196 * @brief Splits a String into multiple splitters. 197 197 * @param string the String to split 198 * @param splitters multiple set of characters at what to split. (delimiters) 198 * @param delimiters multiple set of characters at what to split. (delimiters) 199 * @param delimiterNeighbours: Neighbours to the Delimiters that will be erased too. 200 * @param emptyEntries: If empty entries are added to the List of SubStrings 199 201 * @param escapeChar The Escape Character that overrides splitters commends and so on... 200 202 * @param safemode_char within these characters splitting won't happen 201 203 * @param comment_char the Comment character. 202 204 */ 203 unsigned int SubString::split(const std::string& string, const std::string& splitters, char escapeChar,char safemode_char, char comment_char) 205 unsigned int SubString::split(const std::string& string, 206 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 207 char escapeChar,char safemode_char, char comment_char) 204 208 { 205 209 this->strings.clear(); 206 SubString::splitLine(this->strings, string, splitters, escapeChar, safemode_char, comment_char);210 SubString::splitLine(this->strings, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, safemode_char, comment_char); 207 211 return this->strings.size(); 208 212 } … … 264 268 * @param line the inputLine to split 265 269 * @param delimiters a String of Delimiters (here the input will be splitted) 270 * @param delimiterNeighbour Naighbours to the Delimitter, that will be removed if they are to the left or the right of a Delimiter. 271 * @param emptyEntries: if empty Strings are added to the List of Strings. 266 272 * @param escape_char: Escape carater (escapes splitters) 267 273 * @param safemode_char: the beginning of the safemode is marked with this … … 274 280 * ignores special characters between safemode_char and between comment_char and linend '\n'. 275 281 * 276 */ 277 SPLIT_LINE_STATE SubString::splitLine(std::vector<std::string>& ret, 278 const std::string& line, 279 const std::string& delimiters, 280 char escape_char, 281 char safemode_char, 282 char comment_char, 283 SPLIT_LINE_STATE start_state) 282 * 283 */ 284 SubString::SPLIT_LINE_STATE 285 SubString::splitLine(std::vector<std::string>& ret, 286 const std::string& line, 287 const std::string& delimiters, 288 const std::string& delimiterNeighbours, 289 bool emptyEntries, 290 char escape_char, 291 char safemode_char, 292 char comment_char, 293 SPLIT_LINE_STATE start_state) 284 294 { 285 295 SPLIT_LINE_STATE state = start_state; 286 296 unsigned int i = 0; 297 unsigned int fallBackNeighbours = 0; 298 287 299 std::string token; 288 300 … … 297 309 switch(state) 298 310 { 299 311 case SL_NORMAL: 300 312 if(line[i] == escape_char) 301 313 { … … 308 320 else if(line[i] == comment_char) 309 321 { 322 if (fallBackNeighbours > 0) 323 token = token.substr(0, token.size() - fallBackNeighbours); 310 324 /// FINISH 311 if( token.size() > 0)325 if(emptyEntries || token.size() > 0) 312 326 { 313 327 ret.push_back(token); … … 320 334 { 321 335 // line[i] is a delimiter 336 if (fallBackNeighbours > 0) 337 token = token.substr(0, token.size() - fallBackNeighbours); 322 338 /// FINISH 323 if( token.size() > 0)339 if(emptyEntries || token.size() > 0) 324 340 { 325 341 ret.push_back(token); 326 342 token.clear(); 327 343 } 344 state = SL_NORMAL; 328 345 } 329 346 else 330 347 { 348 if (delimiterNeighbours.find(line[i]) != std::string::npos) 349 { 350 if (token.size() > 0) 351 ++fallBackNeighbours; 352 else 353 { 354 i++; 355 continue; 356 } 357 } 358 else 359 fallBackNeighbours = 0; 331 360 token += line[i]; // EAT 332 361 } 333 362 break; 334 363 case SL_ESCAPE: 335 364 if(line[i] == 'n') token += '\n'; 336 365 else if(line[i] == 't') token += '\t'; … … 344 373 state = SL_NORMAL; 345 374 break; 346 375 case SL_SAFEMODE: 347 376 if(line[i] == safemode_char) 348 377 { … … 358 387 } 359 388 break; 360 case SL_SAFEESCAPE: 389 390 case SL_SAFEESCAPE: 361 391 if(line[i] == 'n') token += '\n'; 362 392 else if(line[i] == 't') token += '\t'; … … 370 400 state = SL_SAFEMODE; 371 401 break; 372 case SL_COMMENT: 402 403 case SL_COMMENT: 373 404 if(line[i] == '\n') 374 405 { … … 386 417 } 387 418 break; 388 default: 419 420 default: 389 421 // nothing 390 422 break; … … 394 426 395 427 /// FINISH 396 if(token.size() > 0) 428 if (fallBackNeighbours > 0) 429 token = token.substr(0, token.size() - fallBackNeighbours); 430 if(emptyEntries || token.size() > 0) 397 431 { 398 432 ret.push_back(token);
Note: See TracChangeset
for help on using the changeset viewer.