Changeset 1495 for code/branches/network/src/util/SubString.cc
- Timestamp:
- Jun 1, 2008, 1:10:46 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/util/SubString.cc
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Christian Meyer * Co-authors: * Benjamin Grauer *//// splitLine// STL string tokenizer//// Created by Clemens Wacha.// Version 1.0// Copyright (c) 2005 Clemens Wacha. All rights reserved.// */ 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Christian Meyer 24 * Co-authors: 25 * Benjamin Grauer 26 * 27 // 28 // splitLine 29 // STL string tokenizer 30 // 31 // Created by Clemens Wacha. 32 // Version 1.0 33 // Copyright (c) 2005 Clemens Wacha. All rights reserved. 34 // 35 */ 36 2 37 #include "SubString.h" 3 38 … … 32 67 SubString::SubString(const std::string& string, 33 68 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 34 char escapeChar, bool removeEscapeChar, char safemode_char, bool removeSafemodeChar, char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 69 char escapeChar, bool removeEscapeChar, char safemode_char, bool removeSafemodeChar, 70 char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 35 71 { 36 72 SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeEscapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char); … … 44 80 SubString::SubString(const SubString& subString, unsigned int subSetBegin) 45 81 { 46 for (unsigned int i = subSetBegin; i < subString.size(); i++) { 47 this->strings.push_back(subString[i]); this->bInSafemode.push_back(subString.isInSafemode(i)); } 82 for (unsigned int i = subSetBegin; i < subString.size(); i++) 83 { 84 this->strings.push_back(subString[i]); 85 this->bInSafemode.push_back(subString.isInSafemode(i)); 86 } 48 87 } 49 88 … … 57 96 SubString::SubString(const SubString& subString, unsigned int subSetBegin, unsigned int subSetEnd) 58 97 { 59 for (unsigned int i = subSetBegin; i < subString.size() && i < subSetEnd; i++) { 60 this->strings.push_back(subString[i]); this->bInSafemode.push_back(subString.isInSafemode(i)); } 98 for (unsigned int i = subSetBegin; i < subString.size() && i < subSetEnd; i++) 99 { 100 this->strings.push_back(subString[i]); 101 this->bInSafemode.push_back(subString.isInSafemode(i)); 102 } 61 103 } 62 104 … … 68 110 SubString::SubString(unsigned int argc, const char** argv) 69 111 { 70 for(unsigned int i = 0; i < argc; ++i) { 71 this->strings.push_back(std::string(argv[i])); this->bInSafemode.push_back(false); } 112 for(unsigned int i = 0; i < argc; ++i) 113 { 114 this->strings.push_back(std::string(argv[i])); 115 this->bInSafemode.push_back(false); 116 } 72 117 } 73 118 … … 94 139 SubString& SubString::operator=(const SubString& subString) 95 140 { 96 this->strings = subString.strings; this->bInSafemode = subString.bInSafemode; 141 this->strings = subString.strings; 142 this->bInSafemode = subString.bInSafemode; 97 143 return *this; 98 144 } … … 155 201 SubString& SubString::operator+=(const SubString& subString) 156 202 { 157 for (unsigned int i = 0; i < subString.size(); i++) { 158 this->strings.push_back(subString[i]); this->bInSafemode.push_back(subString.isInSafemode(i)); } 203 for (unsigned int i = 0; i < subString.size(); i++) 204 { 205 this->strings.push_back(subString[i]); 206 this->bInSafemode.push_back(subString.isInSafemode(i)); 207 } 159 208 return *this; 160 209 } … … 168 217 unsigned int SubString::split(const std::string& string, char splitter) 169 218 { 170 this->strings.clear(); this->bInSafemode.clear(); 219 this->strings.clear(); 220 this->bInSafemode.clear(); 171 221 char split[2]; 172 222 split[0] = splitter; … … 189 239 unsigned int SubString::split(const std::string& string, 190 240 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 191 char escapeChar, bool removeExcapeChar, char safemode_char, bool removeSafemodeChar, char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 192 { 193 this->strings.clear(); this->bInSafemode.clear(); 241 char escapeChar, bool removeExcapeChar, char safemode_char, bool removeSafemodeChar, 242 char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 243 { 244 this->strings.clear(); 245 this->bInSafemode.clear(); 194 246 SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeExcapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char); 195 247 return this->strings.size(); … … 257 309 * @param emptyEntries: if empty Strings are added to the List of Strings. 258 310 * @param escape_char: Escape carater (escapes splitters) 259 * @param safemode_char: the beginning of the safemode is marked with this * @param removeSafemodeChar removes the safemode_char from the beginning and the ending of a token * @param openparenthesis_char the beginning of a safemode is marked with this * @param closeparenthesis_char the ending of a safemode is marked with this * @param removeParenthesisChars removes the parenthesis from the beginning and the ending of a token 311 * @param safemode_char: the beginning of the safemode is marked with this 312 * @param removeSafemodeChar removes the safemode_char from the beginning and the ending of a token 313 * @param openparenthesis_char the beginning of a safemode is marked with this 314 * @param closeparenthesis_char the ending of a safemode is marked with this 315 * @param removeParenthesisChars removes the parenthesis from the beginning and the ending of a token 260 316 * @param comment_char: the beginning of a comment is marked with this: (until the end of a Line) 261 317 * @param start_state: the Initial state on how to parse the String. … … 267 323 */ 268 324 SubString::SPLIT_LINE_STATE 269 SubString::splitLine(std::vector<std::string>& ret, std::vector<bool>& bInSafemode, 325 SubString::splitLine(std::vector<std::string>& ret, 326 std::vector<bool>& bInSafemode, 270 327 const std::string& line, 271 328 const std::string& delimiters, 272 329 const std::string& delimiterNeighbours, 273 330 bool emptyEntries, 274 char escape_char, bool removeExcapeChar, 275 char safemode_char, bool removeSafemodeChar, char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, 331 char escape_char, 332 bool removeExcapeChar, 333 char safemode_char, 334 bool removeSafemodeChar, 335 char openparenthesis_char, 336 char closeparenthesis_char, 337 bool removeParenthesisChars, 276 338 char comment_char, 277 339 SPLIT_LINE_STATE start_state) … … 281 343 unsigned int fallBackNeighbours = 0; 282 344 283 std::string token; bool inSafemode = false; 284 285 if(start_state != SL_NORMAL && ret.size() > 0) { token = ret[ret.size()-1]; 286 ret.pop_back(); } if(start_state != SL_NORMAL && bInSafemode.size() > 0) { inSafemode = bInSafemode[bInSafemode.size()-1]; bInSafemode.pop_back(); } 345 std::string token; 346 bool inSafemode = false; 347 348 if(start_state != SL_NORMAL && ret.size() > 0) 349 { 350 token = ret[ret.size()-1]; 351 ret.pop_back(); 352 } 353 if(start_state != SL_NORMAL && bInSafemode.size() > 0) 354 { 355 inSafemode = bInSafemode[bInSafemode.size()-1]; 356 bInSafemode.pop_back(); 357 } 358 287 359 while(i < line.size()) 288 360 { … … 292 364 if(line[i] == escape_char) 293 365 { 294 state = SL_ESCAPE; if (!removeExcapeChar) token += line[i]; 366 state = SL_ESCAPE; 367 if (!removeExcapeChar) 368 token += line[i]; 295 369 } 296 370 else if(line[i] == safemode_char) 297 371 { 298 state = SL_SAFEMODE; inSafemode = true; if (!removeSafemodeChar) token += line[i]; 299 } else if(line[i] == openparenthesis_char) { state = SL_PARENTHESES; inSafemode = true; if (!removeParenthesisChars) token += line[i]; } 372 state = SL_SAFEMODE; 373 inSafemode = true; 374 if (!removeSafemodeChar) 375 token += line[i]; 376 } 377 else if(line[i] == openparenthesis_char) 378 { 379 state = SL_PARENTHESES; 380 inSafemode = true; 381 if (!removeParenthesisChars) 382 token += line[i]; 383 } 300 384 else if(line[i] == comment_char) 301 385 { … … 305 389 if(emptyEntries || token.size() > 0) 306 390 { 307 ret.push_back(token); token.clear(); bInSafemode.push_back(inSafemode); inSafemode = false; } 391 ret.push_back(token); 392 token.clear(); 393 bInSafemode.push_back(inSafemode); 394 inSafemode = false; 395 } 308 396 token += line[i]; // EAT 309 397 state = SL_COMMENT; … … 319 407 ret.push_back(token); 320 408 token.clear(); 321 bInSafemode.push_back(inSafemode); inSafemode = false; } 409 bInSafemode.push_back(inSafemode); 410 inSafemode = false; 411 } 322 412 state = SL_NORMAL; 323 413 } … … 339 429 } 340 430 break; 341 case SL_ESCAPE: if (!removeSafemodeChar) token += line[i]; else { 431 case SL_ESCAPE: 432 if (!removeSafemodeChar) 433 token += line[i]; 434 else 435 { 342 436 if(line[i] == 'n') token += '\n'; 343 437 else if(line[i] == 't') token += '\t'; … … 348 442 else if(line[i] == 'a') token += '\a'; 349 443 else if(line[i] == '?') token += '\?'; 350 else token += line[i]; // EAT } 444 else token += line[i]; // EAT 445 } 351 446 state = SL_NORMAL; 352 447 break; … … 355 450 { 356 451 state = SL_NORMAL; 357 if (!removeSafemodeChar) token += line[i]; } 452 if (!removeSafemodeChar) 453 token += line[i]; 454 } 358 455 else if(line[i] == escape_char) 359 456 { … … 364 461 token += line[i]; // EAT 365 462 } 366 break; case SL_SAFEESCAPE: 463 break; 464 465 case SL_SAFEESCAPE: 367 466 if(line[i] == 'n') token += '\n'; 368 467 else if(line[i] == 't') token += '\t'; … … 376 475 state = SL_SAFEMODE; 377 476 break; 378 case SL_PARENTHESES: if(line[i] == closeparenthesis_char) { state = SL_NORMAL; if (!removeParenthesisChars) token += line[i]; } else if(line[i] == escape_char) { state = SL_PARENTHESESESCAPE; } else { token += line[i]; // EAT } break; case SL_PARENTHESESESCAPE: if(line[i] == 'n') token += '\n'; else if(line[i] == 't') token += '\t'; else if(line[i] == 'v') token += '\v'; else if(line[i] == 'b') token += '\b'; else if(line[i] == 'r') token += '\r'; else if(line[i] == 'f') token += '\f'; else if(line[i] == 'a') token += '\a'; else if(line[i] == '?') token += '\?'; else token += line[i]; // EAT state = SL_PARENTHESES; break; 477 478 case SL_PARENTHESES: 479 if(line[i] == closeparenthesis_char) 480 { 481 state = SL_NORMAL; 482 if (!removeParenthesisChars) 483 token += line[i]; 484 } 485 else if(line[i] == escape_char) 486 { 487 state = SL_PARENTHESESESCAPE; 488 } 489 else 490 { 491 token += line[i]; // EAT 492 } 493 break; 494 495 case SL_PARENTHESESESCAPE: 496 if(line[i] == 'n') token += '\n'; 497 else if(line[i] == 't') token += '\t'; 498 else if(line[i] == 'v') token += '\v'; 499 else if(line[i] == 'b') token += '\b'; 500 else if(line[i] == 'r') token += '\r'; 501 else if(line[i] == 'f') token += '\f'; 502 else if(line[i] == 'a') token += '\a'; 503 else if(line[i] == '?') token += '\?'; 504 else token += line[i]; // EAT 505 state = SL_PARENTHESES; 506 break; 507 379 508 case SL_COMMENT: 380 509 if(line[i] == '\n') … … 385 514 ret.push_back(token); 386 515 token.clear(); 387 bInSafemode.push_back(inSafemode); inSafemode = false; } 516 bInSafemode.push_back(inSafemode); 517 inSafemode = false; 518 } 388 519 state = SL_NORMAL; 389 520 } … … 408 539 ret.push_back(token); 409 540 token.clear(); 410 bInSafemode.push_back(inSafemode); inSafemode = false; } 541 bInSafemode.push_back(inSafemode); 542 inSafemode = false; 543 } 411 544 return(state); 412 545 }
Note: See TracChangeset
for help on using the changeset viewer.