Changeset 7401 for code/trunk/src/libraries/util/StringUtils.cc
- Timestamp:
- Sep 11, 2010, 12:34:00 AM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/doc (added) merged: 7290-7292,7296-7300,7302-7304,7306-7312,7315-7318,7323,7325,7327,7331-7332,7334-7335,7345-7347,7352-7353,7356-7357,7361,7363-7367,7371-7375,7388
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/util/StringUtils.cc
r7284 r7401 41 41 namespace orxonox 42 42 { 43 /// A blank string (""). Used to return a blank string by reference. 43 44 std::string BLANKSTRING; 44 45 46 /// Returns a string of a unique number. This function is guaranteed to never return the same string twice. 45 47 std::string getUniqueNumberString() 46 48 { … … 48 50 } 49 51 50 /** 51 @brief Removes all whitespaces from a string. 52 @param str The string to strip 53 */ 52 /// Removes all whitespaces from a string. 54 53 void strip(std::string* str) 55 54 { … … 63 62 } 64 63 65 /** 66 @brief Returns a copy of a string without whitespaces. 67 @param str The string to strip 68 @return The stripped line 69 */ 64 /// Returns a copy of a string without whitespaces. 70 65 std::string getStripped(const std::string& str) 71 66 { … … 75 70 } 76 71 77 /** 78 @brief Returns a copy of a string without trailing whitespaces. 79 @param str The string 80 @return The modified copy 81 */ 72 /// Returns a copy of a string without trailing whitespaces. 82 73 std::string removeTrailingWhitespaces(const std::string& str) 83 74 { … … 90 81 91 82 /** 92 @brief Returns the position of the next quot ein the string, starting with start.83 @brief Returns the position of the next quotation mark in the string, starting with start. 93 84 @param str The string 94 @param start The startposition95 @return The position of the next quot e (std::string::npos if there is no next quote)85 @param start The first position to look at 86 @return The position of the next quotation mark (@c std::string::npos if there is none) 96 87 */ 97 88 size_t getNextQuote(const std::string& str, size_t start) … … 115 106 116 107 /** 117 @brief Returns true if pos is between two quot es.108 @brief Returns true if pos is between two quotation marks. 118 109 @param str The string 119 110 @param pos The position to check 120 @return True if pos is between two quot es111 @return True if pos is between two quotation marks 121 112 */ 122 113 bool isBetweenQuotes(const std::string& str, size_t pos) … … 140 131 } 141 132 142 /** 143 @brief Returns true if the string contains something like '..."between quotes"...'. 144 @param The string 145 @return True if there is something between quotes 146 */ 133 /// Returns true if the string contains something like '..."between quotaton marks"...'. 147 134 bool hasStringBetweenQuotes(const std::string& str) 148 135 { … … 152 139 } 153 140 154 /** 155 @brief If the string contains something like '..."between quotes"...' then 'between quotes' gets returned (without quotes). 156 @param The string 157 @param The string between the quotes 158 */ 141 /// If the string contains something like '..."between quotaton marks"...' then 'between quotaton marks' gets returned, otherwise "". 159 142 std::string getStringBetweenQuotes(const std::string& str) 160 143 { … … 168 151 169 152 /** 170 @brief Removes enclosing quotes if available (including whitespaces at the outside of the quotes). 171 @brief str The string to strip 172 @return The string with removed quotes 153 @brief Removes enclosing quotation marks if available (including whitespaces at the outside of the quotation marks). 154 @return The striped string without quotation marks 173 155 */ 174 156 std::string stripEnclosingQuotes(const std::string& str) … … 208 190 209 191 /** 210 @brief Removes enclosing {braces} (braces must be exactly on the beginning and the end of the string). 211 @param str The string to strip 212 @return The striped string 192 @brief Removes enclosing braces '{' and '}' (the braces must be exactly on the beginning and the end of the string). 193 @return The striped string without braces 213 194 */ 214 195 std::string stripEnclosingBraces(const std::string& str) … … 224 205 /** 225 206 @brief Determines if a string is a comment (starts with a comment-symbol). 226 @param str The string to check227 @return True = it's a comment228 207 229 208 A comment is defined by a leading '#', '%', ';' or '//'. … … 253 232 } 254 233 255 /** 256 @brief Determines if a string is empty (contains only whitespaces). 257 @param str The string to check 258 @return True = it's empty 259 */ 234 /// Determines if a string is empty (contains only whitespaces). 260 235 bool isEmpty(const std::string& str) 261 236 { … … 263 238 } 264 239 265 /** 266 @brief Determines if a string contains only numbers and maximal one '.'. 267 @param str The string to check 268 @return True = it's a number 269 */ 240 /// Determines if a string contains only numbers and maximal one '.'. 270 241 bool isNumeric(const std::string& str) 271 242 { … … 288 259 /** 289 260 @brief Adds backslashes to the given string which makes special chars visible. Existing slashes will be doubled. 290 @param str The string to manipulate 291 @return The string with added slashes 261 262 This function converts all special chars like line breaks, tabs, quotation marks etc. into 263 a human readable format by adding a backslash. So for example "\n" will be converted to 264 "\\" + "n". 265 266 This is usually used when a string is written to a file. 267 268 @see removeSlashes 292 269 */ 293 270 std::string addSlashes(const std::string& str) … … 320 297 /** 321 298 @brief Removes backslashes from the given string. Double backslashes are interpreted as one backslash. 322 @param str The string to manipulate 323 @return The string with removed slashes 299 300 This function removes all backslashes and converts the human readable equivalents of 301 special chars like "\\" + "n" into their real meaning (in this case a line break or "\n"). 302 303 This is usually used when reading a string from a file. 304 305 @see addSlashes 324 306 */ 325 307 std::string removeSlashes(const std::string& str) … … 361 343 } 362 344 363 /** 364 @brief Replaces each char between A and Z with its lowercase equivalent. 365 @param str The string to convert 366 */ 345 /// Replaces each char between A and Z with its lowercase equivalent. 367 346 void lowercase(std::string* str) 368 347 { … … 373 352 } 374 353 375 /** 376 @brief Returns a copy of the given string without uppercase chars. 377 @param str The string 378 @return The copy 379 */ 354 /// Returns a copy of the given string where all chars are converted to lowercase. 380 355 std::string getLowercase(const std::string& str) 381 356 { … … 385 360 } 386 361 387 /** 388 @brief Replaces each char between a and z with its uppercase equivalent. 389 @param str The string to convert 390 */ 362 /// Replaces each char between a and z with its uppercase equivalent. 391 363 void uppercase(std::string* str) 392 364 { … … 397 369 } 398 370 399 /** 400 @brief Returns a copy of the given string without lowercase chars. 401 @param str The string 402 @return The copy 403 */ 371 /// Returns a copy of the given string where all chars are converted to uppercase. 404 372 std::string getUppercase(const std::string& str) 405 373 { … … 411 379 /** 412 380 @brief Compares two strings ignoring different casing. 413 @param s1 First string 414 @param s2 Second string 381 @return s1 == s1 -> returns 0 / s1 < s2 -> returns -1 / s1 >= s2 -> returns 1 415 382 */ 416 383 int nocaseCmp(const std::string& s1, const std::string& s2) … … 438 405 439 406 /** 440 @brief Compares the first 'len'chars of two strings ignoring different casing.407 @brief Compares the first @a len chars of two strings ignoring different casing. 441 408 @param s1 First string 442 409 @param s2 Second string … … 463 430 } 464 431 465 /** 466 @brief Returns true if the string contains a comment, introduced by #, %, ; or //. 432 /// Returns true if the string contains a comment, introduced by #, %, ; or //. 433 bool hasComment(const std::string& str) 434 { 435 return (getCommentPosition(str) != std::string::npos); 436 } 437 438 /// If the string contains a comment, the comment gets returned (including the comment symbol), an empty string otherwise. 439 std::string getComment(const std::string& str) 440 { 441 return str.substr(getCommentPosition(str)); 442 } 443 444 /// If the string contains a comment, the position of the comment-symbol gets returned, @c std::string::npos otherwise. 445 size_t getCommentPosition(const std::string& str) 446 { 447 return getNextCommentPosition(str, 0); 448 } 449 450 /** 451 @brief Returns the position of the next comment-symbol, starting with @a start. 467 452 @param str The string 468 @return True if the string contains a comment 469 */ 470 bool hasComment(const std::string& str) 471 { 472 return (getCommentPosition(str) != std::string::npos); 473 } 474 475 /** 476 @brief If the string contains a comment, the comment gets returned (including the comment symbol), an empty string otherwise. 477 @param str The string 478 @return The comment 479 */ 480 std::string getComment(const std::string& str) 481 { 482 return str.substr(getCommentPosition(str)); 483 } 484 485 /** 486 @brief If the string contains a comment, the position of the comment-symbol gets returned, std::string::npos otherwise. 487 @param str The string 488 @return The position 489 */ 490 size_t getCommentPosition(const std::string& str) 491 { 492 return getNextCommentPosition(str, 0); 493 } 494 495 /** 496 @brief Returns the position of the next comment-symbol, starting with start. 497 @param str The string 498 @param start The startposition 499 @return The position 453 @param start The first position to look at 500 454 */ 501 455 size_t getNextCommentPosition(const std::string& str, size_t start)
Note: See TracChangeset
for help on using the changeset viewer.