2x perf. improvement StripChar(); r=rods

git-svn-id: svn://10.0.0.236/trunk@64269 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rickg%netscape.com
2000-03-28 00:02:41 +00:00
parent 825b7a047e
commit 7b539e04c1
6 changed files with 180 additions and 36 deletions

View File

@@ -360,16 +360,40 @@ void nsCString::ToUpperCase(nsCString& aString) const {
* This method is used to remove all occurances of the
* characters found in aSet from this string.
*
* @update gess 11/02/99
* @update rickg 03.27.2000
* @param aChar -- char to be stripped
* @return *this
*/
nsCString& nsCString::StripChar(PRUnichar aChar,PRInt32 anOffset){
anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset,mLength);
while(kNotFound<anOffset) {
nsStr::Delete(*this,anOffset,1);
anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset,mLength);
if(mLength && (anOffset<PRInt32(mLength))) {
if(eOneByte==mCharSize) {
char* to = mStr + anOffset;
char* from = mStr + anOffset;
char* end = mStr + mLength;
while (from < end) {
char theChar = *from++;
if(aChar!=theChar) {
*to++ = theChar;
}
}
*to = 0; //add the null
mLength=to - mStr;
}
else {
PRUnichar* to = mUStr + anOffset;
PRUnichar* from = mUStr + anOffset;
PRUnichar* end = mUStr + mLength;
while (from < end) {
PRUnichar theChar = *from++;
if(aChar!=theChar) {
*to++ = theChar;
}
}
*to = 0; //add the null
mLength=to - mUStr;
}
}
return *this;
}