From d682c47b104cadf38a4b95e2cd2ca0a3edd9109c Mon Sep 17 00:00:00 2001 From: rickg Date: Sat, 25 Apr 1998 19:44:35 +0000 Subject: [PATCH] added Append(unichar) git-svn-id: svn://10.0.0.236/trunk@669 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/base/src/nsString.cpp | 41 ++++++++++++++++++++++ mozilla/base/src/nsString.h | 1 + mozilla/string/obsolete/nsString.cpp | 41 ++++++++++++++++++++++ mozilla/string/obsolete/nsString.h | 1 + mozilla/xpcom/ds/nsString.cpp | 41 ++++++++++++++++++++++ mozilla/xpcom/ds/nsString.h | 1 + mozilla/xpcom/string/obsolete/nsString.cpp | 41 ++++++++++++++++++++++ mozilla/xpcom/string/obsolete/nsString.h | 1 + 8 files changed, 168 insertions(+) diff --git a/mozilla/base/src/nsString.cpp b/mozilla/base/src/nsString.cpp index a4c6b86e46a..8e45375800a 100644 --- a/mozilla/base/src/nsString.cpp +++ b/mozilla/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