diff --git a/base/src/nsString.cpp b/base/src/nsString.cpp index a4c6b86e46a3..8e45375800ac 100644 --- a/base/src/nsString.cpp +++ b/base/src/nsString.cpp @@ -965,6 +965,47 @@ PRInt32 nsString::Insert(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) { return aCount; } + +/** + * Insert a single unicode char into this string at + * a specified offset. + * + * @update gess4/22/98 + * @param aChar char to be inserted into this string + * @param anOffset is insert pos in str + * @return the number of chars inserted into this string + */ +PRInt32 nsString::Insert(PRUnichar aChar,PRInt32 anOffset){ + + //1st optimization: If you're inserting at end, then simply append! + if(anOffset mCapacity) { + EnsureCapacityFor(mLength+1); + } + + PRUnichar* last = mStr + mLength; + PRUnichar* first = mStr + anOffset-1; + PRUnichar* next = mStr + mLength + 1; + + //Copy rightmost chars, up to offset+aCount... + while(first mCapacity) { + EnsureCapacityFor(mLength+1); + } + + PRUnichar* last = mStr + mLength; + PRUnichar* first = mStr + anOffset-1; + PRUnichar* next = mStr + mLength + 1; + + //Copy rightmost chars, up to offset+aCount... + while(first mCapacity) { + EnsureCapacityFor(mLength+1); + } + + PRUnichar* last = mStr + mLength; + PRUnichar* first = mStr + anOffset-1; + PRUnichar* next = mStr + mLength + 1; + + //Copy rightmost chars, up to offset+aCount... + while(first mCapacity) { + EnsureCapacityFor(mLength+1); + } + + PRUnichar* last = mStr + mLength; + PRUnichar* first = mStr + anOffset-1; + PRUnichar* next = mStr + mLength + 1; + + //Copy rightmost chars, up to offset+aCount... + while(first