PRInt32 nsString::Insert(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) { aCount=(aCount>aCopy.mLength) ? aCopy.mLength : aCount; if(aCount>0) {   if(anOffset>=mLength){ Append(aCopy,aCopy.mLength); return aCopy.mLength; }  if(mLength+aCount > mCapacity) { EnsureCapacityFor(mLength+aCount); }  PRUnichar* last = mStr + mLength; PRUnichar* first = mStr + anOffset-1; PRUnichar* next = mStr + mLength + aCount;   while(first<last) { *next=*last; next--; last--; }   next = last; first = aCopy.mStr - 1; last = aCopy.mStr + aCount;  while (++first<last) { *(++next)=*first; } mLength+=aCount; } return aCount; }
nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1) {InsertWithConversion(aChar, anOffset, aCount); return *this;}
PRInt32 nsString::Insert(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) {  aCount=(aCount>aCopy.mLength) ? aCopy.mLength : aCount; //don't try to copy more than you are given  if(aCount>0) {    //1st optimization: If you're inserting at end, then simply append!    if(anOffset>=mLength){      Append(aCopy,aCopy.mLength);      return aCopy.mLength;    }    if(mLength+aCount > mCapacity) {      EnsureCapacityFor(mLength+aCount);    }    PRUnichar* last = mStr + mLength;    PRUnichar* first = mStr + anOffset-1;    PRUnichar* next = mStr + mLength + aCount;      //Copy rightmost chars, up to offset+aCount...    while(first<last) {      *next=*last;        next--;      last--;    }    //now insert new chars, starting at offset    next = last;    first = aCopy.mStr - 1;    last = aCopy.mStr + aCount;    while (++first<last) {      *(++next)=*first;    }    mLength+=aCount;  }  return aCount;}