Changeset 7238 for code/branches/consolecommands3/src/libraries/util
- Timestamp:
- Aug 28, 2010, 4:48:48 PM (14 years ago)
- Location:
- code/branches/consolecommands3/src/libraries/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/consolecommands3/src/libraries/util/StringUtils.cc
r6424 r7238 514 514 @return Number of replacements 515 515 */ 516 _UtilExportsize_t replaceCharacters(std::string& str, char target, char replacement)516 size_t replaceCharacters(std::string& str, char target, char replacement) 517 517 { 518 518 size_t j = 0; … … 527 527 return j; 528 528 } 529 530 /** 531 @brief Calculates the Levenshtein distance between two strings. 532 533 The Levenshtein distance is defined by the number of transformations needed to convert str1 534 into str2. Possible transformations are substituted, added, or removed characters. 535 */ 536 unsigned int getLevenshteinDistance(const std::string& str1, const std::string& str2) 537 { 538 size_t cols = str1.size() + 1; 539 size_t rows = str2.size() + 1; 540 int matrix[rows][cols]; 541 542 for (size_t r = 0; r < rows; ++r) 543 for (size_t c = 0; c < cols; ++c) 544 matrix[r][c] = 0; 545 546 for (size_t i = 1; i < cols; ++i) 547 matrix[0][i] = i; 548 for (size_t i = 1; i < rows; ++i) 549 matrix[i][0] = i; 550 551 for (size_t r = 1; r < rows; ++r) 552 for (size_t c = 1; c < cols; ++c) 553 matrix[r][c] = (str1[c-1] != str2[r-1]); 554 555 for (size_t r = 1; r < rows; ++r) 556 for (size_t c = 1; c < cols; ++c) 557 matrix[r][c] = std::min(std::min(matrix[r-1][c] + 1, matrix[r][c-1] + 1), matrix[r-1][c-1] + (str1[c-1] != str2[r-1])); 558 559 return matrix[rows-1][cols-1]; 560 } 529 561 } -
code/branches/consolecommands3/src/libraries/util/StringUtils.h
r5738 r7238 43 43 _UtilExport std::string getUniqueNumberString(); 44 44 45 _UtilExport void strip(std::string* str);46 _UtilExport std::string getStripped(const std::string& str);45 _UtilExport void strip(std::string* str); 46 _UtilExport std::string getStripped(const std::string& str); 47 47 48 _UtilExport std::string removeTrailingWhitespaces(const std::string& str);48 _UtilExport std::string removeTrailingWhitespaces(const std::string& str); 49 49 50 _UtilExport size_t getNextQuote(const std::string& str, size_t start);51 _UtilExport bool isBetweenQuotes(const std::string& str, size_t pos);50 _UtilExport size_t getNextQuote(const std::string& str, size_t start); 51 _UtilExport bool isBetweenQuotes(const std::string& str, size_t pos); 52 52 53 _UtilExport bool hasStringBetweenQuotes(const std::string& str);54 _UtilExport std::string getStringBetweenQuotes(const std::string& str);53 _UtilExport bool hasStringBetweenQuotes(const std::string& str); 54 _UtilExport std::string getStringBetweenQuotes(const std::string& str); 55 55 56 _UtilExport std::string stripEnclosingQuotes(const std::string& str);57 _UtilExport std::string stripEnclosingBraces(const std::string& str);56 _UtilExport std::string stripEnclosingQuotes(const std::string& str); 57 _UtilExport std::string stripEnclosingBraces(const std::string& str); 58 58 59 _UtilExport bool isEmpty(const std::string& str);60 _UtilExport bool isComment(const std::string& str);61 _UtilExport bool isNumeric(const std::string& str);59 _UtilExport bool isEmpty(const std::string& str); 60 _UtilExport bool isComment(const std::string& str); 61 _UtilExport bool isNumeric(const std::string& str); 62 62 63 _UtilExport std::string addSlashes(const std::string& str);64 _UtilExport std::string removeSlashes(const std::string& str);63 _UtilExport std::string addSlashes(const std::string& str); 64 _UtilExport std::string removeSlashes(const std::string& str); 65 65 66 _UtilExport void lowercase(std::string* str);67 _UtilExport std::string getLowercase(const std::string& str);66 _UtilExport void lowercase(std::string* str); 67 _UtilExport std::string getLowercase(const std::string& str); 68 68 69 _UtilExport void uppercase(std::string* str);70 _UtilExport std::string getUppercase(const std::string& str);69 _UtilExport void uppercase(std::string* str); 70 _UtilExport std::string getUppercase(const std::string& str); 71 71 72 _UtilExport int nocaseCmp(const std::string& s1, const std::string& s2);73 _UtilExport int nocaseCmp(const std::string& s1, const std::string& s2, size_t len);72 _UtilExport int nocaseCmp(const std::string& s1, const std::string& s2); 73 _UtilExport int nocaseCmp(const std::string& s1, const std::string& s2, size_t len); 74 74 75 _UtilExport bool hasComment(const std::string& str);76 _UtilExport std::string getComment(const std::string& str);77 _UtilExport size_t getCommentPosition(const std::string& str);78 _UtilExport size_t getNextCommentPosition(const std::string& str, size_t start = 0);75 _UtilExport bool hasComment(const std::string& str); 76 _UtilExport std::string getComment(const std::string& str); 77 _UtilExport size_t getCommentPosition(const std::string& str); 78 _UtilExport size_t getNextCommentPosition(const std::string& str, size_t start = 0); 79 79 80 _UtilExport size_t replaceCharacters(std::string& str, char target, char replacement); 80 _UtilExport size_t replaceCharacters(std::string& str, char target, char replacement); 81 82 _UtilExport unsigned int getLevenshteinDistance(const std::string& str1, const std::string& str2); 81 83 } 82 84
Note: See TracChangeset
for help on using the changeset viewer.