Changeset 994 for code/branches/core2/src/util
- Timestamp:
- Apr 5, 2008, 5:54:24 PM (17 years ago)
- Location:
- code/branches/core2/src/util
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/util/Convert.h
r961 r994 407 407 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 408 408 409 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0');409 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 410 410 411 411 if (tokens.size() >= 2) … … 433 433 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 434 434 435 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0');435 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 436 436 437 437 if (tokens.size() >= 3) … … 461 461 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 462 462 463 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0');463 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 464 464 465 465 if (tokens.size() >= 4) … … 491 491 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 492 492 493 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0');493 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 494 494 495 495 if (tokens.size() >= 4) … … 521 521 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 522 522 523 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0');523 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 524 524 525 525 if (tokens.size() >= 4) -
code/branches/core2/src/util/String.cc
r957 r994 52 52 std::string output = std::string(str); 53 53 strip(&output); 54 return output; 55 } 56 57 /** 58 @brief Removes enclosing quotes if available. 59 @brief str The string to strip 60 */ 61 void stripEnclosingQuotes(std::string* str) 62 { 63 unsigned int start = std::string::npos; 64 unsigned int end = 0; 65 66 for (unsigned int pos = 0; (pos < (*str).size()) && (pos < std::string::npos); pos++) 67 { 68 if ((*str)[pos] == '"') 69 { 70 start = pos; 71 break; 72 } 73 74 if (((*str)[pos] != ' ') && ((*str)[pos] != '\t') && ((*str)[pos] != '\n')) 75 return; 76 } 77 78 for (unsigned int pos = (*str).size() - 1; pos < std::string::npos; pos--) 79 { 80 if ((*str)[pos] == '"') 81 { 82 end = pos; 83 break; 84 } 85 86 if (((*str)[pos] != ' ') && ((*str)[pos] != '\t') && ((*str)[pos] != '\n')) 87 return; 88 } 89 90 if ((start != std::string::npos) && (end != 0)) 91 (*str) = (*str).substr(start + 1, end - start - 1); 92 } 93 94 /** 95 @brief Returns a copy of the string with removed enclosing quotes (if available). 96 @brief str The string to strip 97 @return The striped copy of the string 98 */ 99 std::string getStrippedEnclosingQuotes(const std::string& str) 100 { 101 std::string output = std::string(str); 102 stripEnclosingQuotes(&output); 54 103 return output; 55 104 } -
code/branches/core2/src/util/String.h
r933 r994 36 36 _UtilExport void strip(std::string* str); 37 37 _UtilExport std::string getStripped(const std::string& str); 38 39 _UtilExport void stripEnclosingQuotes(std::string* str); 40 _UtilExport std::string getStrippedEnclosingQuotes(const std::string& str); 38 41 39 42 _UtilExport bool isEmpty(const std::string& str); -
code/branches/core2/src/util/SubString.cc
r871 r994 66 66 SubString::SubString(const std::string& string, 67 67 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 68 char escapeChar, char safemode_char, char openparenthesis_char, char closeparenthesis_char, char comment_char) 69 { 70 SubString::splitLine(this->strings, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, safemode_char, openparenthesis_char, closeparenthesis_char, comment_char); 68 char escapeChar, bool removeExcapeChar, char safemode_char, bool removeSafemodeChar, 69 char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 70 { 71 SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeExcapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char); 71 72 } 72 73 … … 79 80 { 80 81 for (unsigned int i = subSetBegin; i < subString.size(); i++) 82 { 81 83 this->strings.push_back(subString[i]); 84 this->bInSafemode.push_back(subString.isInSafemode(i)); 85 } 82 86 } 83 87 … … 91 95 SubString::SubString(const SubString& subString, unsigned int subSetBegin, unsigned int subSetEnd) 92 96 { 93 for (unsigned int i = subSetBegin; i < subString.size() || i < subSetEnd; i++) 97 for (unsigned int i = subSetBegin; i < subString.size() && i < subSetEnd; i++) 98 { 94 99 this->strings.push_back(subString[i]); 100 this->bInSafemode.push_back(subString.isInSafemode(i)); 101 } 95 102 } 96 103 … … 103 110 { 104 111 for(unsigned int i = 0; i < argc; ++i) 112 { 105 113 this->strings.push_back(std::string(argv[i])); 114 this->bInSafemode.push_back(false); 115 } 106 116 } 107 117 … … 129 139 { 130 140 this->strings = subString.strings; 141 this->bInSafemode = subString.bInSafemode; 131 142 return *this; 132 143 } … … 140 151 bool SubString::operator==(const SubString& subString) const 141 152 { 142 return ( this->strings == subString.strings);153 return ((this->strings == subString.strings) && (this->bInSafemode == subString.bInSafemode)); 143 154 } 144 155 … … 165 176 166 177 for (unsigned int i = 0; i < length; i++) 167 if ( this->strings[i] != subString.strings[i])178 if ((this->strings[i] != subString.strings[i]) || (this->bInSafemode[i] != subString.bInSafemode[i])) 168 179 return false; 169 180 return true; … … 190 201 { 191 202 for (unsigned int i = 0; i < subString.size(); i++) 203 { 192 204 this->strings.push_back(subString[i]); 205 this->bInSafemode.push_back(subString.isInSafemode(i)); 206 } 193 207 return *this; 194 208 } … … 203 217 { 204 218 this->strings.clear(); 219 this->bInSafemode.clear(); 205 220 char split[2]; 206 221 split[0] = splitter; 207 222 split[1] = '\0'; 208 SubString::splitLine(this->strings, string, split);223 SubString::splitLine(this->strings, this->bInSafemode, string, split); 209 224 return strings.size(); 210 225 } … … 223 238 unsigned int SubString::split(const std::string& string, 224 239 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 225 char escapeChar, char safemode_char, char openparenthesis_char, char closeparenthesis_char, char comment_char) 240 char escapeChar, bool removeExcapeChar, char safemode_char, bool removeSafemodeChar, 241 char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 226 242 { 227 243 this->strings.clear(); 228 SubString::splitLine(this->strings, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, safemode_char, openparenthesis_char, closeparenthesis_char, comment_char); 244 this->bInSafemode.clear(); 245 SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeExcapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char); 229 246 return this->strings.size(); 230 247 } … … 292 309 * @param escape_char: Escape carater (escapes splitters) 293 310 * @param safemode_char: the beginning of the safemode is marked with this 311 * @param removeSafemodeChar removes the safemode_char from the beginning and the ending of a token 312 * @param openparenthesis_char the beginning of a safemode is marked with this 313 * @param closeparenthesis_char the ending of a safemode is marked with this 314 * @param removeParenthesisChars removes the parenthesis from the beginning and the ending of a token 294 315 * @param comment_char: the beginning of a comment is marked with this: (until the end of a Line) 295 316 * @param start_state: the Initial state on how to parse the String. 296 * @return sSPLIT_LINE_STATE the parser was in when returning317 * @return SPLIT_LINE_STATE the parser was in when returning 297 318 * 298 319 * This is the Actual Splitting Algorithm from Clemens Wacha … … 302 323 SubString::SPLIT_LINE_STATE 303 324 SubString::splitLine(std::vector<std::string>& ret, 325 std::vector<bool>& bInSafemode, 304 326 const std::string& line, 305 327 const std::string& delimiters, … … 307 329 bool emptyEntries, 308 330 char escape_char, 331 bool removeExcapeChar, 309 332 char safemode_char, 333 bool removeSafemodeChar, 310 334 char openparenthesis_char, 311 335 char closeparenthesis_char, 336 bool removeParenthesisChars, 312 337 char comment_char, 313 338 SPLIT_LINE_STATE start_state) … … 318 343 319 344 std::string token; 345 bool inSafemode = false; 320 346 321 347 if(start_state != SL_NORMAL && ret.size() > 0) … … 323 349 token = ret[ret.size()-1]; 324 350 ret.pop_back(); 351 } 352 if(start_state != SL_NORMAL && bInSafemode.size() > 0) 353 { 354 inSafemode = bInSafemode[bInSafemode.size()-1]; 355 bInSafemode.pop_back(); 325 356 } 326 357 … … 333 364 { 334 365 state = SL_ESCAPE; 366 if (!removeExcapeChar) 367 token += line[i]; 335 368 } 336 369 else if(line[i] == safemode_char) 337 370 { 338 371 state = SL_SAFEMODE; 372 inSafemode = true; 373 if (!removeSafemodeChar) 374 token += line[i]; 339 375 } 340 376 else if(line[i] == openparenthesis_char) 341 377 { 342 378 state = SL_PARENTHESES; 379 inSafemode = true; 380 if (!removeParenthesisChars) 381 token += line[i]; 343 382 } 344 383 else if(line[i] == comment_char) … … 351 390 ret.push_back(token); 352 391 token.clear(); 392 bInSafemode.push_back(inSafemode); 393 inSafemode = false; 353 394 } 354 395 token += line[i]; // EAT … … 365 406 ret.push_back(token); 366 407 token.clear(); 408 bInSafemode.push_back(inSafemode); 409 inSafemode = false; 367 410 } 368 411 state = SL_NORMAL; … … 386 429 break; 387 430 case SL_ESCAPE: 388 if(line[i] == 'n') token += '\n'; 389 else if(line[i] == 't') token += '\t'; 390 else if(line[i] == 'v') token += '\v'; 391 else if(line[i] == 'b') token += '\b'; 392 else if(line[i] == 'r') token += '\r'; 393 else if(line[i] == 'f') token += '\f'; 394 else if(line[i] == 'a') token += '\a'; 395 else if(line[i] == '?') token += '\?'; 396 else token += line[i]; // EAT 431 if (!removeSafemodeChar) 432 token += line[i]; 433 else 434 { 435 if(line[i] == 'n') token += '\n'; 436 else if(line[i] == 't') token += '\t'; 437 else if(line[i] == 'v') token += '\v'; 438 else if(line[i] == 'b') token += '\b'; 439 else if(line[i] == 'r') token += '\r'; 440 else if(line[i] == 'f') token += '\f'; 441 else if(line[i] == 'a') token += '\a'; 442 else if(line[i] == '?') token += '\?'; 443 else token += line[i]; // EAT 444 } 397 445 state = SL_NORMAL; 398 446 break; … … 401 449 { 402 450 state = SL_NORMAL; 451 if (!removeSafemodeChar) 452 token += line[i]; 403 453 } 404 454 else if(line[i] == escape_char) … … 429 479 { 430 480 state = SL_NORMAL; 481 if (!removeParenthesisChars) 482 token += line[i]; 431 483 } 432 484 else if(line[i] == escape_char) … … 461 513 ret.push_back(token); 462 514 token.clear(); 515 bInSafemode.push_back(inSafemode); 516 inSafemode = false; 463 517 } 464 518 state = SL_NORMAL; … … 484 538 ret.push_back(token); 485 539 token.clear(); 540 bInSafemode.push_back(inSafemode); 541 inSafemode = false; 486 542 } 487 543 return(state); -
code/branches/core2/src/util/SubString.h
r871 r994 88 88 SubString(const std::string& string, 89 89 const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries=false, 90 char escapeChar ='\\', char safemode_char = '"', char openparenthesis_char = '(', char closeparenthesis_char = ')', char comment_char = '\0'); 90 char escapeChar ='\\', bool removeExcapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true, 91 char openparenthesis_char = '(', char closeparenthesis_char = ')', bool removeParenthesisChars = true, char comment_char = '\0'); 91 92 SubString(unsigned int argc, const char** argv); 92 93 /** @brief create a Substring as a copy of another one. @param subString the SubString to copy. */ … … 111 112 unsigned int split(const std::string& string, 112 113 const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries = false, 113 char escapeChar ='\\', char safemode_char = '"', char openparenthesis_char = '(', char closeparenthesis_char = ')', char comment_char = '\0'); 114 char escapeChar ='\\', bool removeExcapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true, 115 char openparenthesis_char = '(', char closeparenthesis_char = ')', bool removeParenthesisChars = true, char comment_char = '\0'); 114 116 std::string join(const std::string& delimiter = " ") const; 115 117 //////////////////////////////////////// … … 120 122 121 123 // retrieve Information from within 122 /** @ returns true if the SubString is empty */124 /** @brief Returns true if the SubString is empty */ 123 125 inline bool empty() const { return this->strings.empty(); }; 124 /** @ returns the count of Strings stored in this substring */126 /** @brief Returns the count of Strings stored in this substring */ 125 127 inline unsigned int size() const { return this->strings.size(); }; 126 /** @ param i the i'th String @returns the i'th string from the subset of Strings*/128 /** @brief Returns the i'th string from the subset of Strings @param i the i'th String */ 127 129 inline const std::string& operator[](unsigned int i) const { return this->strings[i]; }; 128 /** @ param i the i'th String @returns the i'th string from the subset of Strings*/130 /** @brief Returns the i'th string from the subset of Strings @param i the i'th String */ 129 131 inline const std::string& getString(unsigned int i) const { return (*this)[i]; }; 130 /** @returns the front of the StringList. */ 132 /** @brief Returns true if the token is in safemode. @param i the i'th token */ 133 inline bool isInSafemode(unsigned int i) const { return this->bInSafemode[i]; } 134 /** @brief Returns the front of the StringList. */ 131 135 inline const std::string& front() const { return this->strings.front(); }; 132 /** @ returns the back of the StringList. */136 /** @brief Returns the back of the StringList. */ 133 137 inline const std::string& back() const { return this->strings.back(); }; 134 138 /** @brief removes the back of the strings list. */ 135 inline void pop_back() { this->strings.pop_back(); };139 inline void pop_back() { this->strings.pop_back(); this->bInSafemode.pop_back(); }; 136 140 137 141 // the almighty algorithm. 138 142 static SPLIT_LINE_STATE splitLine(std::vector<std::string>& ret, 143 std::vector<bool>& bInSafemode, 139 144 const std::string& line, 140 145 const std::string& delimiters = SubString::WhiteSpaces, … … 142 147 bool emptyEntries = false, 143 148 char escape_char = '\\', 149 bool removeExcapeChar = true, 144 150 char safemode_char = '"', 151 bool removeSafemodeChar = true, 145 152 char openparenthesis_char = '(', 146 153 char closeparenthesis_char = ')', 154 bool removeParenthesisChars = true, 147 155 char comment_char = '\0', 148 156 SPLIT_LINE_STATE start_state = SL_NORMAL); … … 157 165 private: 158 166 std::vector<std::string> strings; //!< strings produced from a single string splitted in multiple strings 167 std::vector<bool> bInSafemode; 159 168 }; 160 169
Note: See TracChangeset
for help on using the changeset viewer.