Changeset 1494 for code/branches/network/src/util/SubString.cc
- Timestamp:
- May 31, 2008, 11:24:44 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/util/SubString.cc
- Property svn:eol-style set to native
r1349 r1494 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 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.// */ 37 2 #include "SubString.h" 38 3 … … 67 32 SubString::SubString(const std::string& string, 68 33 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 69 char escapeChar, bool removeEscapeChar, char safemode_char, bool removeSafemodeChar, 70 char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 34 char escapeChar, bool removeEscapeChar, char safemode_char, bool removeSafemodeChar, char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 71 35 { 72 36 SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeEscapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char); … … 80 44 SubString::SubString(const SubString& subString, unsigned int subSetBegin) 81 45 { 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 } 46 for (unsigned int i = subSetBegin; i < subString.size(); i++) { 47 this->strings.push_back(subString[i]); this->bInSafemode.push_back(subString.isInSafemode(i)); } 87 48 } 88 49 … … 96 57 SubString::SubString(const SubString& subString, unsigned int subSetBegin, unsigned int subSetEnd) 97 58 { 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 } 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)); } 103 61 } 104 62 … … 110 68 SubString::SubString(unsigned int argc, const char** argv) 111 69 { 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 } 70 for(unsigned int i = 0; i < argc; ++i) { 71 this->strings.push_back(std::string(argv[i])); this->bInSafemode.push_back(false); } 117 72 } 118 73 … … 139 94 SubString& SubString::operator=(const SubString& subString) 140 95 { 141 this->strings = subString.strings; 142 this->bInSafemode = subString.bInSafemode; 96 this->strings = subString.strings; this->bInSafemode = subString.bInSafemode; 143 97 return *this; 144 98 } … … 201 155 SubString& SubString::operator+=(const SubString& subString) 202 156 { 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 } 157 for (unsigned int i = 0; i < subString.size(); i++) { 158 this->strings.push_back(subString[i]); this->bInSafemode.push_back(subString.isInSafemode(i)); } 208 159 return *this; 209 160 } … … 217 168 unsigned int SubString::split(const std::string& string, char splitter) 218 169 { 219 this->strings.clear(); 220 this->bInSafemode.clear(); 170 this->strings.clear(); this->bInSafemode.clear(); 221 171 char split[2]; 222 172 split[0] = splitter; … … 239 189 unsigned int SubString::split(const std::string& string, 240 190 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 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(); 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(); 246 194 SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeExcapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char); 247 195 return this->strings.size(); … … 309 257 * @param emptyEntries: if empty Strings are added to the List of Strings. 310 258 * @param escape_char: Escape carater (escapes splitters) 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 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 316 260 * @param comment_char: the beginning of a comment is marked with this: (until the end of a Line) 317 261 * @param start_state: the Initial state on how to parse the String. … … 323 267 */ 324 268 SubString::SPLIT_LINE_STATE 325 SubString::splitLine(std::vector<std::string>& ret, 326 std::vector<bool>& bInSafemode, 269 SubString::splitLine(std::vector<std::string>& ret, std::vector<bool>& bInSafemode, 327 270 const std::string& line, 328 271 const std::string& delimiters, 329 272 const std::string& delimiterNeighbours, 330 273 bool emptyEntries, 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, 274 char escape_char, bool removeExcapeChar, 275 char safemode_char, bool removeSafemodeChar, char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, 338 276 char comment_char, 339 277 SPLIT_LINE_STATE start_state) … … 343 281 unsigned int fallBackNeighbours = 0; 344 282 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 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(); } 359 287 while(i < line.size()) 360 288 { … … 364 292 if(line[i] == escape_char) 365 293 { 366 state = SL_ESCAPE; 367 if (!removeExcapeChar) 368 token += line[i]; 294 state = SL_ESCAPE; if (!removeExcapeChar) token += line[i]; 369 295 } 370 296 else if(line[i] == safemode_char) 371 297 { 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 } 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]; } 384 300 else if(line[i] == comment_char) 385 301 { … … 389 305 if(emptyEntries || token.size() > 0) 390 306 { 391 ret.push_back(token); 392 token.clear(); 393 bInSafemode.push_back(inSafemode); 394 inSafemode = false; 395 } 307 ret.push_back(token); token.clear(); bInSafemode.push_back(inSafemode); inSafemode = false; } 396 308 token += line[i]; // EAT 397 309 state = SL_COMMENT; … … 407 319 ret.push_back(token); 408 320 token.clear(); 409 bInSafemode.push_back(inSafemode); 410 inSafemode = false; 411 } 321 bInSafemode.push_back(inSafemode); inSafemode = false; } 412 322 state = SL_NORMAL; 413 323 } … … 429 339 } 430 340 break; 431 case SL_ESCAPE: 432 if (!removeSafemodeChar) 433 token += line[i]; 434 else 435 { 341 case SL_ESCAPE: if (!removeSafemodeChar) token += line[i]; else { 436 342 if(line[i] == 'n') token += '\n'; 437 343 else if(line[i] == 't') token += '\t'; … … 442 348 else if(line[i] == 'a') token += '\a'; 443 349 else if(line[i] == '?') token += '\?'; 444 else token += line[i]; // EAT 445 } 350 else token += line[i]; // EAT } 446 351 state = SL_NORMAL; 447 352 break; … … 450 355 { 451 356 state = SL_NORMAL; 452 if (!removeSafemodeChar) 453 token += line[i]; 454 } 357 if (!removeSafemodeChar) token += line[i]; } 455 358 else if(line[i] == escape_char) 456 359 { … … 461 364 token += line[i]; // EAT 462 365 } 463 break; 464 465 case SL_SAFEESCAPE: 366 break; case SL_SAFEESCAPE: 466 367 if(line[i] == 'n') token += '\n'; 467 368 else if(line[i] == 't') token += '\t'; … … 475 376 state = SL_SAFEMODE; 476 377 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 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; 508 379 case SL_COMMENT: 509 380 if(line[i] == '\n') … … 514 385 ret.push_back(token); 515 386 token.clear(); 516 bInSafemode.push_back(inSafemode); 517 inSafemode = false; 518 } 387 bInSafemode.push_back(inSafemode); inSafemode = false; } 519 388 state = SL_NORMAL; 520 389 } … … 539 408 ret.push_back(token); 540 409 token.clear(); 541 bInSafemode.push_back(inSafemode); 542 inSafemode = false; 543 } 410 bInSafemode.push_back(inSafemode); inSafemode = false; } 544 411 return(state); 545 412 }
Note: See TracChangeset
for help on using the changeset viewer.