Changeset 994 for code/branches/core2/src/util/String.cc
- Timestamp:
- Apr 5, 2008, 5:54:24 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.