| 304 | } |
| 305 | |
| 306 | StringBuffer StringBuffer::substring(const U32 start, const U32 len) const |
| 307 | { |
| 308 | // Deal with bonehead user input. |
| 309 | if(start >= length() || len == 0) |
| 310 | { |
| 311 | // Either they asked beyond the end of the string or we're null. Either |
| 312 | // way, let's give them a null string. |
| 313 | return StringBuffer(""); |
| 314 | } |
| 315 | |
| 316 | AssertFatal(start < length(), "StringBuffer::substring - invalid start!"); |
| 317 | AssertFatal(start+len <= length(), "StringBuffer::substring - invalid len!"); |
| 318 | AssertFatal(len > 0, "StringBuffer::substring - len must be >= 1."); |
| 319 | |
| 320 | StringBuffer tmp; |
| 321 | tmp.mBuffer.clear(); |
| 322 | for(U32 i=0; i<len; i++) |
| 323 | tmp.mBuffer.push_back(mBuffer[start+i]); |
| 324 | if(tmp.mBuffer.last() != 0) tmp.mBuffer.push_back(0); |
| 325 | |
| 326 | // Make sure this shit is terminated; we might get a totally empty string. |
| 327 | if(!tmp.mBuffer.size()) |
| 328 | tmp.mBuffer.push_back(0); |
| 329 | |
| 330 | return tmp; |
| 331 | } |
| 332 | |
| 333 | UTF8* StringBuffer::createSubstring8(const U32 start, const U32 len) const |
| 334 | { |
no test coverage detected