| 289 | } |
| 290 | |
| 291 | StringBuffer StringBuffer::substring(const U32 start, const U32 len) const |
| 292 | { |
| 293 | // Deal with bonehead user input. |
| 294 | if(start >= length() || len == 0) |
| 295 | { |
| 296 | // Either they asked beyond the end of the string or we're null. Either |
| 297 | // way, let's give them a null string. |
| 298 | return StringBuffer(""); |
| 299 | } |
| 300 | |
| 301 | AssertFatal(start < length(), "StringBuffer::substring - invalid start!"); |
| 302 | AssertFatal(start+len <= length(), "StringBuffer::substring - invalid len!"); |
| 303 | AssertFatal(len > 0, "StringBuffer::substring - len must be >= 1."); |
| 304 | |
| 305 | StringBuffer tmp; |
| 306 | tmp.mBuffer.clear(); |
| 307 | for(S32 i=0; i<len; i++) |
| 308 | tmp.mBuffer.push_back(mBuffer[start+i]); |
| 309 | if(tmp.mBuffer.last() != 0) tmp.mBuffer.push_back(0); |
| 310 | |
| 311 | // Make sure this shit is terminated; we might get a totally empty string. |
| 312 | if(!tmp.mBuffer.size()) |
| 313 | tmp.mBuffer.push_back(0); |
| 314 | |
| 315 | return tmp; |
| 316 | } |
| 317 | |
| 318 | UTF8* StringBuffer::createSubstring8(const U32 start, const U32 len) const |
| 319 | { |