Changeset 9047 for code/branches/testing/src/libraries/util/SubString.cc
- Timestamp:
- Mar 18, 2012, 6:43:24 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/testing/src/libraries/util/SubString.cc
r8858 r9047 87 87 @param other The other SubString 88 88 @param begin The beginning of the subset 89 90 The subset ranges from the token with index @a begin to the end of the tokens. 91 If @a begin is greater than the greatest index, the new SubString will be empty. 92 */ 93 SubString::SubString(const SubString& other, unsigned int begin) 94 { 95 for (unsigned int i = begin; i < other.size(); ++i) 96 { 97 this->tokens_.push_back(other[i]); 98 this->bTokenInSafemode_.push_back(other.isInSafemode(i)); 99 } 100 } 101 102 /** 103 @brief creates a new SubString based on a subset of an other SubString. 104 @param other The other SubString 105 @param begin The beginning of the subset 106 @param end The end of the subset 107 108 The subset ranges from the token with index @a begin until (but not including) the token with index @a end. 109 If @a begin or @a end are beyond the allowed index, the resulting SubString will be empty. 110 */ 111 SubString::SubString(const SubString& other, unsigned int begin, unsigned int end) 112 { 113 for (unsigned int i = begin; i < std::min(other.size(), end); ++i) 114 { 115 this->tokens_.push_back(other[i]); 116 this->bTokenInSafemode_.push_back(other.isInSafemode(i)); 89 @param length The length of the subset 90 91 The subset ranges from the token with index @a begin and contains @a length elements. 92 */ 93 SubString::SubString(const SubString& other, size_t begin, size_t length) 94 { 95 for (size_t i = 0; i < length; ++i) 96 { 97 if (begin + i >= other.size()) 98 break; 99 100 this->tokens_.push_back(other[begin + i]); 101 this->bTokenInSafemode_.push_back(other.isInSafemode(begin + i)); 117 102 } 118 103 } … … 123 108 @param argv An array of pointers to the arguments 124 109 */ 125 SubString::SubString( unsigned int argc, const char** argv)126 { 127 for (unsigned int i = 0; i < argc; ++i)110 SubString::SubString(size_t argc, const char** argv) 111 { 112 for (size_t i = 0; i < argc; ++i) 128 113 { 129 114 this->tokens_.push_back(std::string(argv[i])); … … 158 143 159 144 /** 160 @copydoc operator==161 */162 bool SubString::compare(const SubString& other) const163 {164 return (*this == other);165 }166 167 /**168 145 @brief Compares this SubString to another SubString and returns true if the first @a length values match. 169 146 @param other The other SubString 170 147 @param length How many tokens to compare 171 148 */ 172 bool SubString::compare(const SubString& other, unsigned int length) const173 { 174 if ( length > this->size() || length > other.size())149 bool SubString::compare(const SubString& other, size_t length) const 150 { 151 if (std::min(length, this->size()) != std::min(length, other.size())) 175 152 return false; 176 153 177 for ( unsigned int i = 0; i < length; ++i)154 for (size_t i = 0; i < std::min(length, this->size()); ++i) 178 155 if ((this->tokens_[i] != other.tokens_[i]) || (this->bTokenInSafemode_[i] != other.bTokenInSafemode_[i])) 179 156 return false; 157 180 158 return true; 181 159 } … … 196 174 SubString& SubString::operator+=(const SubString& other) 197 175 { 198 for ( unsigned int i = 0; i < other.size(); ++i)176 for (size_t i = 0; i < other.size(); ++i) 199 177 { 200 178 this->tokens_.push_back(other[i]); … … 207 185 @copydoc SubString(const std::string&,const std::string&,const std::string&,bool,char,bool,char,bool,char,char,bool,char) 208 186 */ 209 unsigned int SubString::split(const std::string& line,210 211 212 187 size_t SubString::split(const std::string& line, 188 const std::string& delimiters, const std::string& delimiterNeighbours, bool bAllowEmptyEntries, 189 char escapeChar, bool bRemoveEscapeChar, char safemodeChar, bool bRemoveSafemodeChar, 190 char openparenthesisChar, char closeparenthesisChar, bool bRemoveParenthesisChars, char commentChar) 213 191 { 214 192 this->tokens_.clear(); … … 228 206 { 229 207 std::string retVal = this->tokens_[0]; 230 for ( unsigned int i = 1; i < this->tokens_.size(); ++i)208 for (size_t i = 1; i < this->tokens_.size(); ++i) 231 209 retVal += delimiter + this->tokens_[i]; 232 210 return retVal; … … 239 217 @brief Creates a subset of this SubString. 240 218 @param begin The beginning of the subset 219 @param length The length of the subset 241 220 @return A new SubString containing the defined subset. 242 221 243 The subset ranges from the token with index @a begin to the end of the tokens. 244 If @a begin is greater than the greatest index, the new SubString will be empty. 222 The subset ranges from the token with index @a begin and contains @a length elements. 245 223 246 224 This function is added for your convenience, and does the same as 247 SubString::SubString(const SubString& other, unsigned int begin) 248 */ 249 SubString SubString::subSet(unsigned int begin) const 250 { 251 return SubString(*this, begin); 252 } 253 254 /** 255 @brief Creates a subset of this SubString. 256 @param begin The beginning of the subset 257 @param end The ending of the subset 258 @return A new SubString containing the defined subset. 259 260 The subset ranges from the token with index @a begin until (but not including) the token with index @a end. 261 If @a begin or @a end are beyond the allowed index, the resulting SubString will be empty. 262 263 This function is added for your convenience, and does the same as 264 SubString::SubString(const SubString& other, unsigned int begin, unsigned int end) 265 */ 266 SubString SubString::subSet(unsigned int begin, unsigned int end) const 267 { 268 return SubString(*this, begin, end); 225 SubString::SubString(const SubString& other, size_t begin, size_t length) 226 */ 227 SubString SubString::subSet(size_t begin, size_t length) const 228 { 229 return SubString(*this, begin, length); 269 230 } 270 231 … … 298 259 { 299 260 SPLIT_LINE_STATE state = start_state; 300 unsigned int i = 0;301 unsigned int fallBackNeighbours = 0;261 size_t i = 0; 262 size_t fallBackNeighbours = 0; 302 263 303 264 std::string token; … … 514 475 { 515 476 orxout(debug_output) << "Substring-information::count=" << this->tokens_.size() << " ::"; 516 for ( unsigned int i = 0; i < this->tokens_.size(); ++i)477 for (size_t i = 0; i < this->tokens_.size(); ++i) 517 478 orxout(debug_output) << "s" << i << "='" << this->tokens_[i].c_str() << "'::"; 518 479 orxout(debug_output) << endl;
Note: See TracChangeset
for help on using the changeset viewer.