Changeset 7327 for code/branches/doc/src/libraries/util/StringUtils.cc
- Timestamp:
- Sep 3, 2010, 12:19:53 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/doc/src/libraries/util/StringUtils.cc
r7297 r7327 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 str 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 str The string between the quotes 157 */ 141 /// If the string contains something like '..."between quotaton marks"...' then 'between quotaton marks' gets returned, otherwise "". 158 142 std::string getStringBetweenQuotes(const std::string& str) 159 143 { … … 167 151 168 152 /** 169 @brief Removes enclosing quotes if available (including whitespaces at the outside of the quotes). 170 @param str The string to strip 171 @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 172 155 */ 173 156 std::string stripEnclosingQuotes(const std::string& str) … … 207 190 208 191 /** 209 @brief Removes enclosing {braces} (braces must be exactly on the beginning and the end of the string). 210 @param str The string to strip 211 @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 212 194 */ 213 195 std::string stripEnclosingBraces(const std::string& str) … … 223 205 /** 224 206 @brief Determines if a string is a comment (starts with a comment-symbol). 225 @param str The string to check226 @return True = it's a comment227 207 228 208 A comment is defined by a leading '#', '%', ';' or '//'. … … 252 232 } 253 233 254 /** 255 @brief Determines if a string is empty (contains only whitespaces). 256 @param str The string to check 257 @return True = it's empty 258 */ 234 /// Determines if a string is empty (contains only whitespaces). 259 235 bool isEmpty(const std::string& str) 260 236 { … … 262 238 } 263 239 264 /** 265 @brief Determines if a string contains only numbers and maximal one '.'. 266 @param str The string to check 267 @return True = it's a number 268 */ 240 /// Determines if a string contains only numbers and maximal one '.'. 269 241 bool isNumeric(const std::string& str) 270 242 { … … 287 259 /** 288 260 @brief Adds backslashes to the given string which makes special chars visible. Existing slashes will be doubled. 289 @param str The string to manipulate 290 @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 291 269 */ 292 270 std::string addSlashes(const std::string& str) … … 319 297 /** 320 298 @brief Removes backslashes from the given string. Double backslashes are interpreted as one backslash. 321 @param str The string to manipulate 322 @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 323 306 */ 324 307 std::string removeSlashes(const std::string& str) … … 360 343 } 361 344 362 /** 363 @brief Replaces each char between A and Z with its lowercase equivalent. 364 @param str The string to convert 365 */ 345 /// Replaces each char between A and Z with its lowercase equivalent. 366 346 void lowercase(std::string* str) 367 347 { … … 372 352 } 373 353 374 /** 375 @brief Returns a copy of the given string without uppercase chars. 376 @param str The string 377 @return The copy 378 */ 354 /// Returns a copy of the given string where all chars are converted to lowercase. 379 355 std::string getLowercase(const std::string& str) 380 356 { … … 384 360 } 385 361 386 /** 387 @brief Replaces each char between a and z with its uppercase equivalent. 388 @param str The string to convert 389 */ 362 /// Replaces each char between a and z with its uppercase equivalent. 390 363 void uppercase(std::string* str) 391 364 { … … 396 369 } 397 370 398 /** 399 @brief Returns a copy of the given string without lowercase chars. 400 @param str The string 401 @return The copy 402 */ 371 /// Returns a copy of the given string where all chars are converted to uppercase. 403 372 std::string getUppercase(const std::string& str) 404 373 { … … 410 379 /** 411 380 @brief Compares two strings ignoring different casing. 412 @param s1 First string 413 @param s2 Second string 381 @return s1 == s1 -> returns 0 / s1 < s2 -> returns -1 / s1 >= s2 -> returns 1 414 382 */ 415 383 int nocaseCmp(const std::string& s1, const std::string& s2) … … 437 405 438 406 /** 439 @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. 440 408 @param s1 First string 441 409 @param s2 Second string … … 462 430 } 463 431 464 /** 465 @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. 466 452 @param str The string 467 @return True if the string contains a comment 468 */ 469 bool hasComment(const std::string& str) 470 { 471 return (getCommentPosition(str) != std::string::npos); 472 } 473 474 /** 475 @brief If the string contains a comment, the comment gets returned (including the comment symbol), an empty string otherwise. 476 @param str The string 477 @return The comment 478 */ 479 std::string getComment(const std::string& str) 480 { 481 return str.substr(getCommentPosition(str)); 482 } 483 484 /** 485 @brief If the string contains a comment, the position of the comment-symbol gets returned, std::string::npos otherwise. 486 @param str The string 487 @return The position 488 */ 489 size_t getCommentPosition(const std::string& str) 490 { 491 return getNextCommentPosition(str, 0); 492 } 493 494 /** 495 @brief Returns the position of the next comment-symbol, starting with start. 496 @param str The string 497 @param start The startposition 498 @return The position 453 @param start The first position to look at 499 454 */ 500 455 size_t getNextCommentPosition(const std::string& str, size_t start)
Note: See TracChangeset
for help on using the changeset viewer.