Changeset 9076 for code/branches/testing
- Timestamp:
- Apr 1, 2012, 11:07:02 AM (13 years ago)
- Location:
- code/branches/testing/src/libraries/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/testing/src/libraries/util/StringUtils.cc
r8858 r9076 81 81 } 82 82 83 /// Splits a given string by a delimiter and stores it in an output vector 83 /// Splits a given string by a delimiter and stores it in an output vector. See @ref SubString for a more sophisticated implementation. 84 84 void vectorize(const std::string& str, char delimiter, std::vector<std::string>* output) 85 85 { 86 output->clear(); 86 87 for (size_t start = 0, end = 0; end != std::string::npos; start = end + 1) 87 88 { … … 92 93 93 94 /** 94 @brief Returns the position of the next quotation mark in the string, starting with start. 95 @brief Returns the position of the next quotation mark in the string, starting with start. Escaped quotation marks (with \ in front) are not considered. 95 96 @param str The string 96 97 @param start The first position to look at … … 130 131 size_t quote = static_cast<size_t>(-1); 131 132 while ((quote = getNextQuote(str, quote + 1)) < pos) 132 {133 if (quote == pos)134 return false;135 133 quotecount++; 136 } 137 134 135 if (quote == pos) 136 return false; 138 137 if (quote == std::string::npos) 139 138 return false; … … 156 155 size_t pos2 = getNextQuote(str, pos1 + 1); 157 156 if (pos1 != std::string::npos && pos2 != std::string::npos) 158 return str.substr(pos1 , pos2 - pos1 +1);157 return str.substr(pos1 + 1, pos2 - pos1 - 1); 159 158 else 160 159 return ""; … … 247 246 { 248 247 return getStripped(str).empty(); 249 }250 251 /// Determines if a string contains only numbers and maximal one '.'.252 bool isNumeric(const std::string& str)253 {254 bool foundPoint = false;255 256 for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)257 {258 if (((*it) < '0' || (*it) > '9'))259 {260 if ((*it) != '.' && !foundPoint)261 foundPoint = true;262 else263 return false;264 }265 }266 267 return true;268 248 } 269 249 … … 444 424 bool hasComment(const std::string& str) 445 425 { 446 return (get CommentPosition(str) != std::string::npos);447 } 448 449 /// If the string contains a comment, the comment gets returned (including the comment symbol ), an empty string otherwise.426 return (getNextCommentPosition(str) != std::string::npos); 427 } 428 429 /// If the string contains a comment, the comment gets returned (including the comment symbol and white spaces in front of it), an empty string otherwise. 450 430 std::string getComment(const std::string& str) 451 431 { 452 return str.substr(getCommentPosition(str)); 453 } 454 455 /// If the string contains a comment, the position of the comment-symbol gets returned, @c std::string::npos otherwise. 456 size_t getCommentPosition(const std::string& str) 457 { 458 return getNextCommentPosition(str, 0); 459 } 460 461 /** 462 @brief Returns the position of the next comment-symbol, starting with @a start. 432 size_t pos = getNextCommentPosition(str); 433 if (pos == std::string::npos) 434 return ""; 435 else 436 return str.substr(pos); 437 } 438 439 /** 440 @brief Returns the beginning of the next comment including whitespaces in front of the comment symbol. 463 441 @param str The string 464 442 @param start The first position to look at -
code/branches/testing/src/libraries/util/StringUtils.h
r8858 r9076 58 58 _UtilExport void vectorize(const std::string& str, char delimiter, std::vector<std::string>* output); 59 59 60 _UtilExport size_t getNextQuote(const std::string& str, size_t start );60 _UtilExport size_t getNextQuote(const std::string& str, size_t start = 0); 61 61 _UtilExport bool isBetweenQuotes(const std::string& str, size_t pos); 62 62 … … 69 69 _UtilExport bool isEmpty(const std::string& str); 70 70 _UtilExport bool isComment(const std::string& str); 71 _UtilExport bool isNumeric(const std::string& str);72 71 73 72 _UtilExport std::string addSlashes(const std::string& str); … … 85 84 _UtilExport bool hasComment(const std::string& str); 86 85 _UtilExport std::string getComment(const std::string& str); 87 _UtilExport size_t getCommentPosition(const std::string& str);88 86 _UtilExport size_t getNextCommentPosition(const std::string& str, size_t start = 0); 89 87
Note: See TracChangeset
for help on using the changeset viewer.