From b0e2f9b69717eaf9686785ab4e7c8bc5bdd3f02e Mon Sep 17 00:00:00 2001 From: rickg Date: Sat, 25 Apr 1998 19:44:35 +0000 Subject: [PATCH] added Append(unichar) --- base/src/nsString.cpp | 41 ++++++++++++++++++++++++++++++ base/src/nsString.h | 1 + string/obsolete/nsString.cpp | 41 ++++++++++++++++++++++++++++++ string/obsolete/nsString.h | 1 + xpcom/ds/nsString.cpp | 41 ++++++++++++++++++++++++++++++ xpcom/ds/nsString.h | 1 + xpcom/string/obsolete/nsString.cpp | 41 ++++++++++++++++++++++++++++++ xpcom/string/obsolete/nsString.h | 1 + 8 files changed, 168 insertions(+) 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