diff --git a/mozilla/string/obsolete/nsStr.cpp b/mozilla/string/obsolete/nsStr.cpp index 2b65f495e23..84a6a8b21d0 100644 --- a/mozilla/string/obsolete/nsStr.cpp +++ b/mozilla/string/obsolete/nsStr.cpp @@ -586,7 +586,6 @@ PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnor return kNotFound; } - /** * Compare source and dest strings, up to an (optional max) number of chars * @param aDest is the first str to compare @@ -609,13 +608,39 @@ PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PR return 1; } - PRInt32 maxlen=(aSource.mLength=aSource.mLength) { + //if you're here, then both dest and source have valid lengths + //and there's enough room in dest (at offset) to contain source. + (*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDestOffset,aSource.mStr,0,aSource.mLength); + } + } +} + //---------------------------------------------------------------------------------------- PRBool nsStr::Alloc(nsStr& aDest,PRUint32 aCount) { diff --git a/mozilla/string/obsolete/nsStr.h b/mozilla/string/obsolete/nsStr.h index f253391f74d..c6c7fdf11ad 100644 --- a/mozilla/string/obsolete/nsStr.h +++ b/mozilla/string/obsolete/nsStr.h @@ -410,6 +410,8 @@ struct NS_COM nsStr { static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset); static PRInt32 RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset); + static void Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 anOffset); + static PRBool DidAcquireMemory(void); /** diff --git a/mozilla/string/obsolete/nsString.cpp b/mozilla/string/obsolete/nsString.cpp index aacf1443a9f..520d7e9b6f0 100644 --- a/mozilla/string/obsolete/nsString.cpp +++ b/mozilla/string/obsolete/nsString.cpp @@ -405,6 +405,73 @@ nsCString& nsCString::ReplaceChar(const char* aSet, PRUnichar aNewChar){ return *this; } +/** + * This method is used to replace all occurances of the + * given target with the given replacement + * + * @param + * @return *this + */ +nsCString& nsCString::ReplaceSubstring(const char* aTarget,const char* aNewValue){ + if(aTarget && aNewValue) { + + PRInt32 len=strlen(aTarget); + if(0=aSource.mLength) { + //if you're here, then both dest and source have valid lengths + //and there's enough room in dest (at offset) to contain source. + (*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDestOffset,aSource.mStr,0,aSource.mLength); + } + } +} + //---------------------------------------------------------------------------------------- PRBool nsStr::Alloc(nsStr& aDest,PRUint32 aCount) { diff --git a/mozilla/xpcom/ds/nsStr.h b/mozilla/xpcom/ds/nsStr.h index f253391f74d..c6c7fdf11ad 100644 --- a/mozilla/xpcom/ds/nsStr.h +++ b/mozilla/xpcom/ds/nsStr.h @@ -410,6 +410,8 @@ struct NS_COM nsStr { static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset); static PRInt32 RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset); + static void Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 anOffset); + static PRBool DidAcquireMemory(void); /** diff --git a/mozilla/xpcom/ds/nsString.cpp b/mozilla/xpcom/ds/nsString.cpp index aacf1443a9f..520d7e9b6f0 100644 --- a/mozilla/xpcom/ds/nsString.cpp +++ b/mozilla/xpcom/ds/nsString.cpp @@ -405,6 +405,73 @@ nsCString& nsCString::ReplaceChar(const char* aSet, PRUnichar aNewChar){ return *this; } +/** + * This method is used to replace all occurances of the + * given target with the given replacement + * + * @param + * @return *this + */ +nsCString& nsCString::ReplaceSubstring(const char* aTarget,const char* aNewValue){ + if(aTarget && aNewValue) { + + PRInt32 len=strlen(aTarget); + if(0=aSource.mLength) { + //if you're here, then both dest and source have valid lengths + //and there's enough room in dest (at offset) to contain source. + (*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDestOffset,aSource.mStr,0,aSource.mLength); + } + } +} + //---------------------------------------------------------------------------------------- PRBool nsStr::Alloc(nsStr& aDest,PRUint32 aCount) { diff --git a/mozilla/xpcom/string/obsolete/nsStr.h b/mozilla/xpcom/string/obsolete/nsStr.h index f253391f74d..c6c7fdf11ad 100644 --- a/mozilla/xpcom/string/obsolete/nsStr.h +++ b/mozilla/xpcom/string/obsolete/nsStr.h @@ -410,6 +410,8 @@ struct NS_COM nsStr { static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset); static PRInt32 RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset); + static void Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 anOffset); + static PRBool DidAcquireMemory(void); /** diff --git a/mozilla/xpcom/string/obsolete/nsString.cpp b/mozilla/xpcom/string/obsolete/nsString.cpp index aacf1443a9f..520d7e9b6f0 100644 --- a/mozilla/xpcom/string/obsolete/nsString.cpp +++ b/mozilla/xpcom/string/obsolete/nsString.cpp @@ -405,6 +405,73 @@ nsCString& nsCString::ReplaceChar(const char* aSet, PRUnichar aNewChar){ return *this; } +/** + * This method is used to replace all occurances of the + * given target with the given replacement + * + * @param + * @return *this + */ +nsCString& nsCString::ReplaceSubstring(const char* aTarget,const char* aNewValue){ + if(aTarget && aNewValue) { + + PRInt32 len=strlen(aTarget); + if(0