diff --git a/mozilla/xpcom/string/obsolete/Makefile.in b/mozilla/xpcom/string/obsolete/Makefile.in
index a5f9f3ee570..227dc11fb6a 100644
--- a/mozilla/xpcom/string/obsolete/Makefile.in
+++ b/mozilla/xpcom/string/obsolete/Makefile.in
@@ -35,22 +35,14 @@ REQUIRES = \
xpcom \
$(NULL)
-CPPSRCS = \
- nsTStringBaseObsolete.cpp \
+CPPSRCS = \
+ nsStringObsolete.cpp \
$(NULL)
-# nsStr.cpp \
-# nsString.cpp \
-# nsString2.cpp \
-
EXPORTS = \
nsString2.h \
$(NULL)
-# nsStr.h \
-# nsStrShared.h \
-# nsString.h \
-
# we don't want the shared lib, but we want to force the creation of a
# static lib.
FORCE_STATIC_LIB = 1
diff --git a/mozilla/xpcom/string/obsolete/README.html b/mozilla/xpcom/string/obsolete/README.html
deleted file mode 100644
index 145ef82872a..00000000000
--- a/mozilla/xpcom/string/obsolete/README.html
+++ /dev/null
@@ -1,35 +0,0 @@
-
-
-
- original string implementations soon to be replaced (the names you are using will still be good)
-
- These are the original string implementations by rickg and others.
- Most of the code here will be made obsolete by the new shared-buffer string (see bug #53065).
- For the most part, this change is intended to be transparent to clients.
- The type names you are using for strings now, e.g., nsString, nsAutoString, nsXPIDLString, will still be good,
- they will just refer to better, but compatible, implementations.
- If you're interested in learning how strings work, you probably want to start with
- nsAReadableString.
-
-
-
diff --git a/mozilla/xpcom/string/obsolete/nsStr.cpp b/mozilla/xpcom/string/obsolete/nsStr.cpp
deleted file mode 100644
index 357d34b06bf..00000000000
--- a/mozilla/xpcom/string/obsolete/nsStr.cpp
+++ /dev/null
@@ -1,1336 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: NPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Netscape Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/NPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Rick Gessner (original author)
- * Scott Collins
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the NPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the NPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef nsCharTraits_h___
-#include "nsCharTraits.h"
-#endif
-
-#include "nsStrPrivate.h"
-#include "nsStr.h"
-#include "bufferRoutines.h"
-#include //only used for printf
-#include "prdtoa.h"
-
-/******************************************************************************************
- MODULE NOTES:
-
- This file contains the nsStr data structure.
- This general purpose buffer management class is used as the basis for our strings.
- It's benefits include:
- 1. An efficient set of library style functions for manipulating nsStrs
- 2. Support for 1 and 2 byte character strings (which can easily be increased to n)
- 3. Unicode awareness and interoperability.
-
-*******************************************************************************************/
-
-//static const char* kCallFindChar = "For better performance, call FindChar() for targets whose length==1.";
-//static const char* kCallRFindChar = "For better performance, call RFindChar() for targets whose length==1.";
-
-static const PRUnichar gCommonEmptyBuffer[1] = {0};
-
-#ifdef NS_STR_STATS
-static PRBool gStringAcquiredMemory = PR_TRUE;
-#endif
-
-/**
- * This method initializes all the members of the nsStr structure
- *
- * @update gess10/30/98
- * @param
- * @return
- */
-void nsStrPrivate::Initialize(nsStr& aDest,eCharSize aCharSize) {
- aDest.mStr=(char*)gCommonEmptyBuffer;
- aDest.mLength=0;
- aDest.mCapacityAndFlags = 0;
- // handled by mCapacityAndFlags
- // aDest.SetInternalCapacity(0);
- // aDest.SetOwnsBuffer(PR_FALSE);
- aDest.SetCharSize(aCharSize);
-}
-
-/**
- * This method initializes all the members of the nsStr structure
- * @update gess10/30/98
- * @param
- * @return
- */
-void nsStrPrivate::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer){
- aDest.mStr=(aCString) ? aCString : (char*)gCommonEmptyBuffer;
- aDest.mLength=aLength;
- aDest.mCapacityAndFlags = 0;
- aDest.SetInternalCapacity(aCapacity);
- aDest.SetCharSize(aCharSize);
- aDest.SetOwnsBuffer(aOwnsBuffer);
-}
-
-/**
- * This member destroys the memory buffer owned by an nsStr object (if it actually owns it)
- * @update gess10/30/98
- * @param
- * @return
- */
-void nsStrPrivate::Destroy(nsStr& aDest) {
- if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) {
- Free(aDest);
- }
-}
-
-
-/**
- * This method gets called when the internal buffer needs
- * to grow to a given size. The original contents are not preserved.
- * @update gess 3/30/98
- * @param aNewLength -- new capacity of string in charSize units
- * @return void
- */
-PRBool nsStrPrivate::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) {
- PRBool result=PR_TRUE;
- if(aNewLength>aString.GetCapacity()) {
- result=Realloc(aString,aNewLength);
- if(aString.mStr)
- AddNullTerminator(aString);
- }
- return result;
-}
-
-/**
- * This method gets called when the internal buffer needs
- * to grow to a given size. The original contents ARE preserved.
- * @update gess 3/30/98
- * @param aNewLength -- new capacity of string in charSize units
- * @return void
- */
-PRBool nsStrPrivate::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) {
- PRBool result=PR_TRUE;
- if(aNewLength>aDest.GetCapacity()) {
- nsStr theTempStr;
- nsStrPrivate::Initialize(theTempStr,eCharSize(aDest.GetCharSize()));
-
- // the new strategy is, allocate exact size, double on grows
- if ( aDest.GetCapacity() ) {
- PRUint32 newCapacity = aDest.GetCapacity();
- while ( newCapacity < aNewLength )
- newCapacity <<= 1;
- aNewLength = newCapacity;
- }
-
- result=EnsureCapacity(theTempStr,aNewLength);
- if(result) {
- if(aDest.mLength) {
- StrAppend(theTempStr,aDest,0,aDest.mLength);
- }
- Free(aDest);
- aDest.mStr = theTempStr.mStr;
- theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
- aDest.mLength=theTempStr.mLength;
- aDest.SetInternalCapacity(theTempStr.GetCapacity());
- aDest.SetOwnsBuffer(theTempStr.GetOwnsBuffer());
- }
- }
- return result;
-}
-
-/**
- * Replaces the contents of aDest with aSource, up to aCount of chars.
- * @update gess10/30/98
- * @param aDest is the nsStr that gets changed.
- * @param aSource is where chars are copied from
- * @param aCount is the number of chars copied from aSource
- */
-void nsStrPrivate::StrAssign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){
- if(&aDest!=&aSource){
- StrTruncate(aDest,0);
- StrAppend(aDest,aSource,anOffset,aCount);
- }
-}
-
-/**
- * This method appends the given nsStr to this one. Note that we have to
- * pay attention to the underlying char-size of both structs.
- * @update gess10/30/98
- * @param aDest is the nsStr to be manipulated
- * @param aSource is where char are copied from
- * @aCount is the number of bytes to be copied
- */
-void nsStrPrivate::StrAppend(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){
- if(anOffset aDest.GetCapacity()) {
- isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength);
- }
-
- if(isBigEnough) {
- //now append new chars, starting at offset
- (*gCopyChars[aSource.GetCharSize()][aDest.GetCharSize()])(aDest.mStr,aDest.mLength,aSource.mStr,anOffset,theLength);
-
- aDest.mLength+=theLength;
- AddNullTerminator(aDest);
- NSSTR_SEEN(aDest);
- }
- }
- }
-}
-
-
-/**
- * This method inserts up to "aCount" chars from a source nsStr into a dest nsStr.
- * @update gess10/30/98
- * @param aDest is the nsStr that gets changed
- * @param aDestOffset is where in aDest the insertion is to occur
- * @param aSource is where chars are copied from
- * @param aSrcOffset is where in aSource chars are copied from
- * @param aCount is the number of chars from aSource to be inserted into aDest
- */
-
-PRInt32 nsStrPrivate::GetSegmentLength(const nsStr& aSource,
- PRUint32 aSrcOffset, PRInt32 aCount)
-{
- PRInt32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
- PRInt32 theLength=(aSrcOffset+theRealLen aDest.GetCapacity())
- AppendForInsert(aDest, aDestOffset, aSource, aSrcOffset, theLength);
- else {
- //shift the chars right by theDelta...
- ShiftCharsRight(aDest.mStr, aDest.mLength, aDestOffset, theLength);
-
- //now insert new chars, starting at offset
- CopyChars1To1(aDest.mStr, aDestOffset, aSource.mStr, aSrcOffset, theLength);
- }
-
- //finally, make sure to update the string length...
- aDest.mLength+=theLength;
- AddNullTerminator(aDest);
- NSSTR_SEEN(aDest);
- }//if
- //else nothing to do!
- }
- else StrAppend(aDest,aSource,0,aCount);
- }
- else StrAppend(aDest,aSource,0,aCount);
- }
-}
-
-void nsStrPrivate::StrInsert1into2( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount){
- NS_ASSERTION(aSource.GetCharSize() == eOneByte, "Must be 1 byte");
- NS_ASSERTION(aDest.GetCharSize() == eTwoByte, "Must be 2 byte");
- //there are a few cases for insert:
- // 1. You're inserting chars into an empty string (assign)
- // 2. You're inserting onto the end of a string (append)
- // 3. You're inserting onto the 1..n-1 pos of a string (the hard case).
- if(0 aDest.GetCapacity())
- AppendForInsert(aDest, aDestOffset, aSource, aSrcOffset, theLength);
- else {
- //shift the chars right by theDelta...
- ShiftDoubleCharsRight(aDest.mUStr, aDest.mLength, aDestOffset, theLength);
-
- //now insert new chars, starting at offset
- CopyChars1To2(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
- }
-
- //finally, make sure to update the string length...
- aDest.mLength+=theLength;
- AddNullTerminator(aDest);
- NSSTR_SEEN(aDest);
- }//if
- //else nothing to do!
- }
- else StrAppend(aDest,aSource,0,aCount);
- }
- else StrAppend(aDest,aSource,0,aCount);
- }
-}
-
-void nsStrPrivate::StrInsert2into2( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount){
- NS_ASSERTION(aSource.GetCharSize() == eTwoByte, "Must be 1 byte");
- NS_ASSERTION(aDest.GetCharSize() == eTwoByte, "Must be 2 byte");
- //there are a few cases for insert:
- // 1. You're inserting chars into an empty string (assign)
- // 2. You're inserting onto the end of a string (append)
- // 3. You're inserting onto the 1..n-1 pos of a string (the hard case).
- if(0 aDest.GetCapacity())
- AppendForInsert(aDest, aDestOffset, aSource, aSrcOffset, theLength);
- else {
-
- //shift the chars right by theDelta...
- ShiftDoubleCharsRight(aDest.mUStr, aDest.mLength, aDestOffset, theLength);
-
- //now insert new chars, starting at offset
- CopyChars2To2(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
- }
-
- //finally, make sure to update the string length...
- aDest.mLength+=theLength;
- AddNullTerminator(aDest);
- NSSTR_SEEN(aDest);
- }//if
- //else nothing to do!
- }
- else StrAppend(aDest,aSource,0,aCount);
- }
- else StrAppend(aDest,aSource,0,aCount);
- }
-}
-
-
-/**
- * This method deletes up to aCount chars from aDest
- * @update gess10/30/98
- * @param aDest is the nsStr to be manipulated
- * @param aDestOffset is where in aDest deletion is to occur
- * @param aCount is the number of chars to be deleted in aDest
- */
-
-
-void nsStrPrivate::Delete1(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount){
- NS_ASSERTION(aDest.GetCharSize() == eOneByte, "Must be 1 byte");
-
- if(aDestOffset0) && aSet){
- PRInt32 theIndex=-1;
- PRInt32 theMax=aDest.mLength;
- PRInt32 theSetLen=strlen(aSet);
-
- if(aEliminateLeading) {
- while(++theIndex<=theMax) {
- PRUnichar theChar=aDest.GetCharAt(theIndex);
- PRInt32 thePos=::FindChar1(aSet,theSetLen,0,theChar,theSetLen);
- if(kNotFound==thePos)
- break;
- }
-
- if(0=0) {
- PRUnichar theChar=aDest.GetCharAt(theIndex); //read at end now...
- PRInt32 thePos=::FindChar1(aSet,theSetLen,0,theChar,theSetLen);
- if(kNotFoundtheMaxPos) || (aTarget.mLength==0))
- return kNotFound;
-
- if(aCount<0)
- aCount = MaxInt(theMaxPos,1);
-
- if (aCount <= 0)
- return kNotFound;
-
- const char* root = aDest.mStr;
- const char* left = root + anOffset;
- const char* last = left + aCount;
- const char* max = root + theMaxPos;
-
- const char* right = (lasttheMaxPos) || (aTarget.mLength==0))
- return kNotFound;
-
- if(aCount<0)
- aCount = MaxInt(theMaxPos,1);
-
- if (aCount <= 0)
- return kNotFound;
-
- const PRUnichar* root = aDest.mUStr;
- const PRUnichar* left = root+anOffset;
- const PRUnichar* last = left+aCount;
- const PRUnichar* max = root+theMaxPos;
- const PRUnichar* right = (lasttheMaxPos) || (aTarget.mLength==0))
- return kNotFound;
-
- if(aCount<0)
- aCount = MaxInt(theMaxPos,1);
-
- if (aCount <= 0)
- return kNotFound;
-
- const PRUnichar* root = aDest.mUStr;
- const PRUnichar* left = root+anOffset;
- const PRUnichar* last = left+aCount;
- const PRUnichar* max = root+theMaxPos;
- const PRUnichar* right = (last=aDest.mLength) || (aTarget.mLength==0))
- return kNotFound;
-
- if (aCount<=0)
- return kNotFound;
-
- const char* root = aDest.mStr;
- const char* destLast = root+aDest.mLength; //pts to last char in aDest (likely null)
-
- const char* rightmost = root+anOffset;
- const char* min = rightmost-aCount + 1;
-
- const char* leftmost = (min=aDest.mLength) || (aTarget.mLength==0))
- return kNotFound;
-
- if (aCount<=0)
- return kNotFound;
-
- const PRUnichar* root = aDest.mUStr;
- const PRUnichar* destLast = root+aDest.mLength; //pts to last char in aDest (likely null)
-
- const PRUnichar* rightmost = root+anOffset;
- const PRUnichar* min = rightmost-aCount+1;
-
- const PRUnichar* leftmost = (min=aDest.mLength) || (aTarget.mLength==0))
- return kNotFound;
-
- if (aCount<=0)
- return kNotFound;
-
- const PRUnichar* root = aDest.mUStr;
- const PRUnichar* destLast = root+aDest.mLength; //pts to last char in aDest (likely null)
-
- const PRUnichar* rightmost = root+anOffset;
- const PRUnichar* min = rightmost-aCount+1;
-
- const PRUnichar* leftmost = (minaSource=1
- */
-PRInt32 nsStrPrivate::StrCompare1To1(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) {
- NS_ASSERTION(aDest.GetCharSize() == eOneByte, "Must be 1 byte");
- NS_ASSERTION(aSource.GetCharSize() == eOneByte, "Must be 1 byte");
- if (aCount) {
- PRInt32 theCount = GetCompareCount(aDest.mLength, aSource.mLength, aCount);
- PRInt32 result = Compare1To1(aDest.mStr, aSource.mStr, theCount, aIgnoreCase);
- result = TranslateCompareResult(aDest.mLength, aSource.mLength, result, aCount);
- return result;
- }
-
- return 0;
-}
-
-PRInt32 nsStrPrivate::StrCompare2To1(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) {
- NS_ASSERTION(aDest.GetCharSize() == eTwoByte, "Must be 2 byte");
- NS_ASSERTION(aSource.GetCharSize() == eOneByte, "Must be 1 byte");
-
- if (aCount) {
- PRInt32 theCount = GetCompareCount(aDest.mLength, aSource.mLength, aCount);
- PRInt32 result = Compare2To1(aDest.mUStr, aSource.mStr, theCount, aIgnoreCase);
- result = TranslateCompareResult(aDest.mLength, aSource.mLength, result, aCount);
- return result;
- }
-
- return 0;
-}
-
-PRInt32 nsStrPrivate::StrCompare2To2(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount) {
- NS_ASSERTION(aDest.GetCharSize() == eTwoByte, "Must be 2 byte");
- NS_ASSERTION(aSource.GetCharSize() == eTwoByte, "Must be 2 byte");
-
- if (aCount) {
- PRInt32 theCount = GetCompareCount(aDest.mLength, aSource.mLength, aCount);
- PRInt32 result = Compare2To2(aDest.mUStr, aSource.mUStr, theCount);
- result = TranslateCompareResult(aDest.mLength, aSource.mLength, result, aCount);
- return result;
- }
-
- return 0;
-}
-
-/**
- * Overwrites the contents of dest at offset with contents of aSource
- *
- * @param aDest is the first str to compare
- * @param aSource is the second str to compare
- * @param aDestOffset is the offset within aDest where source should be copied
- * @return error code
- */
-void nsStrPrivate::Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 aDestOffset) {
- if(aDest.mLength && aSource.mLength) {
- if((aDest.mLength-aDestOffset)>=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.GetCharSize()][aDest.GetCharSize()])(aDest.mStr,aDestOffset,aSource.mStr,0,aSource.mLength);
- }
- }
-}
-
-//----------------------------------------------------------------------------------------
-// allocate the given bytes, not including the null terminator
-PRBool nsStrPrivate::Alloc(nsStr& aDest,PRUint32 aCount) {
-
- // the new strategy is, allocate exact size, double on grows
- aDest.SetInternalCapacity(aCount);
- aDest.mStr = (char*)nsMemory::Alloc((aCount+1)<1) {
- mCapacity=aCapacity-1;
- mLength=(-1==aLength) ? nsCharTraits::length(aString) : aLength;
- if(mLength>PRInt32(mCapacity))
- mLength=mCapacity;
- }
-}
-
-CBufDescriptor::CBufDescriptor(const char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
- mBuffer=(char*)aString;
- mCharSize=eOneByte;
- mStackBased=aStackBased;
- mIsConst=PR_TRUE;
- mLength=mCapacity=0;
- if(aString && aCapacity>1) {
- mCapacity=aCapacity-1;
- mLength=(-1==aLength) ? nsCharTraits::length(aString) : aLength;
- if(mLength>PRInt32(mCapacity))
- mLength=mCapacity;
- }
-}
-
-
-CBufDescriptor::CBufDescriptor(PRUnichar* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
- mBuffer=(char*)aString;
- mCharSize=eTwoByte;
- mStackBased=aStackBased;
- mLength=mCapacity=0;
- mIsConst=PR_FALSE;
- if(aString && aCapacity>1) {
- mCapacity=aCapacity-1;
- mLength=(-1==aLength) ? nsCharTraits::length(aString) : aLength;
- if(mLength>PRInt32(mCapacity))
- mLength=mCapacity;
- }
-}
-
-CBufDescriptor::CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
- mBuffer=(char*)aString;
- mCharSize=eTwoByte;
- mStackBased=aStackBased;
- mLength=mCapacity=0;
- mIsConst=PR_TRUE;
- if(aString && aCapacity>1) {
- mCapacity=aCapacity-1;
- mLength=(-1==aLength) ? nsCharTraits::length(aString) : aLength;
- if(mLength>PRInt32(mCapacity))
- mLength=mCapacity;
- }
-}
-
-//----------------------------------------------------------------------------------------
-
-PRUint32
-nsStrPrivate::HashCode(const nsStr& aDest)
-{
- PRUint32 h = 0;
- if (aDest.GetCharSize() == eTwoByte) {
- const PRUnichar* s = aDest.mUStr;
-
- if (!s) return h;
-
- PRUnichar c;
- while ( (c = *s++) )
- h = (h>>28) ^ (h<<4) ^ c;
- return h;
- } else {
- const char* s = aDest.mStr;
-
- if (!s) return h;
-
- unsigned char c;
- while ( (c = *s++) )
- h = (h>>28) ^ (h<<4) ^ c;
- return h;
- }
-}
-
-/**
- * This is a copy of |PR_cnvtf| with a bug fixed. (The second argument
- * of PR_dtoa is 2 rather than 1.)
- */
-void
-nsStrPrivate::cnvtf(char *buf, int bufsz, int prcsn, double fval)
-{
- PRIntn decpt, sign, numdigits;
- char *num, *nump;
- char *bufp = buf;
- char *endnum;
-
- /* If anything fails, we store an empty string in 'buf' */
- num = (char*)PR_MALLOC(bufsz);
- if (num == NULL) {
- buf[0] = '\0';
- return;
- }
- if (PR_dtoa(fval, 2, prcsn, &decpt, &sign, &endnum, num, bufsz)
- == PR_FAILURE) {
- buf[0] = '\0';
- goto done;
- }
- numdigits = endnum - num;
- nump = num;
-
- /*
- * The NSPR code had a fancy way of checking that we weren't dealing
- * with -0.0 or -NaN, but I'll just use < instead.
- * XXX Should we check !isnan(fval) as well? Is it portable? We
- * probably don't need to bother since NAN isn't portable.
- */
- if (sign && fval < 0.0f) {
- *bufp++ = '-';
- }
-
- if (decpt == 9999) {
- while ((*bufp++ = *nump++) != 0) {} /* nothing to execute */
- goto done;
- }
-
- if (decpt > (prcsn+1) || decpt < -(prcsn-1) || decpt < -5) {
- *bufp++ = *nump++;
- if (numdigits != 1) {
- *bufp++ = '.';
- }
-
- while (*nump != '\0') {
- *bufp++ = *nump++;
- }
- *bufp++ = 'e';
- PR_snprintf(bufp, bufsz - (bufp - buf), "%+d", decpt-1);
- }
- else if (decpt >= 0) {
- if (decpt == 0) {
- *bufp++ = '0';
- }
- else {
- while (decpt--) {
- if (*nump != '\0') {
- *bufp++ = *nump++;
- }
- else {
- *bufp++ = '0';
- }
- }
- }
- if (*nump != '\0') {
- *bufp++ = '.';
- while (*nump != '\0') {
- *bufp++ = *nump++;
- }
- }
- *bufp++ = '\0';
- }
- else if (decpt < 0) {
- *bufp++ = '0';
- *bufp++ = '.';
- while (decpt++) {
- *bufp++ = '0';
- }
-
- while (*nump != '\0') {
- *bufp++ = *nump++;
- }
- *bufp++ = '\0';
- }
-done:
- PR_DELETE(num);
-}
-
-#ifdef NS_STR_STATS
-
-#include
-
-#ifdef XP_MAC
-#define isascii(c) ((unsigned)(c) < 0x80)
-#endif
-
-void
-nsStrPrivate::Print(const nsStr& aDest, FILE* out, PRBool truncate)
-{
- PRInt32 printLen = (PRInt32)aDest.mLength;
-
- if (aDest.GetCharSize() == eOneByte) {
- const char* chars = aDest.mStr;
- while (printLen-- && (!truncate || *chars != '\n')) {
- fputc(*chars++, out);
- }
- }
- else {
- const PRUnichar* chars = aDest.mUStr;
- while (printLen-- && (!truncate || *chars != '\n')) {
- if (isascii(*chars))
- fputc((char)(*chars++), out);
- else
- fputc('-', out);
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// String Usage Statistics Routines
-
-static PLHashTable* gStringInfo = nsnull;
-PRLock* gStringInfoLock = nsnull;
-PRBool gNoStringInfo = PR_FALSE;
-
-nsStringInfo::nsStringInfo(nsStr& str)
- : mCount(0)
-{
- nsStrPrivate::Initialize(mStr, str.GetCharSize());
- nsStrPrivate::StrAssign(mStr, str, 0, -1);
-// nsStrPrivate::Print(mStr, stdout);
-// fputc('\n', stdout);
-}
-
-PR_EXTERN(PRHashNumber)
-nsStr_Hash(const void* key)
-{
- nsStr* str = (nsStr*)key;
- return nsStrPrivate::HashCode(*str);
-}
-
-nsStringInfo*
-nsStringInfo::GetInfo(nsStr& str)
-{
- if (gStringInfo == nsnull) {
- gStringInfo = PL_NewHashTable(1024,
- nsStr_Hash,
- nsStr_Compare,
- PL_CompareValues,
- NULL, NULL);
- gStringInfoLock = PR_NewLock();
- }
- PR_Lock(gStringInfoLock);
- nsStringInfo* info =
- (nsStringInfo*)PL_HashTableLookup(gStringInfo, &str);
- if (info == NULL) {
- gNoStringInfo = PR_TRUE;
- info = new nsStringInfo(str);
- if (info) {
- PLHashEntry* e = PL_HashTableAdd(gStringInfo, &info->mStr, info);
- if (e == NULL) {
- delete info;
- info = NULL;
- }
- }
- gNoStringInfo = PR_FALSE;
- }
- PR_Unlock(gStringInfoLock);
- return info;
-}
-
-void
-nsStringInfo::Seen(nsStr& str)
-{
- if (!gNoStringInfo) {
- nsStringInfo* info = GetInfo(str);
- info->mCount++;
- }
-}
-
-void
-nsStringInfo::Report(FILE* out)
-{
- if (gStringInfo) {
- fprintf(out, "\n== String Stats\n");
- PL_HashTableEnumerateEntries(gStringInfo, nsStringInfo::ReportEntry, out);
- }
-}
-
-PRIntn
-nsStringInfo::ReportEntry(PLHashEntry *he, PRIntn i, void *arg)
-{
- nsStringInfo* entry = (nsStringInfo*)he->value;
- FILE* out = (FILE*)arg;
-
- fprintf(out, "%d ==> (%d) ", entry->mCount, entry->mStr.mLength);
- nsStrPrivate::Print(entry->mStr, out, PR_TRUE);
- fputc('\n', out);
- return HT_ENUMERATE_NEXT;
-}
-
-#endif // NS_STR_STATS
-
-////////////////////////////////////////////////////////////////////////////////
diff --git a/mozilla/xpcom/string/obsolete/nsStr.h b/mozilla/xpcom/string/obsolete/nsStr.h
deleted file mode 100644
index 481bfc3cc3d..00000000000
--- a/mozilla/xpcom/string/obsolete/nsStr.h
+++ /dev/null
@@ -1,390 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: NPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Netscape Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/NPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Rick Gessner (original author)
- * Scott Collins
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the NPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the NPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* nsStr.h --- the underlying buffer for rickg's original string implementations;
- these classes will be replaced by the new shared-buffer string (see bug #53065)
- */
-
-#ifndef _nsStr
-#define _nsStr
-
-#ifndef nsStringDefines_h___
-#include "nsStringDefines.h"
-#endif
-
-
-/***********************************************************************
- MODULE NOTES:
-
- 1. There are two philosophies to building string classes:
- A. Hide the underlying buffer & offer API's allow indirect iteration
- B. Reveal underlying buffer, risk corruption, but gain performance
-
- We chose the option B for performance reasons.
-
- 2 Our internal buffer always holds capacity+1 bytes.
-
- The nsStr struct is a simple structure (no methods) that contains
- the necessary info to be described as a string. This simple struct
- is manipulated by the static methods provided in this class.
- (Which effectively makes this a library that works on structs).
-
- There are also object-based versions called nsString and nsAutoString
- which use nsStr but makes it look at feel like an object.
-
- ***********************************************************************/
-
-/***********************************************************************
- ASSUMPTIONS:
-
- 1. nsStrings and nsAutoString are always null terminated. However,
- since it maintains a length byte, you can store NULL's inside
- the string. Just be careful passing such buffers to 3rd party
- API's that assume that NULL always terminate the buffer.
-
- 2. nsCStrings can be upsampled into nsString without data loss
-
- 3. Char searching is faster than string searching. Use char interfaces
- if your needs will allow it.
-
- 4. It's easy to use the stack for nsAutostring buffer storage (fast too!).
- See the CBufDescriptor class in this file.
-
- 5. If you don't provide the optional count argument to Append() and Insert(),
- the method will assume that the given buffer is terminated by the first
- NULL it encounters.
-
- 6. Downsampling from nsString to nsCString can be lossy -- avoid it if possible!
-
- 7. Calls to ToNewCString() and ToNewUnicode() should be matched with calls to nsMemory::Free().
-
- ***********************************************************************/
-
-
-/**********************************************************************************
-
- AND NOW FOR SOME GENERAL DOCUMENTATION ON STRING USAGE...
-
- The fundamental datatype in the string library is nsStr. It's a structure that
- provides the buffer storage and meta-info. It also provides a C-style library
- of functions for direct manipulation (for those of you who prefer K&R to Bjarne).
-
- Here's a diagram of the class hierarchy:
-
- nsStr
- |___nsString
- | |
- | ------nsAutoString
- |
- |___nsCString
- |
- ------nsCAutoString
-
- Why so many string classes? The 4 variants give you the control you need to
- determine the best class for your purpose. There are 2 dimensions to this
- flexibility: 1) stack vs. heap; and 2) 1-byte chars vs. 2-byte chars.
-
- Note: While nsAutoString and nsCAutoString begin life using stack-based storage,
- they may not stay that way. Like all nsString classes, autostrings will
- automatically grow to contain the data you provide. When autostrings
- grow beyond their intrinsic buffer, they switch to heap based allocations.
- (We avoid alloca to avoid considerable platform difficulties; see the
- GNU documentation for more details).
-
- I should also briefly mention that all the string classes use a "memory agent"
- object to perform memory operations. This class proxies the standard nsMemory
- for actual memory calls, but knows the structure of nsStr making heap operations
- more localized.
-
-
- CHOOSING A STRING CLASS:
-
- In order to choose a string class for you purpose, use this handy table:
-
- heap-based stack-based
- -----------------------------------
- ascii data | nsCString nsCAutoString |
- |----------------------------------
- unicode data | nsString nsAutoString |
- -----------------------------------
-
-
- Note: The i18n folks will stenuously object if we get too carried away with the
- use of nsCString's that pass interface boundaries. Try to limit your
- use of these to external interfaces that demand them, or for your own
- private purposes in cases where they'll never be seen by humans.
-
-
- --- FAQ ---
-
- Q. When should I use nsCString instead of nsString?
-
- A. You should really try to stick with nsString, so that we stay as unicode
- compliant as possible. But there are cases where an interface you use requires
- a char*. In such cases, it's fair to use nsCString.
-
- Q. I know that my string is going to be a certain size. Can I pre-size my nsString?
-
- A. Yup, here's how:
-
- {
- nsString mBuffer;
- mBuffer.SetCapacity(aReasonableSize);
- }
-
- Q. Should nsAutoString or nsCAutoString ever live on the heap?
-
- A. That would be counterproductive. The point of nsAutoStrings is to preallocate your
- buffers, and to auto-destroy the string when it goes out of scope.
-
- Q. I already have a char*. Can I use the nsString functionality on that buffer?
-
- A. Yes you can -- by using an intermediate class called CBufDescriptor.
- The CBufDescriptor class is used to tell nsString about an external buffer (heap or stack) to use
- instead of it's own internal buffers. Here's an example:
-
- {
- char theBuffer[256];
- CBufDescritor theBufDecriptor( theBuffer, PR_TRUE, sizeof(theBuffer), 0);
- nsCAutoString s3( theBufDescriptor );
- s3="HELLO, my name is inigo montoya, you killed my father, prepare to die!.";
- }
-
- The assignment statment to s3 will cause the given string to be written to your
- stack-based buffer via the normal nsString/nsCString interfaces. Cool, huh?
- Note however that just like any other nsStringXXX use, if you write more data
- than will fit in the buffer, a visit to the heap manager will be in order.
-
-
- Q. What is the simplest way to get from a char* to PRUnichar*?
-
- A. The simplest way is by construction (or assignment):
-
- {
- char* theBuf = "hello there";
- nsAutoString foo(theBuf);
- }
-
- If you don't want the char* to be copied into the nsAutoString, the use a
- CBufDescriptor instead.
-
-
- **********************************************************************************/
-
-
-#include "nscore.h"
-#include "nsMemory.h"
-#include
-#include
-#include "plhash.h"
-#include "nsStrShared.h"
-
-//----------------------------------------------------------------------------------------
-#define kDefaultCharSize eTwoByte
-#define kRadix10 (10)
-#define kRadix16 (16)
-#define kAutoDetect (100)
-#define kRadixUnknown (kAutoDetect+1)
-#define IGNORE_CASE (PR_TRUE)
-
-#define NSSTR_CHARSIZE_BIT (31)
-#define NSSTR_OWNSBUFFER_BIT (30)
-
-#define NSSTR_CHARSIZE_MASK (1<> NSSTR_CHARSIZE_BIT);
- }
-
-private:
-
- inline void SetInternalCapacity(PRUint32 aCapacity) {
- mCapacityAndFlags =
- ((mCapacityAndFlags & ~NSSTR_CAPACITY_MASK) |
- (aCapacity & NSSTR_CAPACITY_MASK));
- }
-
- inline void SetCharSize(eCharSize aCharSize) {
- mCapacityAndFlags =
- ((mCapacityAndFlags & ~NSSTR_CHARSIZE_MASK) |
- (PRUint32(aCharSize) << NSSTR_CHARSIZE_BIT));
- }
-
- inline void SetOwnsBuffer(PRBool aOwnsBuffer) {
- mCapacityAndFlags =
- (mCapacityAndFlags & ~NSSTR_OWNSBUFFER_MASK |
- (aOwnsBuffer ? 1 : 0) << NSSTR_OWNSBUFFER_BIT);
- }
-
- inline PRUnichar GetCharAt(PRUint32 anIndex) const {
- if(anIndex (original author)
- * Scott Collins
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the NPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the NPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef __nsStrPrivate_h
-#define __nsStrPrivate_h
-
-#include "nscore.h"
-#include "nsStrShared.h"
-
-struct nsStr;
-
-// there are only static methods here!
-class nsStrPrivate {
- public:
- /**
- * This method initializes an nsStr for use
- *
- * @update gess 01/04/99
- * @param aString is the nsStr to be initialized
- * @param aCharSize tells us the requested char size (1 or 2 bytes)
- */
- static void Initialize(nsStr& aDest,eCharSize aCharSize);
-
- /**
- * This method initializes an nsStr for use
- *
- * @update gess 01/04/99
- * @param aString is the nsStr to be initialized
- * @param aCharSize tells us the requested char size (1 or 2 bytes)
- */
- static void Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer);
- /**
- * This method destroys the given nsStr, and *MAY*
- * deallocate it's memory depending on the setting
- * of the internal mOwnsBUffer flag.
- *
- * @update gess 01/04/99
- * @param aString is the nsStr to be manipulated
- */
- static void Destroy(nsStr& aDest);
-
- /**
- * These methods are where memory allocation/reallocation occur.
- *
- * @update gess 01/04/99
- * @param aString is the nsStr to be manipulated
- * @return
- */
- static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength);
- static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength);
-
- /**
- * These methods are used to append content to the given nsStr
- *
- * @update gess 01/04/99
- * @param aDest is the nsStr to be appended to
- * @param aSource is the buffer to be copied from
- * @param anOffset tells us where in source to start copying
- * @param aCount tells us the (max) # of chars to copy
- */
- static void StrAppend(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount);
-
- /**
- * These methods are used to assign contents of a source string to dest string
- *
- * @update gess 01/04/99
- * @param aDest is the nsStr to be appended to
- * @param aSource is the buffer to be copied from
- * @param anOffset tells us where in source to start copying
- * @param aCount tells us the (max) # of chars to copy
- */
- static void StrAssign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount);
-
- /**
- * These methods are used to insert content from source string to the dest nsStr
- *
- * @update gess 01/04/99
- * @param aDest is the nsStr to be appended to
- * @param aDestOffset tells us where in dest to start insertion
- * @param aSource is the buffer to be copied from
- * @param aSrcOffset tells us where in source to start copying
- * @param aCount tells us the (max) # of chars to insert
- */
- static void StrInsert1into1( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount);
- static void StrInsert1into2( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount);
- static void StrInsert2into2( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount);
-
-
- /**
- * Helper routines for StrInsert1into1, etc
- */
- static PRInt32 GetSegmentLength(const nsStr& aSource,
- PRUint32 aSrcOffset, PRInt32 aCount);
- static void AppendForInsert(nsStr& aDest, PRUint32 aDestOffset, const nsStr& aSource, PRUint32 aSrcOffset, PRInt32 theLength);
-
- /**
- * This method deletes chars from the given str.
- * The given allocator may choose to resize the str as well.
- *
- * @update gess 01/04/99
- * @param aDest is the nsStr to be deleted from
- * @param aDestOffset tells us where in dest to start deleting
- * @param aCount tells us the (max) # of chars to delete
- */
- static void Delete1(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount);
- static void Delete2(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount);
-
- /**
- * helper routines for Delete1, Delete2
- */
- static PRInt32 GetDeleteLength(const nsStr& aDest, PRUint32 aDestOffset, PRUint32 aCount);
-
- /**
- * This method is used to truncate the given string.
- * The given allocator may choose to resize the str as well (but it's not likely).
- *
- * @update gess 01/04/99
- * @param aDest is the nsStr to be appended to
- * @param aDestOffset tells us where in dest to start insertion
- * @param aSource is the buffer to be copied from
- * @param aSrcOffset tells us where in source to start copying
- */
- static void StrTruncate(nsStr& aDest,PRUint32 aDestOffset);
-
- /**
- * This method trims chars (given in aSet) from the edges of given buffer
- *
- * @update gess 01/04/99
- * @param aDest is the buffer to be manipulated
- * @param aSet tells us which chars to remove from given buffer
- * @param aEliminateLeading tells us whether to strip chars from the start of the buffer
- * @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
- */
- static void Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
-
- /**
- * This method compresses duplicate runs of a given char from the given buffer
- *
- * @update gess 01/04/99
- * @param aDest is the buffer to be manipulated
- * @param aSet tells us which chars to compress from given buffer
- * @param aChar is the replacement char
- * @param aEliminateLeading tells us whether to strip chars from the start of the buffer
- * @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
- */
- static void CompressSet1(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
- static void CompressSet2(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
-
- /**
- * This method removes all occurances of chars in given set from aDest
- *
- * @update gess 01/04/99
- * @param aDest is the buffer to be manipulated
- * @param aSet tells us which chars to compress from given buffer
- * @param aChar is the replacement char
- * @param aEliminateLeading tells us whether to strip chars from the start of the buffer
- * @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
- */
- static void StripChars1(nsStr& aDest,const char* aSet);
- static void StripChars2(nsStr& aDest,const char* aSet);
-
- /**
- * This method compares the data bewteen two nsStr's
- *
- * @update gess 01/04/99
- * @param aStr1 is the first buffer to be compared
- * @param aStr2 is the 2nd buffer to be compared
- * @param aCount is the number of chars to compare
- * @param aIgnorecase tells us whether to use a case-sensitive comparison
- * @return -1,0,1 depending on <,==,>
- */
- static PRInt32 StrCompare1To1(const nsStr& aDest,const nsStr& aSource,
- PRInt32 aCount,PRBool aIgnoreCase);
- static PRInt32 StrCompare2To1(const nsStr& aDest, const nsStr& aSource,
- PRInt32 aCount, PRBool aIgnoreCase);
- static PRInt32 StrCompare2To2(const nsStr& aDest, const nsStr& aSource,
- PRInt32 aCount);
-
- /**
- * These methods scan the given string for 1 or more chars in a given direction
- *
- * @update gess 01/04/99
- * @param aDest is the nsStr to be searched to
- * @param aSource (or aChar) is the substr we're looking to find
- * @param aIgnoreCase tells us whether to search in a case-sensitive manner
- * @param anOffset tells us where in the dest string to start searching
- * @return the index of the source (substr) in dest, or -1 (kNotFound) if not found.
- */
- static PRInt32 FindSubstr1in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
- static PRInt32 FindSubstr1in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
- static PRInt32 FindSubstr2in2(const nsStr& aDest,const nsStr& aSource, PRInt32 anOffset,PRInt32 aCount);
-
- static PRInt32 FindChar1(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount);
- static PRInt32 FindChar2(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount);
-
- static PRInt32 RFindSubstr1in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
- static PRInt32 RFindSubstr1in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
- static PRInt32 RFindSubstr2in2(const nsStr& aDest,const nsStr& aSource, PRInt32 anOffset,PRInt32 aCount);
-
- static PRInt32 RFindChar1(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount);
- static PRInt32 RFindChar2(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount);
-
- static void Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 anOffset);
-
- static char GetFindInSetFilter(const char *set)
- {
- // Calculate filter
- char filter = ~char(0); // All bits set
- while (*set) {
- filter &= ~(*set);
- ++set;
- }
-
- return filter;
- }
- static PRUnichar GetFindInSetFilter(const PRUnichar *set)
- {
- // Calculate filter
- PRUnichar filter = ~PRUnichar(0); // All bits set
- while (*set) {
- filter &= ~(*set);
- ++set;
- }
- return filter;
- }
-
-#ifdef NS_STR_STATS
- static PRBool DidAcquireMemory(void);
-#endif
-
- /**
- * Returns a hash code for the string for use in a PLHashTable.
- */
- static PRUint32 HashCode(const nsStr& aDest);
-
- // A copy of PR_cnvtf with a bug fixed.
- static void cnvtf(char *buf, int bufsz, int prcsn, double fval);
-
-#ifdef NS_STR_STATS
- /**
- * Prints an nsStr. If truncate is true, the string is only printed up to
- * the first newline. (Note: The current implementation doesn't handle
- * non-ascii unicode characters.)
- */
- static void Print(const nsStr& aDest, FILE* out, PRBool truncate = PR_FALSE);
-#endif
-
- static PRBool Alloc(nsStr& aString,PRUint32 aCount);
- static PRBool Realloc(nsStr& aString,PRUint32 aCount);
- static PRBool Free(nsStr& aString);
-
-};
-
-#endif
diff --git a/mozilla/xpcom/string/obsolete/nsStrShared.h b/mozilla/xpcom/string/obsolete/nsStrShared.h
deleted file mode 100644
index 251c9bfd915..00000000000
--- a/mozilla/xpcom/string/obsolete/nsStrShared.h
+++ /dev/null
@@ -1,8 +0,0 @@
-
-#ifndef __nsStrShared_h
-#define __nsStrShared_h
-
-
-enum eCharSize {eOneByte=0,eTwoByte=1};
-
-#endif
diff --git a/mozilla/xpcom/string/obsolete/nsString.cpp b/mozilla/xpcom/string/obsolete/nsString.cpp
deleted file mode 100644
index 72797f743f8..00000000000
--- a/mozilla/xpcom/string/obsolete/nsString.cpp
+++ /dev/null
@@ -1,1243 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: NPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Netscape Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/NPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Rick Gessner
- * Scott Collins
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the NPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the NPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include
-#include
-#include
-#include
-#include "nsStrPrivate.h"
-#include "nsString.h"
-#include "nsReadableUtils.h"
-#include "nsDebug.h"
-#include "nsUTF8Utils.h"
-
-#ifndef nsCharTraits_h___
-#include "nsCharTraits.h"
-#endif
-
-#ifndef RICKG_TESTBED
-#include "prdtoa.h"
-#endif
-
-#ifdef DEBUG
-static const char* kPossibleNull = "Error: possible unintended null in string";
-static const char* kNullPointerError = "Error: unexpected null ptr";
-#endif
-static const char* kWhitespace="\b\t\r\n ";
-
-const nsBufferHandle*
-nsCString::GetFlatBufferHandle() const
- {
- return NS_REINTERPRET_CAST(const nsBufferHandle*, 1);
- }
-
-/**
- * Default constructor.
- */
-nsCString::nsCString() {
- nsStrPrivate::Initialize(*this,eOneByte);
-}
-
-nsCString::nsCString(const char* aCString) {
- nsStrPrivate::Initialize(*this,eOneByte);
- Assign(aCString);
-}
-
-/**
- * This constructor accepts an ascii string
- * @update gess 1/4/99
- * @param aCString is a ptr to a 1-byte cstr
- * @param aLength tells us how many chars to copy from given CString
- */
-nsCString::nsCString(const char* aCString,PRInt32 aLength) {
- nsStrPrivate::Initialize(*this,eOneByte);
- Assign(aCString,aLength);
-}
-
-/**
- * This is our copy constructor
- * @update gess 1/4/99
- * @param reference to another nsCString
- */
-nsCString::nsCString(const nsCString& aString) {
- nsStrPrivate::Initialize(*this,aString.GetCharSize());
- nsStrPrivate::StrAssign(*this,aString,0,aString.mLength);
-}
-
-/**
- * Destructor
- */
-nsCString::~nsCString() {
- nsStrPrivate::Destroy(*this);
-}
-
-const char* nsCString::GetReadableFragment( nsReadableFragment& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const {
- switch ( aRequest ) {
- case kFirstFragment:
- case kLastFragment:
- case kFragmentAt:
- aFragment.mEnd = (aFragment.mStart = mStr) + mLength;
- return aFragment.mStart + aOffset;
-
- case kPrevFragment:
- case kNextFragment:
- default:
- return 0;
- }
-}
-
-char* nsCString::GetWritableFragment( nsWritableFragment& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) {
- switch ( aRequest ) {
- case kFirstFragment:
- case kLastFragment:
- case kFragmentAt:
- aFragment.mEnd = (aFragment.mStart = mStr) + mLength;
- return aFragment.mStart + aOffset;
-
- case kPrevFragment:
- case kNextFragment:
- default:
- return 0;
- }
-}
-
-nsCString::nsCString( const nsACString& aReadable ) {
- nsStrPrivate::Initialize(*this,eOneByte);
- Assign(aReadable);
-}
-
-/**
- * This method truncates this string to given length.
- *
- * @update rickg 03.23.2000
- * @param anIndex -- new length of string
- * @return nada
- */
-void nsCString::SetLength(PRUint32 anIndex) {
- if ( anIndex > GetCapacity() )
- SetCapacity(anIndex);
- // |SetCapacity| normally doesn't guarantee the use we are putting it to here (see its interface comment in nsAString.h),
- // we can only use it since our local implementation, |nsCString::SetCapacity|, is known to do what we want
-
- nsStrPrivate::StrTruncate(*this,anIndex);
-}
-
-
-/**
- * Call this method if you want to force the string to a certain capacity;
- * |SetCapacity(0)| discards associated storage.
- *
- * @param aNewCapacity -- desired minimum capacity
- */
-void
-nsCString::SetCapacity( PRUint32 aNewCapacity )
- {
- if ( aNewCapacity )
- {
- if( aNewCapacity > GetCapacity() )
- nsStrPrivate::GrowCapacity(*this,aNewCapacity);
- AddNullTerminator(*this);
- }
- else
- {
- nsStrPrivate::Destroy(*this);
- nsStrPrivate::Initialize(*this, eOneByte);
- }
- }
-
-/**********************************************************************
- Accessor methods...
- *********************************************************************/
-
-/**
- * set a char inside this string at given index
- * @param aChar is the char you want to write into this string
- * @param anIndex is the ofs where you want to write the given char
- * @return TRUE if successful
- */
-PRBool nsCString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
- PRBool result=PR_FALSE;
- if(anIndex::length(aTarget);
- if(0::length(aNewValue);
- if(02)) {
- theFirstChar=First();
- theLastChar=Last();
- if(theFirstChar==theLastChar) {
- if(('\''==theFirstChar) || ('"'==theFirstChar)) {
- Cut(0,1);
- Truncate(mLength-1);
- theQuotesAreNeeded=PR_TRUE;
- }
- else theFirstChar=0;
- }
- }
-
- nsStrPrivate::Trim(*this, aTrimSet, aEliminateLeading, aEliminateTrailing);
-
- if(aIgnoreQuotes && theQuotesAreNeeded) {
- Insert(theFirstChar, 0);
- Append(theLastChar);
- }
-
- }
-}
-
-/**
- * This method strips chars in given set from string.
- * You can control whether chars are yanked from
- * start and end of string as well.
- *
- * @update gess 3/31/98
- * @param aEliminateLeading controls stripping of leading ws
- * @param aEliminateTrailing controls stripping of trailing ws
- * @return this
- */
-static void
-CompressSet(nsCString& aStr, const char* aSet, char aChar,
- PRBool aEliminateLeading, PRBool aEliminateTrailing){
- if(aSet){
- aStr.ReplaceChar(aSet, aChar);
- nsStrPrivate::CompressSet1(aStr, aSet,
- aEliminateLeading, aEliminateTrailing);
- }
-}
-
-/**
- * This method strips whitespace from string.
- * You can control whether whitespace is yanked from
- * start and end of string as well.
- *
- * @update gess 3/31/98
- * @param aEliminateLeading controls stripping of leading ws
- * @param aEliminateTrailing controls stripping of trailing ws
- * @return this
- */
-void
-nsCString::CompressWhitespace( PRBool aEliminateLeading,PRBool aEliminateTrailing){
- CompressSet(*this, kWhitespace,' ',aEliminateLeading,aEliminateTrailing);
-}
-
-/**********************************************************************
- string conversion methods...
- *********************************************************************/
-
-/**
- * Perform string to float conversion.
- * @update gess 01/04/99
- * @param aErrorCode will contain error if one occurs
- * @return float rep of string value
- */
-float nsCString::ToFloat(PRInt32* aErrorCode) const {
- float res = 0.0f;
- if (mLength > 0) {
- char *conv_stopped;
- const char *str = get();
- // Use PR_strtod, not strtod, since we don't want locale involved.
- res = (float)PR_strtod(str, &conv_stopped);
- if (conv_stopped == str+mLength) {
- *aErrorCode = (PRInt32) NS_OK;
- }
- else {
- /* Not all the string was scanned */
- *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE;
- }
- }
- else {
- /* The string was too short (0 characters) */
- *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE;
- }
- return res;
-}
-
-/**
- * Perform decimal numeric string to int conversion.
- * NOTE: In this version, we use the radix you give, even if it's wrong.
- * @update gess 02/14/00
- * @param aErrorCode will contain error if one occurs
- * @param aRadix tells us what base to expect the given string in. kAutoDetect tells us to determine the radix.
- * @return int rep of string value
- */
-PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
- char* cp=mStr;
- PRInt32 theRadix=10; // base 10 unless base 16 detected, or overriden (aRadix != kAutoDetect)
- PRInt32 result=0;
- PRBool negate=PR_FALSE;
- char theChar=0;
-
- //initial value, override if we find an integer
- *anErrorCode=NS_ERROR_ILLEGAL_VALUE;
-
- if(cp) {
-
- //begin by skipping over leading chars that shouldn't be part of the number...
-
- char* endcp=cp+mLength;
- PRBool done=PR_FALSE;
-
- while((cp='A') && (theChar<='F')) {
- if(10==theRadix) {
- if(kAutoDetect==aRadix){
- theRadix=16;
- cp=first; //backup
- result=0;
- haveValue = PR_FALSE;
- }
- else {
- *anErrorCode=NS_ERROR_ILLEGAL_VALUE;
- result=0;
- break;
- }
- }
- else {
- result = (theRadix * result) + ((theChar-'A')+10);
- haveValue = PR_TRUE;
- }
- }
- else if((theChar>='a') && (theChar<='f')) {
- if(10==theRadix) {
- if(kAutoDetect==aRadix){
- theRadix=16;
- cp=first; //backup
- result=0;
- haveValue = PR_FALSE;
- }
- else {
- *anErrorCode=NS_ERROR_ILLEGAL_VALUE;
- result=0;
- break;
- }
- }
- else {
- result = (theRadix * result) + ((theChar-'a')+10);
- haveValue = PR_TRUE;
- }
- }
- else if((('X'==theChar) || ('x'==theChar)) && (!haveValue || result == 0)) {
- continue;
- }
- else if((('#'==theChar) || ('+'==theChar)) && !haveValue) {
- continue;
- }
- else {
- //we've encountered a char that's not a legal number or sign
- break;
- }
- } //while
- if(negate)
- result=-result;
- } //if
- }
- return result;
-}
-
-/**********************************************************************
- String manipulation methods...
- *********************************************************************/
-
-
-/**
- * assign given unichar* to this string
- * @update gess 01/04/99
- * @param aCString: buffer to be assigned to this
- * @param aCount -- length of given buffer or -1 if you want me to compute length.
- * NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
- *
- * @return this
- */
-void nsCString::AssignWithConversion(const PRUnichar* aString,PRInt32 aCount) {
- nsStrPrivate::StrTruncate(*this,0);
-
- if(aString && aCount){
- nsStr temp;
- nsStrPrivate::Initialize(temp,eTwoByte);
- temp.mUStr=(PRUnichar*)aString;
-
- if(0::length(aString);
-
- if(0::length(aBuffer);
-
- if ( aLength > 0 )
- {
- temp.mLength = aLength;
- nsStrPrivate::StrAppend(*this, temp, 0, aLength);
- }
- }
-
-/**
- * Append the given integer to this string
- * @update gess 01/04/99
- * @param aInteger:
- * @param aRadix:
- * @return
- */
-void nsCString::AppendInt(PRInt32 anInteger,PRInt32 aRadix) {
-
- PRUint32 theInt=(PRUint32)anInteger;
-
- char buf[]={'0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
-
- PRInt32 radices[] = {1000000000,268435456};
- PRInt32 mask1=radices[16==aRadix];
-
- PRInt32 charpos=0;
- if(anInteger<0) {
- theInt*=-1;
- if(10==aRadix) {
- buf[charpos++]='-';
- }
- else theInt=(int)~(theInt-1);
- }
-
- PRBool isfirst=PR_TRUE;
- while(mask1>=1) {
- PRInt32 theDiv=theInt/mask1;
- if((theDiv) || (!isfirst)) {
- buf[charpos++]="0123456789abcdef"[theDiv];
- isfirst=PR_FALSE;
- }
- theInt-=theDiv*mask1;
- mask1/=aRadix;
- }
- Append(buf);
-}
-
-
-/**
- * Append the given float to this string
- * @update gess 01/04/99
- * @param aFloat:
- * @return
- */
-void nsCString::AppendFloat( double aFloat ){
- char buf[40];
- // Use nsStrPrivate::cnvtf, which is locale-insensitive, instead of the
- // locale-sensitive PR_snprintf or sprintf(3)
- nsStrPrivate::cnvtf(buf, sizeof(buf), 6, aFloat);
- Append(buf);
-}
-
-/**
- * append given string to this string;
- * @update gess 01/04/99
- * @param aString : string to be appended to this
- * @return this
- */
-void nsCString::AppendWithConversion(const nsString& aString,PRInt32 aCount) {
-
- if(aCount<0)
- aCount=aString.mLength;
- else aCount=MinInt(aCount,aString.mLength);
-
- if(0::length(aPtr);
- // We don't know the capacity, so we'll just have to assume
- // capacity = length.
- nsStrPrivate::Initialize(*this, aPtr, aLength, aLength, eOneByte, PR_TRUE);
-}
-
-nsCString::size_type
-nsCString::Mid( self_type& aResult, index_type aStartPos, size_type aLengthToCopy ) const
- {
- // If we're just assigning our entire self, give |aResult| the opportunity to share
- if ( aStartPos == 0 && aLengthToCopy >= Length() )
- aResult = *this;
- else
- aResult = Substring(*this, aStartPos, aLengthToCopy);
-
- return aResult.Length();
- }
-
-
-/**********************************************************************
- Searching methods...
- *********************************************************************/
-
-
-/**
- * Search for given cstr within this string
- *
- * @update gess 3/25/98
- * @param aCString - substr to be found
- * @param aIgnoreCase tells us whether or not to do caseless compare
- * @param anOffset tells us where in this string to start searching
- * @param aCount tells us how many iterations to make starting at the given offset
- * @return offset in string, or -1 (kNotFound)
- */
-PRInt32 nsCString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
- PRInt32 result=kNotFound;
- if(aCString) {
- nsStr temp;
- nsStrPrivate::Initialize(temp,eOneByte);
- temp.mLength = nsCharTraits::length(aCString);
- temp.mStr=(char*)aCString;
- result=nsStrPrivate::FindSubstr1in1(*this,temp,aIgnoreCase,anOffset,aCount);
- }
- return result;
-}
-
-
-/**
- * Search for given string within this string
- *
- * @update gess 3/25/98
- * @param aString - substr to be found
- * @param aIgnoreCase tells us whether or not to do caseless compare
- * @param anOffset tells us where in this string to start searching
- * @param aCount tells us how many iterations to make starting at the given offset
- * @return offset in string, or -1 (kNotFound)
- */
-PRInt32 nsCString::Find(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
- PRInt32 result=nsStrPrivate::FindSubstr1in1(*this,aString,aIgnoreCase,anOffset,aCount);
- return result;
-}
-
-/**
- * This searches this string for a given character
- *
- * @update gess 2/04/00
- * @param char is the character you're trying to find.
- * @param anOffset tells us where to start the search; -1 means start at 0.
- * @param aCount tell us how many chars to search from offset; -1 means use full length.
- * @return index in aDest where member of aSet occurs, or -1 if not found
- */
-PRInt32 nsCString::FindChar(PRUnichar aChar,PRInt32 anOffset,PRInt32 aCount) const{
- if (anOffset < 0)
- anOffset=0;
-
- if (aCount < 0)
- aCount = (PRInt32)mLength;
-
- if ((aChar < 256) && (0 < mLength) &&
- ((PRUint32)anOffset < mLength) && (0 < aCount)) {
- // We'll only search if the given aChar is 8-bit,
- // since this string is 8-bit.
-
- PRUint32 last = anOffset + aCount;
- PRUint32 end = (last < mLength) ? last : mLength;
- PRUint32 searchLen = end - anOffset; // Will be > 0 by the conditions above
- const char* leftp = mStr + anOffset;
- unsigned char theChar = (unsigned char) aChar;
-
- const char* result = (const char*)memchr(leftp, (int)theChar, searchLen);
-
- if (result)
- return result - mStr;
- }
-
- return kNotFound;
-}
-
-/**
- * This method finds the offset of the first char in this string that is
- * a member of the given charset, starting the search at anOffset
- *
- * @update gess 3/25/98
- * @param aCStringSet
- * @param anOffset -- where in this string to start searching
- * @return
- */
-PRInt32 nsCString::FindCharInSet(const char* aCStringSet,PRInt32 anOffset) const{
- if (anOffset < 0)
- anOffset = 0;
-
- if(*aCStringSet && (PRUint32)anOffset < mLength) {
- // Build filter that will be used to filter out characters with
- // bits that none of the terminal chars have. This works very well
- // because searches are often done for chars with only the last
- // 4-6 bits set and normal ascii letters have bit 7 set. Other
- // letters have even higher bits set.
-
- // Calculate filter
- char filter = nsStrPrivate::GetFindInSetFilter(aCStringSet);
-
- const char* endChar = mStr + mLength;
- for(char *charp = mStr + anOffset; charp < endChar; ++charp) {
- char currentChar = *charp;
- // Check if all bits are in the required area
- if (currentChar & filter) {
- // They were not. Go on with the next char.
- continue;
- }
-
- // Test all chars
- const char *charInSet = aCStringSet;
- char setChar = *charInSet;
- while (setChar) {
- if (setChar == currentChar) {
- // Found it!
- return charp - mStr; // The index of the found char
- }
- setChar = *(++charInSet);
- }
- } // end for all chars in the string
- }
- return kNotFound;
-}
-
-PRInt32 nsCString::FindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{
- // This assumes that the set doesn't contain the null char.
- PRInt32 result = FindCharInSet(aSet.get(), anOffset);
- return result;
-}
-
-/**
- * Reverse search for given string within this string
- *
- * @update gess 3/25/98
- * @param aString - substr to be found
- * @param aIgnoreCase tells us whether or not to do caseless compare
- * @param anOffset tells us where in this string to start searching
- * @param aCount tells us how many iterations to make starting at the given offset
- * @return offset in string, or -1 (kNotFound)
- */
-PRInt32 nsCString::RFind(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
- PRInt32 result=nsStrPrivate::RFindSubstr1in1(*this,aString,aIgnoreCase,anOffset,aCount);
- return result;
-}
-
-
-/**
- * Reverse search for given string within this string
- *
- * @update gess 3/25/98
- * @param aString - substr to be found
- * @param aIgnoreCase tells us whether or not to do caseless compare
- * @param anOffset tells us where in this string to start searching
- * @param aCount tells us how many iterations to make starting at the given offset
- * @return offset in string, or -1 (kNotFound)
- */
-PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
- NS_ASSERTION(0!=aString,kNullPointerError);
-
- PRInt32 result=kNotFound;
- if(aString) {
- nsStr temp;
- nsStrPrivate::Initialize(temp,eOneByte);
- temp.mLength=nsCharTraits::length(aString);
- temp.mStr=(char*)aString;
- result=nsStrPrivate::RFindSubstr1in1(*this,temp,aIgnoreCase,anOffset,aCount);
- }
- return result;
-}
-
-/**
- * This reverse searches this string for a given character
- *
- * @update gess 2/04/00
- * @param char is the character you're trying to find.
- * @param aIgnorecase indicates case sensitivity of search
- * @param anOffset tells us where to start the search; -1 means start at 0.
- * @param aCount tell us how many chars to search from offset; -1 means use full length.
- * @return index in aDest where member of aSet occurs, or -1 if not found
- */
-PRInt32 nsCString::RFindChar(PRUnichar aChar,PRInt32 anOffset,PRInt32 aCount) const{
- PRInt32 result=nsStrPrivate::RFindChar1(*this,aChar,anOffset,aCount);
- return result;
-}
-
-/**
- * Reverse search for char in this string that is also a member of given charset
- *
- * @update gess 3/25/98
- * @param aCStringSet
- * @param anOffset
- * @return offset of found char, or -1 (kNotFound)
- */
-PRInt32 nsCString::RFindCharInSet(const char* aCStringSet,PRInt32 anOffset) const{
- NS_ASSERTION(0!=aCStringSet,kNullPointerError);
-
- if (anOffset < 0 || (PRUint32)anOffset > mLength-1)
- anOffset = mLength-1;
-
- if(*aCStringSet) {
- // Build filter that will be used to filter out characters with
- // bits that none of the terminal chars have. This works very well
- // because searches are often done for chars with only the last
- // 4-6 bits set and normal ascii letters have bit 7 set. Other
- // letters have even higher bits set.
-
- // Calculate filter
- char filter = nsStrPrivate::GetFindInSetFilter(aCStringSet);
-
- const char* end = mStr;
- for(char *charp = mStr + anOffset; charp > end; --charp) {
- char currentChar = *charp;
- // Check if all bits are in the required area
- if (currentChar & filter) {
- // They were not. Go on with the next char.
- continue;
- }
-
- // Test all chars
- const char *setp = aCStringSet;
- char setChar = *setp;
- while (setChar) {
- if (setChar == currentChar) {
- // Found it!
- return charp - mStr;
- }
- setChar = *(++setp);
- }
- } // end for all chars in the string
- }
- return kNotFound;
-}
-
-PRInt32 nsCString::RFindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{
- // Assumes that the set doesn't contain any nulls.
- PRInt32 result = RFindCharInSet(aSet.get(), anOffset);
- return result;
-}
-
-/**************************************************************
- COMPARISON METHODS...
- **************************************************************/
-
-/**
- * Compares given cstring to this string.
- * @update gess 01/04/99
- * @param aCString points to a cstring
- * @param aIgnoreCase tells us how to treat case
- * @param aCount tells us how many chars to test; -1 implies full length
- * @return -1,0,1
- */
-PRInt32 nsCString::Compare(const char *aCString,PRBool aIgnoreCase,PRInt32 aCount) const {
- NS_ASSERTION(0!=aCString,kNullPointerError);
-
- if(aCString) {
- nsStr temp;
- nsStrPrivate::Initialize(temp,eOneByte);
- temp.mLength=nsCharTraits::length(aCString);
- temp.mStr=(char*)aCString;
- return nsStrPrivate::StrCompare1To1(*this,temp,aCount,aIgnoreCase);
- }
- return 0;
-}
-
-PRBool nsCString::EqualsIgnoreCase(const char* aString,PRInt32 aLength) const {
- return EqualsWithConversion(aString,PR_TRUE,aLength);
-}
-
-/**
- * Compare this to given string; note that we compare full strings here.
- *
- * @param aString is the CString to be compared
- * @param aCount tells us how many chars you want to compare starting with start of string
- * @param aIgnorecase tells us whether to be case sensitive
- * @param aCount tells us how many chars to test; -1 implies full length
- * @return TRUE if equal
- */
-PRBool nsCString::EqualsWithConversion(const char* aCString,PRBool aIgnoreCase,PRInt32 aCount) const{
- PRInt32 theAnswer=Compare(aCString,aIgnoreCase,aCount);
- PRBool result=PRBool(0==theAnswer);
- return result;
-}
-
-//----------------------------------------------------------------------
-
-NS_ConvertUTF16toUTF8::NS_ConvertUTF16toUTF8( const PRUnichar* aString )
- {
- if (!aString)
- // Leave us as an uninitialized nsCAutoString.
- return;
- Init(aString, nsCharTraits::length(aString));
- }
-
-NS_ConvertUTF16toUTF8::NS_ConvertUTF16toUTF8( const PRUnichar* aString, PRUint32 aLength )
- {
- if (!aString)
- // Leave us as an uninitialized nsCAutoString.
- return;
- Init(aString, aLength);
- }
-
-NS_ConvertUTF16toUTF8::NS_ConvertUTF16toUTF8( const nsASingleFragmentString& aString )
- {
- nsASingleFragmentString::const_char_iterator start;
- Init(aString.BeginReading(start), aString.Length());
- }
-
-NS_ConvertUTF16toUTF8::NS_ConvertUTF16toUTF8( const nsAString& aString )
- {
- // Compute space required: do this once so we don't incur multiple
- // allocations. This "optimization" is probably of dubious value...
-
- nsAString::const_iterator start, end;
- CalculateUTF8Size calculator;
- copy_string(aString.BeginReading(start), aString.EndReading(end),
- calculator);
-
- PRUint32 count = calculator.Size();
-
- if (count)
- {
- // Grow the buffer if we need to.
- SetCapacity(count);
-
- // All ready? Time to convert
-
- ConvertUTF16toUTF8 converter(mStr);
- copy_string(aString.BeginReading(start), aString.EndReading(end),
- converter).write_terminator();
- mLength = converter.Size();
- if (mLength != count)
- {
- NS_ERROR("Input invalid or incorrect length was calculated");
- Truncate();
- }
- }
- }
-
-void NS_ConvertUTF16toUTF8::Init( const PRUnichar* aString, PRUint32 aLength )
- {
- // Compute space required: do this once so we don't incur multiple
- // allocations. This "optimization" is probably of dubious value...
-
- CalculateUTF8Size calculator;
- calculator.write(aString, aLength);
-
- PRUint32 count = calculator.Size();
-
- if (count)
- {
- // Grow the buffer if we need to.
- SetCapacity(count);
-
- // All ready? Time to convert
-
- ConvertUTF16toUTF8 converter(mStr);
- converter.write(aString, aLength);
- mLength = converter.Size();
- mStr[mLength] = char_type(0);
- if (mLength != count)
- {
- NS_ERROR("Input invalid or incorrect length was calculated");
- Truncate();
- }
- }
- }
-
-NS_LossyConvertUTF16toASCII::NS_LossyConvertUTF16toASCII( const nsAString& aString )
- {
- SetCapacity(aString.Length());
-
- nsAString::const_iterator start; aString.BeginReading(start);
- nsAString::const_iterator end; aString.EndReading(end);
-
- while (start != end) {
- nsReadableFragment frag(start.fragment());
- AppendWithConversion(frag.mStart, frag.mEnd - frag.mStart);
- start.advance(start.size_forward());
- }
- }
-
-
-/***********************************************************************
- IMPLEMENTATION NOTES: AUTOSTRING...
- ***********************************************************************/
-
-
-/**
- * Default constructor
- *
- */
-nsCAutoString::nsCAutoString() : nsCString(){
- nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
- AddNullTerminator(*this);
-
-}
-
-nsCAutoString::nsCAutoString( const nsCString& aString ) : nsCString(){
- nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
- AddNullTerminator(*this);
- Append(aString);
-}
-
-nsCAutoString::nsCAutoString( const nsACString& aString ) : nsCString(){
- nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
- AddNullTerminator(*this);
- Append(aString);
-}
-
-nsCAutoString::nsCAutoString(const char* aCString) : nsCString() {
- nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
- AddNullTerminator(*this);
- Append(aCString);
-}
-
-/**
- * Copy construct from ascii c-string
- * @param aCString is a ptr to a 1-byte cstr
- */
-nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() {
- nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
- AddNullTerminator(*this);
- Append(aCString,aLength);
-}
-
-/**
- * Copy construct using an external buffer descriptor
- * @param aBuffer -- descibes external buffer
- */
-nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
- if(!aBuffer.mBuffer) {
- nsStrPrivate::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
- }
- else {
- nsStrPrivate::Initialize(*this,aBuffer.mBuffer,aBuffer.mCapacity,aBuffer.mLength,aBuffer.mCharSize,!aBuffer.mStackBased);
- }
- if(!aBuffer.mIsConst)
- AddNullTerminator(*this); //this isn't really needed, but it guarantees that folks don't pass string constants.
-}
diff --git a/mozilla/xpcom/string/obsolete/nsString.h b/mozilla/xpcom/string/obsolete/nsString.h
deleted file mode 100644
index ef13a352254..00000000000
--- a/mozilla/xpcom/string/obsolete/nsString.h
+++ /dev/null
@@ -1,480 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: NPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Netscape Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/NPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Rick Gessner (original author)
- * Scott Collins
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the NPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the NPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/*
- * nsString.h --- rickg's original strings of 1-byte chars, |nsCString|
- * and |nsCAutoString|; these classes will be replaced by the new
- * shared-buffer string (see bug #53065)
- *
- * This file will one day be _only_ a compatibility header for clients
- * using the names |ns[C]String| et al ... which we probably want to
- * support forever.
- */
-
-#ifndef nsString_h__
-#define nsString_h__
-
-#ifndef nsString2_h__
-#include "nsString2.h"
-#endif
-
-class NS_COM nsCString :
- public nsAFlatCString,
- public nsStr {
-
-public:
- friend class nsString;
- friend NS_COM void ToUpperCase( nsCString& );
- friend NS_COM void ToLowerCase( nsCString& );
-
-protected:
- virtual const nsBufferHandle* GetFlatBufferHandle() const;
- virtual const char* GetReadableFragment( nsReadableFragment&, nsFragmentRequest, PRUint32 ) const;
- virtual char* GetWritableFragment( nsWritableFragment&, nsFragmentRequest, PRUint32 );
-
-public:
- virtual const char* get() const { return mStr; }
-
- PRBool IsEmpty() const { return mLength == 0; }
-
-public:
- /**
- * Default constructor.
- */
- nsCString();
-
- /**
- * This is our copy constructor
- * @param reference to another nsCString
- */
- nsCString(const nsCString& aString);
-
- explicit nsCString( const nsACString& );
-
- explicit nsCString(const char*);
- nsCString(const char*, PRInt32);
-
- /**
- * Destructor
- *
- */
- virtual ~nsCString();
-
- /**
- * Retrieve the length of this string
- * @return string length
- */
- virtual PRUint32 Length() const { return mLength; }
-
- /**
- * Call this method if you want to force a different string capacity
- * @update gess7/30/98
- * @param aLength -- contains new length for mStr
- * @return
- */
- void SetLength(PRUint32 aLength);
-
- /**
- * Sets the new length of the string.
- * @param aLength is new string length.
- * @return nada
- */
- void SetCapacity(PRUint32 aLength);
-
- /**********************************************************************
- Accessor methods...
- *********************************************************************/
-
- PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
-
- /**********************************************************************
- Lexomorphic transforms...
- *********************************************************************/
-
-
- /**
- * This method is used to remove all occurances of the
- * characters found in aSet from this string.
- *
- * @param aSet -- characters to be cut from this
- * @return *this
- */
- void StripChars(const char* aSet);
- void StripChar(char aChar,PRInt32 anOffset=0);
-
- /**
- * This method strips whitespace throughout the string
- *
- * @return this
- */
- void StripWhitespace();
-
- /**
- * swaps occurence of 1 string for another
- *
- * @return this
- */
- void ReplaceChar(char aOldChar,char aNewChar);
- void ReplaceChar(const char* aSet,char aNewChar);
-
- void ReplaceSubstring(const nsCString& aTarget,const nsCString& aNewValue);
- void ReplaceSubstring(const char* aTarget,const char* aNewValue);
-
- /**
- * This method trims characters found in aTrimSet from
- * either end of the underlying string.
- *
- * @param aTrimSet -- contains chars to be trimmed from
- * both ends
- * @param aEliminateLeading
- * @param aEliminateTrailing
- * @param aIgnoreQuotes
- * @return this
- */
- void Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE,PRBool aIgnoreQuotes=PR_FALSE);
-
- /**
- * This method strips whitespace from string.
- * You can control whether whitespace is yanked from
- * start and end of string as well.
- *
- * @param aEliminateLeading controls stripping of leading ws
- * @param aEliminateTrailing controls stripping of trailing ws
- * @return this
- */
- void CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
-
- /**********************************************************************
- string conversion methods...
- *********************************************************************/
-
- /**
- * Perform string to float conversion.
- * @param aErrorCode will contain error if one occurs
- * @return float rep of string value
- */
- float ToFloat(PRInt32* aErrorCode) const;
-
-
- /**
- * Perform string to int conversion.
- * @param aErrorCode will contain error if one occurs
- * @param aRadix tells us which radix to assume; kAutoDetect tells us to determine the radix for you.
- * @return int rep of string value, and possible (out) error code
- */
- PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
-
-
- /**********************************************************************
- String manipulation methods...
- *********************************************************************/
-
- /**
- * assign given string to this string
- * @param aStr: buffer to be assigned to this
- * @param aCount is the length of the given str (or -1) if you want me to determine its length
- * NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
- *
- * @return this
- */
-
- nsCString& operator=( const nsCString& aString ) { Assign(aString); return *this; }
- nsCString& operator=( const nsACString& aReadable ) { Assign(aReadable); return *this; }
-//nsCString& operator=( const nsPromiseReadable& aReadable ) { Assign(aReadable); return *this; }
- nsCString& operator=( const char* aPtr ) { Assign(aPtr); return *this; }
- nsCString& operator=( char aChar ) { Assign(aChar); return *this; }
-
- void AssignWithConversion(const PRUnichar*,PRInt32=-1);
- void AssignWithConversion( const nsString& aString );
- void AssignWithConversion( const nsAString& aString );
-
- /*
- * Appends n characters from given string to this,
- *
- * @param aString is the source to be appended to this
- * @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you
- * NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
- *
- * @return number of chars copied
- */
-
- void AppendWithConversion(const nsString&, PRInt32=-1);
- void AppendWithConversion( const nsAString& aString );
- void AppendWithConversion(const PRUnichar*, PRInt32=-1);
- // Why no |AppendWithConversion(const PRUnichar*, PRInt32)|? --- now I know, because implicit construction hid the need for this routine
- void AppendInt(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
- void AppendFloat( double aFloat );
-
-
-#if 0
- virtual void do_AppendFromReadable( const nsACString& );
- virtual void do_InsertFromReadable( const nsACString&, PRUint32 );
-#endif
-
-
- // Takes ownership of aPtr, sets the current length to aLength if specified.
- void Adopt( char* aPtr, PRInt32 aLength = -1 );
-
- /*
- |Left|, |Mid|, and |Right| are annoying signatures that seem better almost
- any _other_ way than they are now. Consider these alternatives
-
- aWritable = aReadable.Left(17); // ...a member function that returns a |Substring|
- aWritable = Left(aReadable, 17); // ...a global function that returns a |Substring|
- Left(aReadable, 17, aWritable); // ...a global function that does the assignment
-
- as opposed to the current signature
-
- aReadable.Left(aWritable, 17); // ...a member function that does the assignment
-
- or maybe just stamping them out in favor of |Substring|, they are just duplicate functionality
-
- aWritable = Substring(aReadable, 0, 17);
- */
-
- size_type Left( self_type&, size_type ) const;
- size_type Mid( self_type&, PRUint32, PRUint32 ) const;
- size_type Right( self_type&, size_type ) const;
-
-
- /**********************************************************************
- Searching methods...
- *********************************************************************/
-
-
- /**
- * Search for given substring within this string
- *
- * @param aString is substring to be sought in this
- * @param aIgnoreCase selects case sensitivity
- * @param anOffset tells us where in this strig to start searching
- * @param aCount tells us how many iterations to make starting at the given offset
- * @return offset in string, or -1 (kNotFound)
- */
- PRInt32 Find(const nsCString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
- PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
- /**
- * Search for given char within this string
- *
- * @param aString is substring to be sought in this
- * @param anOffset tells us where in this strig to start searching
- * @param aIgnoreCase selects case sensitivity
- * @param aCount tells us how many iterations to make starting at the given offset
- * @return find pos in string, or -1 (kNotFound)
- */
- PRInt32 FindChar(PRUnichar aChar,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
-
- /**
- * This method searches this string for the first character
- * found in the given charset
- * @param aString contains set of chars to be found
- * @param anOffset tells us where to start searching in this
- * @return -1 if not found, else the offset in this
- */
- PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const;
- PRInt32 FindCharInSet(const nsCString& aString,PRInt32 anOffset=0) const;
-
-
- /**
- * This methods scans the string backwards, looking for the given string
- * @param aString is substring to be sought in this
- * @param aIgnoreCase tells us whether or not to do caseless compare
- * @param aCount tells us how many iterations to make starting at the given offset
- * @return offset in string, or -1 (kNotFound)
- */
- PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
- PRInt32 RFind(const nsCString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
-
- /**
- * Search for given char within this string
- *
- * @param aString is substring to be sought in this
- * @param anOffset tells us where in this strig to start searching
- * @param aIgnoreCase selects case sensitivity
- * @return find pos in string, or -1 (kNotFound)
- */
- PRInt32 RFindChar(PRUnichar aChar,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
-
- /**
- * This method searches this string for the last character
- * found in the given string
- * @param aString contains set of chars to be found
- * @param anOffset tells us where to start searching in this
- * @return -1 if not found, else the offset in this
- */
- PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
- PRInt32 RFindCharInSet(const nsCString& aString,PRInt32 anOffset=-1) const;
-
-
-
- /**********************************************************************
- Comparison methods...
- *********************************************************************/
-
- /**
- * Compares a given string type to this string.
- * @update gess 7/27/98
- * @param S is the string to be compared
- * @param aIgnoreCase tells us how to treat case
- * @param aCount tells us how many chars to compare
- * @return -1,0,1
- */
- PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
-
- PRBool EqualsWithConversion(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
-
- PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
-
-private:
- // NOT TO BE IMPLEMENTED
- // these signatures help clients not accidentally call the wrong thing helped by C++ automatic integral promotion
- void operator=( PRUnichar );
- void AssignWithConversion( const char*, PRInt32=-1 );
- void InsertWithConversion( char, PRUint32 );
-};
-
-inline
-nsCString::size_type
-nsCString::Left( nsACString& aResult, size_type aLengthToCopy ) const
- {
- return Mid(aResult, 0, aLengthToCopy);
- }
-
-inline
-nsCString::size_type
-nsCString::Right( self_type& aResult, size_type aLengthToCopy ) const
- {
- size_type myLength = Length();
- aLengthToCopy = NS_MIN(myLength, aLengthToCopy);
- return Mid(aResult, myLength-aLengthToCopy, aLengthToCopy);
- }
-
-// NS_DEF_STRING_COMPARISON_OPERATORS(nsCString, char)
-// NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsCString, char)
-
-
-/**************************************************************
- Here comes the AutoString class which uses internal memory
- (typically found on the stack) for its default buffer.
- If the buffer needs to grow, it gets reallocated on the heap.
- **************************************************************/
-
-class NS_COM nsCAutoString : public nsCString {
-public:
-
- virtual ~nsCAutoString() {}
-
- nsCAutoString();
- explicit nsCAutoString(const nsCString& );
- explicit nsCAutoString(const nsACString& aString);
- explicit nsCAutoString(const char* aString);
- nsCAutoString(const char* aString,PRInt32 aLength);
- explicit nsCAutoString(const CBufDescriptor& aBuffer);
-
- nsCAutoString& operator=( const nsCAutoString& aString ) { Assign(aString); return *this; }
- private:
- void operator=( PRUnichar ); // NOT TO BE IMPLEMENTED
- public:
- nsCAutoString& operator=( const nsACString& aReadable ) { Assign(aReadable); return *this; }
-// nsCAutoString& operator=( const nsPromiseReadable& aReadable ) { Assign(aReadable); return *this; }
- nsCAutoString& operator=( const char* aPtr ) { Assign(aPtr); return *this; }
- nsCAutoString& operator=( char aChar ) { Assign(aChar); return *this; }
-
- char mBuffer[kDefaultStringSize];
-};
-
-// NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsCAutoString, char)
-
-/**
- * A helper class that converts a UTF-16 string to UTF-8
- */
-class NS_COM NS_ConvertUTF16toUTF8
- : public nsCAutoString
- /*
- ...
- */
- {
- public:
- explicit NS_ConvertUTF16toUTF8( const PRUnichar* aString );
- NS_ConvertUTF16toUTF8( const PRUnichar* aString, PRUint32 aLength );
- explicit NS_ConvertUTF16toUTF8( const nsAString& aString );
- explicit NS_ConvertUTF16toUTF8( const nsASingleFragmentString& aString );
-
- protected:
- void Init( const PRUnichar* aString, PRUint32 aLength );
-
- private:
- // NOT TO BE IMPLEMENTED
- NS_ConvertUTF16toUTF8( char );
- };
-
-
-/**
- * A helper class that converts a UTF-16 string to ASCII in a lossy manner
- */
-class NS_COM NS_LossyConvertUTF16toASCII
- : public nsCAutoString
- /*
- ...
- */
- {
- public:
- explicit
- NS_LossyConvertUTF16toASCII( const PRUnichar* aString )
- {
- AppendWithConversion( aString, ~PRUint32(0) /* MAXINT */);
- }
-
- NS_LossyConvertUTF16toASCII( const PRUnichar* aString, PRUint32 aLength )
- {
- AppendWithConversion( aString, aLength );
- }
-
- explicit NS_LossyConvertUTF16toASCII( const nsAString& aString );
-
- private:
- // NOT TO BE IMPLEMENTED
- NS_LossyConvertUTF16toASCII( char );
- };
-
-// Backward compatibility
-typedef NS_ConvertUTF16toUTF8 NS_ConvertUCS2toUTF8;
-typedef NS_LossyConvertUTF16toASCII NS_LossyConvertUCS2toASCII;
-
-#endif /* !defined(nsString_h__) */
diff --git a/mozilla/xpcom/string/obsolete/nsString2.cpp b/mozilla/xpcom/string/obsolete/nsString2.cpp
deleted file mode 100644
index 2b87c4d559e..00000000000
--- a/mozilla/xpcom/string/obsolete/nsString2.cpp
+++ /dev/null
@@ -1,1473 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: NPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Netscape Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/NPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Rick Gessner (original author)
- * Scott Collins
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the NPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the NPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include
-#include
-#include
-#include "nsStrPrivate.h"
-#include "nsString.h"
-#include "nsReadableUtils.h"
-#include "nsDebug.h"
-#include "nsUTF8Utils.h"
-
-#ifndef nsCharTraits_h___
-#include "nsCharTraits.h"
-#endif
-
-#ifndef RICKG_TESTBED
-#include "prdtoa.h"
-#endif
-
-#ifdef DEBUG
-static const char* kPossibleNull = "Error: possible unintended null in string";
-static const char* kNullPointerError = "Error: unexpected null ptr";
-#endif
-static const char* kWhitespace="\b\t\r\n ";
-
-const nsBufferHandle*
-nsString::GetFlatBufferHandle() const
- {
- return NS_REINTERPRET_CAST(const nsBufferHandle*, 1);
- }
-
-/**
- * Default constructor.
- */
-nsString::nsString() {
- nsStrPrivate::Initialize(*this,eTwoByte);
-}
-
-nsString::nsString(const PRUnichar* aString) {
- nsStrPrivate::Initialize(*this,eTwoByte);
- Assign(aString);
-}
-
-/**
- * This constructor accepts a unicode string
- * @update gess 1/4/99
- * @param aString is a ptr to a unichar string
- * @param aLength tells us how many chars to copy from given aString
- */
-nsString::nsString(const PRUnichar* aString,PRInt32 aCount) {
- nsStrPrivate::Initialize(*this,eTwoByte);
- Assign(aString,aCount);
-}
-
-/**
- * This is our copy constructor
- * @update gess 1/4/99
- * @param reference to another nsString
- */
-nsString::nsString(const nsString& aString) {
- nsStrPrivate::Initialize(*this,eTwoByte);
- nsStrPrivate::StrAssign(*this,aString,0,aString.mLength);
-}
-
-/**
- * Destructor
- * Make sure we call nsStrPrivate::Destroy.
- */
-nsString::~nsString() {
- nsStrPrivate::Destroy(*this);
-}
-
-const PRUnichar* nsString::GetReadableFragment( nsReadableFragment& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const {
- switch ( aRequest ) {
- case kFirstFragment:
- case kLastFragment:
- case kFragmentAt:
- aFragment.mEnd = (aFragment.mStart = mUStr) + mLength;
- return aFragment.mStart + aOffset;
-
- case kPrevFragment:
- case kNextFragment:
- default:
- return 0;
- }
-}
-
-PRUnichar* nsString::GetWritableFragment( nsWritableFragment& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) {
- switch ( aRequest ) {
- case kFirstFragment:
- case kLastFragment:
- case kFragmentAt:
- aFragment.mEnd = (aFragment.mStart = mUStr) + mLength;
- return aFragment.mStart + aOffset;
-
- case kPrevFragment:
- case kNextFragment:
- default:
- return 0;
- }
-}
-
-
-void
-nsString::do_AppendFromElement( PRUnichar inChar )
- {
- PRUnichar buf[2] = { 0, 0 };
- buf[0] = inChar;
-
- nsStr temp;
- nsStrPrivate::Initialize(temp, eTwoByte);
- temp.mUStr = buf;
- temp.mLength = 1;
- nsStrPrivate::StrAppend(*this, temp, 0, 1);
- }
-
-
-nsString::nsString( const nsAString& aReadable ) {
- nsStrPrivate::Initialize(*this,eTwoByte);
- Assign(aReadable);
-}
-
-/**
- * This method truncates this string to given length.
- *
- * @update gess 01/04/99
- * @param anIndex -- new length of string
- * @return nada
- */
-void nsString::SetLength(PRUint32 anIndex) {
- if ( anIndex > GetCapacity() )
- SetCapacity(anIndex);
- // |SetCapacity| normally doesn't guarantee the use we are putting it to here (see its interface comment in nsAString.h),
- // we can only use it since our local implementation, |nsString::SetCapacity|, is known to do what we want
- nsStrPrivate::StrTruncate(*this,anIndex);
-}
-
-
-/**
- * Call this method if you want to force the string to a certain capacity;
- * |SetCapacity(0)| discards associated storage.
- *
- * @param aNewCapacity -- desired minimum capacity
- */
-void
-nsString::SetCapacity( PRUint32 aNewCapacity )
- {
- if ( aNewCapacity )
- {
- if( aNewCapacity > GetCapacity() )
- nsStrPrivate::GrowCapacity(*this, aNewCapacity);
- AddNullTerminator(*this);
- }
- else
- {
- nsStrPrivate::Destroy(*this);
- nsStrPrivate::Initialize(*this, eTwoByte);
- }
- }
-
-/**********************************************************************
- Accessor methods...
- *********************************************************************/
-
-
-/**
- * set a char inside this string at given index
- * @param aChar is the char you want to write into this string
- * @param anIndex is the ofs where you want to write the given char
- * @return TRUE if successful
- */
-PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
- PRBool result=PR_FALSE;
- if(anIndex::length(aTarget);
- if(0::length(aNewValue);
- if(02)) {
- theFirstChar=First();
- theLastChar=Last();
- if(theFirstChar==theLastChar) {
- if(('\''==theFirstChar) || ('"'==theFirstChar)) {
- Cut(0,1);
- Truncate(mLength-1);
- theQuotesAreNeeded=PR_TRUE;
- }
- else theFirstChar=0;
- }
- }
-
- nsStrPrivate::Trim(*this,aTrimSet,aEliminateLeading,aEliminateTrailing);
-
- if(aIgnoreQuotes && theQuotesAreNeeded) {
- Insert(theFirstChar,0);
- Append(theLastChar);
- }
-
- }
-}
-
-/**
- * This method strips chars in given set from string.
- */
-static void
-CompressSet(nsString& aStr, const char* aSet, PRUnichar aChar,
- PRBool aEliminateLeading, PRBool aEliminateTrailing) {
- if (aSet) {
- aStr.ReplaceChar(aSet, aChar);
- nsStrPrivate::CompressSet2(aStr, aSet,
- aEliminateLeading, aEliminateTrailing);
- }
-}
-
-/**
- * This method strips whitespace from string.
- * You can control whether whitespace is yanked from
- * start and end of string as well.
- *
- * @update gess 3/31/98
- * @param aEliminateLeading controls stripping of leading ws
- * @param aEliminateTrailing controls stripping of trailing ws
- * @return this
- */
-void
-nsString::CompressWhitespace( PRBool aEliminateLeading,PRBool aEliminateTrailing){
- CompressSet(*this, kWhitespace,' ', aEliminateLeading, aEliminateTrailing);
-}
-
-/**********************************************************************
- string conversion methods...
- *********************************************************************/
-
-/**
- * Copies contents of this string into he given buffer
- * Note that if you provide me a buffer that is smaller than the length of
- * this string, only the number of bytes that will fit are copied.
- *
- * @update gess 01/04/99
- * @param aBuf
- * @param aBufLength -- size of your external buffer (including null)
- * @param anOffset -- THIS IS NOT USED AT THIS TIME!
- * @return
- */
-char* nsString::ToCString(char* aBuf, PRUint32 aBufLength,PRUint32 anOffset) const{
- if(aBuf) {
-
- // NS_ASSERTION(mLength<=aBufLength,"buffer smaller than string");
-
- CBufDescriptor theDescr(aBuf,PR_TRUE,aBufLength,0);
- nsCAutoString temp(theDescr);
- nsStrPrivate::StrAssign(temp, *this, anOffset, PR_MIN(mLength, aBufLength-1));
- temp.mStr=0;
- }
- return aBuf;
-}
-
-/**
- * Perform string to float conversion.
- * @update gess 01/04/99
- * @param aErrorCode will contain error if one occurs
- * @return float rep of string value
- */
-float nsString::ToFloat(PRInt32* aErrorCode) const {
- float res = 0.0f;
- char buf[100];
- if (mLength > 0 && mLength < sizeof(buf)) {
- char *conv_stopped;
- const char *str = ToCString(buf, sizeof(buf));
- // Use PR_strtod, not strtod, since we don't want locale involved.
- res = (float)PR_strtod(str, &conv_stopped);
- if (*conv_stopped == '\0') {
- *aErrorCode = (PRInt32) NS_OK;
- }
- else {
- /* Not all the string was scanned */
- *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE;
- }
- }
- else {
- /* The string was too short (0 characters) or too long (sizeof(buf)) */
- *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE;
- }
- return res;
-}
-
-
-/**
- * Perform decimal numeric string to int conversion.
- * NOTE: In this version, we use the radix you give, even if it's wrong.
- * @update gess 02/14/00
- * @param aErrorCode will contain error if one occurs
- * @param aRadix tells us what base to expect the given string in. kAutoDetect tells us to determine the radix.
- * @return int rep of string value
- */
-PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
- PRUnichar* cp=mUStr;
- PRInt32 theRadix=10; // base 10 unless base 16 detected, or overriden (aRadix != kAutoDetect)
- PRInt32 result=0;
- PRBool negate=PR_FALSE;
- PRUnichar theChar=0;
-
- //initial value, override if we find an integer
- *anErrorCode=NS_ERROR_ILLEGAL_VALUE;
-
- if(cp) {
-
- //begin by skipping over leading chars that shouldn't be part of the number...
-
- PRUnichar* endcp=cp+mLength;
- PRBool done=PR_FALSE;
-
- while((cp='A') && (theChar<='F')) {
- if(10==theRadix) {
- if(kAutoDetect==aRadix){
- theRadix=16;
- cp=first; //backup
- result=0;
- haveValue = PR_FALSE;
- }
- else {
- *anErrorCode=NS_ERROR_ILLEGAL_VALUE;
- result=0;
- break;
- }
- }
- else {
- result = (theRadix * result) + ((theChar-'A')+10);
- haveValue = PR_TRUE;
- }
- }
- else if((theChar>='a') && (theChar<='f')) {
- if(10==theRadix) {
- if(kAutoDetect==aRadix){
- theRadix=16;
- cp=first; //backup
- result=0;
- haveValue = PR_FALSE;
- }
- else {
- *anErrorCode=NS_ERROR_ILLEGAL_VALUE;
- result=0;
- break;
- }
- }
- else {
- result = (theRadix * result) + ((theChar-'a')+10);
- haveValue = PR_TRUE;
- }
- }
- else if((('X'==theChar) || ('x'==theChar)) && (!haveValue || result == 0)) {
- continue;
- }
- else if((('#'==theChar) || ('+'==theChar)) && !haveValue) {
- continue;
- }
- else {
- //we've encountered a char that's not a legal number or sign
- break;
- }
- } //while
- if(negate)
- result=-result;
- } //if
- }
- return result;
-}
-
-/**********************************************************************
- String manipulation methods...
- *********************************************************************/
-
-
-
-/**
- * assign given char* to this string
- * @update gess 01/04/99
- * @param aCString: buffer to be assigned to this
- * @param aCount -- length of given buffer or -1 if you want me to compute length.
- * NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
- *
- * @return this
- */
-void nsString::AssignWithConversion(const char* aCString,PRInt32 aCount) {
- nsStrPrivate::StrTruncate(*this,0);
- if(aCString){
- AppendWithConversion(aCString,aCount);
- }
-}
-
-void nsString::AssignWithConversion(const char* aCString) {
- nsStrPrivate::StrTruncate(*this,0);
- if(aCString){
- AppendWithConversion(aCString);
- }
-}
-
-
-/**
- * append given c-string to this string
- * @update gess 01/04/99
- * @param aString : string to be appended to this
- * @param aCount -- length of given buffer or -1 if you want me to compute length.
- * NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
- *
- * @return this
- */
-void nsString::AppendWithConversion(const char* aCString,PRInt32 aCount) {
- if(aCString && aCount){ //if astring is null or count==0 there's nothing to do
- nsStr temp;
- nsStrPrivate::Initialize(temp,eOneByte);
- temp.mStr = NS_CONST_CAST(char*, aCString);
-
- if(0::length(aCString);
-
- if(0=1) {
- PRInt32 theDiv=theInt/mask1;
- if((theDiv) || (!isfirst)) {
- buf[charpos++]="0123456789abcdef"[theDiv];
- isfirst=PR_FALSE;
- }
- theInt-=theDiv*mask1;
- mask1/=aRadix;
- }
- AppendWithConversion(buf);
-}
-
-
-/**
- * Append the given float to this string
- * @update gess 01/04/99
- * @param aFloat:
- * @return
- */
-void nsString::AppendFloat(double aFloat){
- char buf[40];
- // Use nsStrPrivate::cnvtf, which is locale-insensitive, instead of the
- // locale-sensitive PR_snprintf or sprintf(3)
- nsStrPrivate::cnvtf(buf, sizeof(buf), 6, aFloat);
- AppendWithConversion(buf);
-}
-
-
-
-/**
- * Insert a char* into this string at a specified offset.
- *
- * @update gess4/22/98
- * @param char* aCString to be inserted into this string
- * @param anOffset is insert pos in str
- * @param aCount -- length of given buffer or -1 if you want me to compute length.
- * NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
- *
- * @return this
- */
-void nsString::InsertWithConversion(const char* aCString,PRUint32 anOffset,PRInt32 aCount){
- if(aCString && aCount){
- nsStr temp;
- nsStrPrivate::Initialize(temp,eOneByte);
- temp.mStr = NS_CONST_CAST(char*, aCString);
-
- if(0::length(aCString);
-
- if(0::length(aPtr);
- // We don't know the capacity, so we'll just have to assume
- // capacity = length.
- nsStrPrivate::Initialize(*this, (char*)aPtr, aLength, aLength, eTwoByte, PR_TRUE);
-}
-
-nsAString::size_type
-nsString::Mid( self_type& aResult, index_type aStartPos, size_type aLengthToCopy ) const
- {
- // If we're just assigning our entire self, give |aResult| the opportunity to share
- if ( aStartPos == 0 && aLengthToCopy >= Length() )
- aResult = *this;
- else
- aResult = Substring(*this, aStartPos, aLengthToCopy);
-
- return aResult.Length();
- }
-
-
-/**********************************************************************
- Searching methods...
- *********************************************************************/
-
- /**
- * Search for given character within this string
- *
- * @param aChar is the character to search for
- * @param anOffset tells us where in this string to start searching
- (optional parameter)
- * @param aCount tells us how far from the offset we are to search. Use
- -1 to search the whole string. (optional parameter)
- * @return offset in string, or -1 (kNotFound)
- */
-PRInt32 nsString::FindChar(PRUnichar aChar, PRInt32 anOffset/*=0*/, PRInt32 aCount/*=-1*/) const{
- if (anOffset < 0)
- anOffset=0;
-
- if (aCount < 0)
- aCount = (PRInt32)mLength;
-
- if ((0 < mLength) && ((PRUint32)anOffset < mLength) && (0 < aCount)) {
- PRUint32 last = anOffset + aCount;
- PRUint32 end = (last < mLength) ? last : mLength;
- const PRUnichar* charp = mUStr + anOffset;
- const PRUnichar* endp = mUStr + end;
-
- while (charp < endp && *charp != aChar) {
- ++charp;
- }
-
- if (charp < endp)
- return charp - mUStr;
- }
- return kNotFound;
-}
-
-/**
- * search for given string within this string
- *
- * @update gess 3/25/98
- * @param aString - substr to be found
- * @param aIgnoreCase tells us whether or not to do caseless compare
- * @param anOffset tells us where in this string to start searching
- * @param aCount tells us how many iterations to make starting at the given offset
- * @return offset in string, or -1 (kNotFound)
- */
-PRInt32 nsString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
- NS_ASSERTION(0!=aCString,kNullPointerError);
-
- PRInt32 result=kNotFound;
- if(aCString) {
- nsStr temp;
- nsStrPrivate::Initialize(temp,eOneByte);
- temp.mLength=nsCharTraits::length(aCString);
- temp.mStr = NS_CONST_CAST(char*, aCString);
- result=nsStrPrivate::FindSubstr1in2(*this,temp,aIgnoreCase,anOffset,aCount);
- }
- return result;
-}
-
-/**
- * search for given string within this string
- *
- * @update gess 3/25/98
- * @param aString - substr to be found
- * @param aIgnoreCase tells us whether or not to do caseless compare
- * @param anOffset tells us where in this string to start searching
- * @param aCount tells us how many iterations to make starting at the given offset
- * @return offset in string, or -1 (kNotFound)
- */
-PRInt32 nsString::Find(const PRUnichar* aString,PRInt32 anOffset,PRInt32 aCount) const{
- NS_ASSERTION(0!=aString,kNullPointerError);
-
- PRInt32 result=kNotFound;
- if(aString) {
- nsStr temp;
- nsStrPrivate::Initialize(temp,eTwoByte);
- temp.mLength = nsCharTraits::length(aString);
- temp.mUStr = NS_CONST_CAST(PRUnichar*, aString);
- result=nsStrPrivate::FindSubstr2in2(*this,temp,anOffset,aCount);
- }
- return result;
-}
-
-/**
- * search for given string within this string
- *
- * @update gess 3/25/98
- * @param aString - substr to be found
- * @param aIgnoreCase tells us whether or not to do caseless compare
- * @param anOffset tells us where in this string to start searching
- * @param aCount tells us how many iterations to make starting at the given offset
- * @return offset in string, or -1 (kNotFound)
- */
-PRInt32 nsString::Find(const nsAFlatString& aString,PRInt32 anOffset,PRInt32 aCount) const{
-
- nsStr temp;
- nsStrPrivate::Initialize(temp, eTwoByte);
- temp.mLength = aString.Length();
- temp.mUStr = NS_CONST_CAST(PRUnichar*, aString.get());
-
- PRInt32 result=nsStrPrivate::FindSubstr2in2(*this,temp,anOffset,aCount);
- return result;
-}
-
-/**
- * This method finds the offset of the first char in this string that is
- * a member of the given charset, starting the search at anOffset
- *
- * @update gess 3/25/98
- * @param aCStringSet
- * @param anOffset -- where in this string to start searching
- * @return
- */
-PRInt32 nsString::FindCharInSet(const char* aCStringSet,PRInt32 anOffset) const{
- NS_ASSERTION(0!=aCStringSet,kNullPointerError);
-
- if (anOffset < 0)
- anOffset = 0;
-
- if(*aCStringSet && (PRUint32)anOffset < mLength) {
- // Build filter that will be used to filter out characters with
- // bits that none of the terminal chars have. This works very well
- // because searches are often done for chars with only the last
- // 4-6 bits set and normal ascii letters have bit 7 set. Other
- // letters have even higher bits set.
-
- // Calculate filter
- PRUnichar filter = (~PRUnichar(0)^~char(0)) |
- nsStrPrivate::GetFindInSetFilter(aCStringSet);
-
- const PRUnichar* endChar = mUStr + mLength;
- for(PRUnichar *charp = mUStr + anOffset; charp < endChar; ++charp) {
- PRUnichar currentChar = *charp;
- // Check if all bits are in the required area
- if (currentChar & filter) {
- // They were not. Go on with the next char.
- continue;
- }
-
- // Test all chars
- const char *setp = aCStringSet;
- PRUnichar setChar = PRUnichar(*setp);
- while (setChar) {
- if (setChar == currentChar) {
- // Found it!
- return charp - mUStr; // The index of the found char
- }
- setChar = PRUnichar(*(++setp));
- }
- } // end for all chars in the string
- }
- return kNotFound;
-}
-
-/**
- * This method finds the offset of the first char in this string that is
- * a member of the given charset, starting the search at anOffset
- *
- * @update gess 3/25/98
- * @param aCStringSet
- * @param anOffset -- where in this string to start searching
- * @return
- */
-PRInt32 nsString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) const{
- NS_ASSERTION(0!=aStringSet,kNullPointerError);
-
- if (anOffset < 0)
- anOffset = 0;
-
- if (*aStringSet && (PRUint32)anOffset < mLength) {
- // Build filter that will be used to filter out characters with
- // bits that none of the terminal chars have. This works very well
- // because searches are often done for chars with only the last
- // 4-6 bits set and normal ascii letters have bit 7 set. Other
- // letters have even higher bits set.
-
- // Calculate filter
- PRUnichar filter = nsStrPrivate::GetFindInSetFilter(aStringSet);
-
- const PRUnichar* endChar = mUStr + mLength;
- for(PRUnichar *charp = mUStr + anOffset;charp < endChar; ++charp) {
- PRUnichar currentChar = *charp;
- // Check if all bits are in the required area
- if (currentChar & filter) {
- // They were not. Go on with the next char.
- continue;
- }
-
- // Test all chars
- const PRUnichar *setp = aStringSet;
- PRUnichar setChar = *setp;
- while (setChar) {
- if (setChar == currentChar) {
- // Found it!
- return charp - mUStr; // The index of the found char
- }
- setChar = *(++setp);
- }
- } // end for all chars in the string
- }
- return kNotFound;
-}
-
-/**
- * Reverse search for given string within this string
- *
- * @update gess 3/25/98
- * @param aString - substr to be found
- * @param aIgnoreCase tells us whether or not to do caseless compare
- * @param anOffset tells us where in this string to start searching
- * @param aCount tells us how many iterations to make starting at the given offset
- * @return offset in string, or -1 (kNotFound)
- */
-PRInt32 nsString::RFind(const nsAFlatString& aString,PRInt32 anOffset,PRInt32 aCount) const
-{
- nsStr temp;
- nsStrPrivate::Initialize(temp, eTwoByte);
- temp.mLength = aString.Length();
- temp.mUStr = NS_CONST_CAST(PRUnichar*, aString.get());
- PRInt32 result=nsStrPrivate::RFindSubstr2in2(*this,temp,anOffset,aCount);
- return result;
-}
-
-PRInt32 nsString::RFind(const PRUnichar* aString, PRInt32 anOffset, PRInt32 aCount) const
-{
- PRInt32 result=kNotFound;
- if (aString) {
- nsStr temp;
- nsStrPrivate::Initialize(temp, eTwoByte);
- temp.mLength = nsCharTraits::length(aString);
- temp.mUStr = NS_CONST_CAST(PRUnichar*, aString);
- result=nsStrPrivate::RFindSubstr2in2(*this,temp,anOffset,aCount);
- }
- return result;
-}
-
-/**
- * Reverse search for given string within this string
- *
- * @update gess 3/25/98
- * @param aString - substr to be found
- * @param aIgnoreCase tells us whether or not to do caseless compare
- * @param anOffset tells us where in this string to start searching
- * @param aCount tells us how many iterations to make starting at the given offset
- * @return offset in string, or -1 (kNotFound)
- */
-PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
- NS_ASSERTION(0!=aString,kNullPointerError);
-
- PRInt32 result=kNotFound;
- if(aString) {
- nsStr temp;
- nsStrPrivate::Initialize(temp,eOneByte);
- temp.mLength=nsCharTraits::length(aString);
- temp.mStr = NS_CONST_CAST(char*, aString);
- result=nsStrPrivate::RFindSubstr1in2(*this,temp,aIgnoreCase,anOffset,aCount);
- }
- return result;
-}
-
-/**
- * Reverse search for a given char, starting at given offset
- *
- * @update gess 3/25/98
- * @param aChar
- * @param aIgnoreCase
- * @param anOffset
- * @return offset of found char, or -1 (kNotFound)
- */
-PRInt32 nsString::RFindChar(PRUnichar aChar,PRInt32 anOffset,PRInt32 aCount) const{
- PRInt32 result=nsStrPrivate::RFindChar2(*this,aChar,anOffset,aCount);
- return result;
-}
-
-/**
- * Reverse search for a first char in this string that is a
- * member of the given char set
- *
- * @update gess 3/25/98
- * @param aSet
- * @param aIgnoreCase
- * @param anOffset
- * @return offset of found char, or -1 (kNotFound)
- */
-PRInt32 nsString::RFindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) const{
- NS_ASSERTION(0!=aStringSet,kNullPointerError);
-
- if (anOffset < 0 || (PRUint32)anOffset >= mLength)
- anOffset = mLength - 1;
-
- if(*aStringSet) {
- // Build filter that will be used to filter out characters with
- // bits that none of the terminal chars have. This works very well
- // because searches are often done for chars with only the last
- // 4-6 bits set and normal ascii letters have bit 7 set. Other
- // letters have even higher bits set.
-
- // Calculate filter
- PRUnichar filter = nsStrPrivate::GetFindInSetFilter(aStringSet);
-
- const PRUnichar* endp = mUStr - 1;
- for(PRUnichar *charp = mUStr + anOffset; charp > endp; --charp) {
- PRUnichar currentChar = *charp;
- // Check if all bits are in the required area
- if (currentChar & filter) {
- // They were not. Go on with the next char.
- continue;
- }
-
- // Test all chars
- const PRUnichar* setp = aStringSet;
- PRUnichar setChar = *setp;
- while (setChar) {
- if (setChar == currentChar) {
- // Found it!
- return charp - mUStr;
- }
- setChar = *(++setp);
- }
- } // end for all chars in the string
- }
- return kNotFound;
-}
-
-
-/**************************************************************
- COMPARISON METHODS...
- **************************************************************/
-
-/**
- * Compares given cstring to this string.
- * @update gess 01/04/99
- * @param aCString pts to a cstring
- * @param aIgnoreCase tells us how to treat case
- * @param aCount tells us how many chars to test; -1 implies full length
- * @return -1,0,1
- */
-PRInt32 nsString::CompareWithConversion(const char *aCString,PRBool aIgnoreCase,PRInt32 aCount) const {
- NS_ASSERTION(0!=aCString,kNullPointerError);
-
- if(aCString) {
- nsStr temp;
- nsStrPrivate::Initialize(temp,eOneByte);
-
- temp.mLength= (0::length(aCString);
-
- temp.mStr = NS_CONST_CAST(char*, aCString);
- return nsStrPrivate::StrCompare2To1(*this,temp,aCount,aIgnoreCase);
- }
-
- return 0;
-}
-
-PRBool nsString::EqualsIgnoreCase(const char* aString,PRInt32 aLength) const {
- return EqualsWithConversion(aString,PR_TRUE,aLength);
-}
-
-/**
- * Compare this to given c-string; note that we compare full strings here.
- *
- * @param aString is the CString to be compared
- * @param aIgnorecase tells us whether to be case sensitive
- * @param aCount tells us how many chars to test; -1 implies full length
- * @return TRUE if equal
- */
-PRBool nsString::EqualsWithConversion(const char* aString,PRBool aIgnoreCase,PRInt32 aCount) const {
- PRInt32 theAnswer=CompareWithConversion(aString,aIgnoreCase,aCount);
- PRBool result=PRBool(0==theAnswer);
- return result;
-}
-
-PRInt32 Compare2To2(const PRUnichar* aStr1,const PRUnichar* aStr2,PRUint32 aCount);
-
-/**
- * Determine if given char is a valid space character
- *
- * @update gess 3/31/98
- * @param aChar is character to be tested
- * @return TRUE if is valid space char
- */
-PRBool nsString::IsSpace(PRUnichar aChar) {
- // XXX i18n
- if ((aChar == ' ') || (aChar == '\r') || (aChar == '\n') || (aChar == '\t')) {
- return PR_TRUE;
- }
- return PR_FALSE;
-}
-
-/**
- * Determine if given buffer contains plain ascii
- *
- * @param aBuffer -- if null, then we test *this, otherwise we test given buffer
- * @return TRUE if is all ascii chars, or if strlen==0
- */
-PRBool nsString::IsASCII(const PRUnichar* aBuffer) {
-
- if(!aBuffer) {
- if(eOneByte==GetCharSize()) {
- char* aByte = mStr;
- while(*aByte) {
- if(*aByte & 0x80) { // don't use (*aByte > 0x7F) since char is signed
- return PR_FALSE;
- }
- aByte++;
- }
- return PR_TRUE;
- } else {
- aBuffer=mUStr; // let the following code handle it
- }
- }
- if(aBuffer) {
- while(*aBuffer) {
- if(*aBuffer>0x007F){
- return PR_FALSE;
- }
- aBuffer++;
- }
- }
- return PR_TRUE;
-}
-
-
-/***********************************************************************
- IMPLEMENTATION NOTES: AUTOSTRING...
- ***********************************************************************/
-
-
-/**
- * Default constructor
- *
- */
-nsAutoString::nsAutoString() : nsString() {
- nsStrPrivate::Initialize(*this, (char*)mBuffer, (sizeof(mBuffer)/sizeof(mBuffer[0]))-1, 0, eTwoByte, PR_FALSE);
- AddNullTerminator(*this);
-}
-
-nsAutoString::nsAutoString(const PRUnichar* aString) : nsString() {
- nsStrPrivate::Initialize(*this, (char*)mBuffer, (sizeof(mBuffer)/sizeof(mBuffer[0]))-1, 0, eTwoByte, PR_FALSE);
- AddNullTerminator(*this);
- Append(aString);
-}
-
-/**
- * Copy construct from uni-string
- * @param aString is a ptr to a unistr
- * @param aLength tells us how many chars to copy from aString
- */
-nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() {
- nsStrPrivate::Initialize(*this, (char*)mBuffer, (sizeof(mBuffer)/sizeof(mBuffer[0]))-1, 0, eTwoByte, PR_FALSE);
- AddNullTerminator(*this);
- Append(aString,aLength);
-}
-
-nsAutoString::nsAutoString( const nsString& aString )
- : nsString()
-{
- nsStrPrivate::Initialize(*this, (char*)mBuffer, (sizeof(mBuffer)/sizeof(mBuffer[0]))-1, 0, eTwoByte, PR_FALSE);
- AddNullTerminator(*this);
- Append(aString);
-}
-
-nsAutoString::nsAutoString( const nsAString& aString )
- : nsString()
-{
- nsStrPrivate::Initialize(*this, (char*)mBuffer, (sizeof(mBuffer)/sizeof(mBuffer[0]))-1, 0, eTwoByte, PR_FALSE);
- AddNullTerminator(*this);
- Append(aString);
-}
-
-
-
-/**
- * constructor that uses external buffer
- * @param aBuffer describes the external buffer
- */
-nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
- if(!aBuffer.mBuffer) {
- nsStrPrivate::Initialize(*this, (char*)mBuffer, (sizeof(mBuffer)/sizeof(mBuffer[0]))-1, 0, eTwoByte, PR_FALSE);
- }
- else {
- nsStrPrivate::Initialize(*this, aBuffer.mBuffer, aBuffer.mCapacity, aBuffer.mLength, aBuffer.mCharSize, !aBuffer.mStackBased);
- }
- if(!aBuffer.mIsConst)
- AddNullTerminator(*this);
-}
-
-PRUnichar* nsVoidableString::GetWritableFragment(nsWritableFragment& aFragment,nsFragmentRequest aRequest,PRUint32 aOffset) {
- mIsVoid = PR_FALSE;
-
- return nsAutoString::GetWritableFragment(aFragment, aRequest, aOffset);
-}
-
-PRBool nsVoidableString::IsVoid() const {
- return mIsVoid;
-}
-
-void nsVoidableString::SetIsVoid(PRBool aVoid) {
- if (aVoid && !mIsVoid) {
- Truncate();
- }
-
- mIsVoid = aVoid;
-}
-
-void
-NS_ConvertASCIItoUTF16::Init( const char* aCString, PRUint32 aLength )
- {
- AppendWithConversion(aCString,aLength);
- }
-
-NS_ConvertASCIItoUTF16::NS_ConvertASCIItoUTF16( const nsACString& aCString )
- {
- SetCapacity(aCString.Length());
-
- nsACString::const_iterator start; aCString.BeginReading(start);
- nsACString::const_iterator end; aCString.EndReading(end);
-
- while (start != end)
- {
- const nsReadableFragment& frag = start.fragment();
- AppendWithConversion(frag.mStart, frag.mEnd - frag.mStart);
- start.advance(start.size_forward());
- }
- }
-
-NS_ConvertUTF8toUTF16::NS_ConvertUTF8toUTF16( const nsACString& aCString )
- {
- // Compute space required: do this once so we don't incur multiple
- // allocations. This "optimization" is probably of dubious value...
-
- nsACString::const_iterator start, end;
- CalculateUTF8Length calculator;
- copy_string(aCString.BeginReading(start), aCString.EndReading(end),
- calculator);
-
- PRUint32 count = calculator.Length();
-
- if (count)
- {
- // Grow the buffer if we need to.
- SetCapacity(count);
-
- // All ready? Time to convert
-
- ConvertUTF8toUTF16 converter(mUStr);
- copy_string(aCString.BeginReading(start), aCString.EndReading(end),
- converter).write_terminator();
- mLength = converter.Length();
- if (mLength != count)
- {
- NS_ERROR("Input wasn't UTF-8 or incorrect length was calculated");
- Truncate();
- }
- }
- }
-
-NS_ConvertUTF8toUTF16::NS_ConvertUTF8toUTF16( const nsASingleFragmentCString& aCString )
- {
- nsASingleFragmentCString::const_char_iterator start;
- Init(aCString.BeginReading(start), aCString.Length());
- }
-
-NS_ConvertUTF8toUTF16::NS_ConvertUTF8toUTF16( const char* aCString )
- {
- if (!aCString)
- // Leave us as an uninitialized nsAutoString.
- return;
- Init(aCString, nsCharTraits::length(aCString));
- }
-
-NS_ConvertUTF8toUTF16::NS_ConvertUTF8toUTF16( const char* aCString, PRUint32 aLength )
- {
- if (!aCString)
- // Leave us as an uninitialized nsAutoString.
- return;
- Init(aCString, aLength);
- }
-
-void
-NS_ConvertUTF8toUTF16::Init( const char* aCString, PRUint32 aLength )
- {
- // Compute space required: do this once so we don't incur multiple
- // allocations. This "optimization" is probably of dubious value...
-
- CalculateUTF8Length calculator;
- calculator.write(aCString, aLength);
-
- PRUint32 count = calculator.Length();
-
- if (count)
- {
- // Grow the buffer if we need to.
- SetCapacity(count);
-
- // All ready? Time to convert
-
- ConvertUTF8toUTF16 converter(mUStr);
- converter.write(aCString, aLength);
- mLength = converter.Length();
- mUStr[mLength] = char_type(0);
- if (mLength != count)
- {
- NS_ERROR("Input invalid or incorrect length was calculated");
- Truncate();
- }
- }
- }
-
-/**
- * Default copy constructor
- */
-nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
- nsStrPrivate::Initialize(*this,(char*)mBuffer,(sizeof(mBuffer)/sizeof(mBuffer[0]))-1,0,eTwoByte,PR_FALSE);
- AddNullTerminator(*this);
- Append(aString);
-}
-
-
-/**
- * Copy construct from a unichar
- * @param
- */
-nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
- nsStrPrivate::Initialize(*this,(char*)mBuffer,(sizeof(mBuffer)/sizeof(mBuffer[0]))-1,0,eTwoByte,PR_FALSE);
- AddNullTerminator(*this);
- Append(aChar);
-}
diff --git a/mozilla/xpcom/string/public/Makefile.in b/mozilla/xpcom/string/public/Makefile.in
index 5a47663b6ae..34961c76260 100644
--- a/mozilla/xpcom/string/public/Makefile.in
+++ b/mozilla/xpcom/string/public/Makefile.in
@@ -62,6 +62,12 @@ EXPORTS = \
nsTString.h \
nsTStringBase.h \
nsTStringTuple.h \
+ nsObsoleteAString.h \
+ nsStringBase.h \
+ nsStringTuple.h \
+ string-template-def-unichar.h \
+ string-template-def-char.h \
+ string-template-undef.h \
$(NULL)
include $(topsrcdir)/config/rules.mk
diff --git a/mozilla/xpcom/string/public/nsAFlatString.h b/mozilla/xpcom/string/public/nsAFlatString.h
index 1b0fc883d6e..7c4644edc6c 100644
--- a/mozilla/xpcom/string/public/nsAFlatString.h
+++ b/mozilla/xpcom/string/public/nsAFlatString.h
@@ -26,8 +26,8 @@
#ifndef nsAFlatString_h___
#define nsAFlatString_h___
-#ifndef nsTString_h___
-#include "nsTString.h"
+#ifndef nsString_h___
+#include "nsString.h"
#endif
#endif /* !defined(nsAFlatString_h___) */
diff --git a/mozilla/xpcom/string/public/nsASingleFragmentString.h b/mozilla/xpcom/string/public/nsASingleFragmentString.h
index 19962335d6d..cf73261168d 100644
--- a/mozilla/xpcom/string/public/nsASingleFragmentString.h
+++ b/mozilla/xpcom/string/public/nsASingleFragmentString.h
@@ -26,8 +26,8 @@
#ifndef nsASingleFragmentString_h___
#define nsASingleFragmentString_h___
-#ifndef nsTStringBase_h___
-#include "nsTStringBase.h"
+#ifndef nsStringBase_h___
+#include "nsStringBase.h"
#endif
#endif /* !defined(nsASingleFragmentString_h___) */
diff --git a/mozilla/xpcom/string/public/nsAString.h b/mozilla/xpcom/string/public/nsAString.h
index c5a196d66b6..6251dc1f218 100644
--- a/mozilla/xpcom/string/public/nsAString.h
+++ b/mozilla/xpcom/string/public/nsAString.h
@@ -24,8 +24,49 @@
#ifndef nsAString_h___
#define nsAString_h___
-#ifndef nsTAString_h___
+#ifndef nsStringFwd_h___
+#include "nsStringFwd.h"
+#endif
+
+#ifndef nsStringIterator_h___
+#include "nsStringIterator.h"
+#endif
+
+#ifndef nsObsoleteAString_h___
+#include "nsObsoleteAString.h"
+#endif
+
+
+ // declare nsAString
+#include "string-template-def-unichar.h"
#include "nsTAString.h"
+#include "string-template-undef.h"
+
+
+ // declare nsACString
+#include "string-template-def-char.h"
+#include "nsTAString.h"
+#include "string-template-undef.h"
+
+
+ /**
+ * ASCII case-insensitive comparator. (for Unicode case-insensitive
+ * comparision, see nsUnicharUtils.h)
+ */
+class NS_COM nsCaseInsensitiveCStringComparator
+ : public nsCStringComparator
+ {
+ public:
+ typedef char char_type;
+
+ virtual int operator()( const char_type*, const char_type*, PRUint32 length ) const;
+ virtual int operator()( char_type, char_type ) const;
+ };
+
+
+ // included here for backwards compatibility
+#ifndef nsStringTuple_h___
+#include "nsStringTuple.h"
#endif
#endif // !defined(nsAString_h___)
diff --git a/mozilla/xpcom/string/public/nsDependentConcatenation.h b/mozilla/xpcom/string/public/nsDependentConcatenation.h
index 44603b5392a..92795340221 100644
--- a/mozilla/xpcom/string/public/nsDependentConcatenation.h
+++ b/mozilla/xpcom/string/public/nsDependentConcatenation.h
@@ -27,8 +27,8 @@
#ifndef nsDependentConcatenation_h___
#define nsDependentConcatenation_h___
-#ifndef nsTStringTuple_h___
-#include "nsTStringTuple.h"
+#ifndef nsStringTuple_h___
+#include "nsStringTuple.h"
#endif
#endif /* !defined(nsDependentConcatenation_h___) */
diff --git a/mozilla/xpcom/string/public/nsDependentString.h b/mozilla/xpcom/string/public/nsDependentString.h
index 279d877eef4..9750732c374 100644
--- a/mozilla/xpcom/string/public/nsDependentString.h
+++ b/mozilla/xpcom/string/public/nsDependentString.h
@@ -24,8 +24,22 @@
#ifndef nsDependentString_h___
#define nsDependentString_h___
-#ifndef nsTDependentString_h___
-#include "nsTDependentString.h"
+#ifndef nsString_h___
+#include "nsString.h"
#endif
+#ifndef nsDebug_h___
+#include "nsDebug.h"
+#endif
+
+ // declare nsDependentString
+#include "string-template-def-unichar.h"
+#include "nsTDependentString.h"
+#include "string-template-undef.h"
+
+ // declare nsDependentCString
+#include "string-template-def-char.h"
+#include "nsTDependentString.h"
+#include "string-template-undef.h"
+
#endif /* !defined(nsDependentString_h___) */
diff --git a/mozilla/xpcom/string/public/nsDependentSubstring.h b/mozilla/xpcom/string/public/nsDependentSubstring.h
index 3b367944010..abe10bf33a1 100644
--- a/mozilla/xpcom/string/public/nsDependentSubstring.h
+++ b/mozilla/xpcom/string/public/nsDependentSubstring.h
@@ -24,8 +24,18 @@
#ifndef nsDependentSubstring_h___
#define nsDependentSubstring_h___
-#ifndef nsTDependentSubstring_h___
-#include "nsTDependentSubstring.h"
+#ifndef nsStringBase_h___
+#include "nsStringBase.h"
#endif
+ // declare nsDependentSubstring
+#include "string-template-def-unichar.h"
+#include "nsTDependentSubstring.h"
+#include "string-template-undef.h"
+
+ // declare nsDependentCSubstring
+#include "string-template-def-char.h"
+#include "nsTDependentSubstring.h"
+#include "string-template-undef.h"
+
#endif /* !defined(nsDependentSubstring_h___) */
diff --git a/mozilla/xpcom/string/public/nsObsoleteAString.h b/mozilla/xpcom/string/public/nsObsoleteAString.h
new file mode 100644
index 00000000000..de842ff85d9
--- /dev/null
+++ b/mozilla/xpcom/string/public/nsObsoleteAString.h
@@ -0,0 +1,66 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla.
+ *
+ * The Initial Developer of the Original Code is IBM Corporation.
+ * Portions created by IBM Corporation are Copyright (C) 2003
+ * IBM Corporation. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Darin Fisher
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef nsObsoleteAString_h___
+#define nsObsoleteAString_h___
+
+/****************************************************************************
+
+ THIS FILE IS NOT FOR HUMAN CONSUMPTION. See nsAString instead.
+
+ ****************************************************************************/
+
+#ifndef nsStringFwd_h___
+#include "nsStringFwd.h"
+#endif
+
+#ifndef nscore_h___
+#include "nscore.h"
+#endif
+
+ // declare nsObsoleteAString
+#include "string-template-def-unichar.h"
+#include "nsTObsoleteAString.h"
+#include "string-template-undef.h"
+
+ // declare nsObsoleteACString
+#include "string-template-def-char.h"
+#include "nsTObsoleteAString.h"
+#include "string-template-undef.h"
+
+#endif // !defined(nsObsoleteAString_h___)
diff --git a/mozilla/xpcom/string/public/nsPrintfCString.h b/mozilla/xpcom/string/public/nsPrintfCString.h
index 058c32e35c4..4bba696f157 100755
--- a/mozilla/xpcom/string/public/nsPrintfCString.h
+++ b/mozilla/xpcom/string/public/nsPrintfCString.h
@@ -38,8 +38,8 @@
#ifndef nsPrintfCString_h___
#define nsPrintfCString_h___
-#ifndef nsTString_h___
-#include "nsTString.h"
+#ifndef nsString_h___
+#include "nsString.h"
#endif
@@ -67,9 +67,9 @@
* much more efficiently handled with |NS_LITERAL_[C]STRING| and |nsLiteral[C]String|.
*/
-class NS_COM nsPrintfCString : public nsTString
+class NS_COM nsPrintfCString : public nsCString
{
- typedef nsTString string_type;
+ typedef nsCString string_type;
enum { kLocalBufferSize=15 };
// ought to be large enough for most things ... a |long long| needs at most 20 (so you'd better ask)
diff --git a/mozilla/xpcom/string/public/nsPromiseFlatString.h b/mozilla/xpcom/string/public/nsPromiseFlatString.h
index dbba1814856..8106d244055 100644
--- a/mozilla/xpcom/string/public/nsPromiseFlatString.h
+++ b/mozilla/xpcom/string/public/nsPromiseFlatString.h
@@ -24,8 +24,66 @@
#ifndef nsPromiseFlatString_h___
#define nsPromiseFlatString_h___
-#ifndef nsTPromiseFlatString_h___
-#include "nsTPromiseFlatString.h"
+#ifndef nsString_h___
+#include "nsString.h"
#endif
+ // declare nsPromiseFlatString
+#include "string-template-def-unichar.h"
+#include "nsTPromiseFlatString.h"
+#include "string-template-undef.h"
+
+ // declare nsPromiseFlatCString
+#include "string-template-def-char.h"
+#include "nsTPromiseFlatString.h"
+#include "string-template-undef.h"
+
+
+inline
+const nsPromiseFlatString
+PromiseFlatString( const nsAString& str )
+ {
+ return nsPromiseFlatString(str);
+ }
+
+ // e.g., PromiseFlatString(Substring(s))
+inline
+const nsPromiseFlatString
+PromiseFlatString( const nsStringBase& frag )
+ {
+ return nsPromiseFlatString(frag);
+ }
+
+ // e.g., PromiseFlatString(a + b)
+inline
+const nsPromiseFlatString
+PromiseFlatString( const nsStringTuple& tuple )
+ {
+ return nsPromiseFlatString(tuple);
+ }
+
+
+inline
+const nsPromiseFlatCString
+PromiseFlatCString( const nsACString& str )
+ {
+ return nsPromiseFlatCString(str);
+ }
+
+ // e.g., PromiseFlatCString(Substring(s))
+inline
+const nsPromiseFlatCString
+PromiseFlatCString( const nsCStringBase& frag )
+ {
+ return nsPromiseFlatCString(frag);
+ }
+
+ // e.g., PromiseFlatCString(a + b)
+inline
+const nsPromiseFlatCString
+PromiseFlatCString( const nsCStringTuple& tuple )
+ {
+ return nsPromiseFlatCString(tuple);
+ }
+
#endif /* !defined(nsPromiseFlatString_h___) */
diff --git a/mozilla/xpcom/string/public/nsSharableString.h b/mozilla/xpcom/string/public/nsSharableString.h
index 6dbf7a778ec..d9775112200 100644
--- a/mozilla/xpcom/string/public/nsSharableString.h
+++ b/mozilla/xpcom/string/public/nsSharableString.h
@@ -27,8 +27,8 @@
#ifndef nsSharableString_h___
#define nsSharableString_h___
-#ifndef nsTString_h___
-#include "nsTString.h"
+#ifndef nsString_h___
+#include "nsString.h"
#endif
// need to include this for compatibility
diff --git a/mozilla/xpcom/string/public/nsString.h b/mozilla/xpcom/string/public/nsString.h
index 54958ca1387..6cd1e2643ed 100644
--- a/mozilla/xpcom/string/public/nsString.h
+++ b/mozilla/xpcom/string/public/nsString.h
@@ -39,28 +39,243 @@
#ifndef nsString_h___
#define nsString_h___
-#ifndef nsTString_h___
-#include "nsTString.h"
+
+#ifndef nsStringBase_h___
+#include "nsStringBase.h"
#endif
-#ifndef nsTDependentString_h___
-#include "nsTDependentString.h"
+#ifndef nsDependentSubstring_h___
+#include "nsDependentSubstring.h"
+#endif
+
+#ifndef nsReadableUtils_h___
+#include "nsReadableUtils.h"
+#endif
+
+
+ // enable support for the obsolete string API if not explicitly disabled
+#ifndef MOZ_STRING_WITH_OBSOLETE_API
+#define MOZ_STRING_WITH_OBSOLETE_API 1
+#endif
+
+#if MOZ_STRING_WITH_OBSOLETE_API
+ // radix values for ToInteger/AppendInt
+#define kRadix10 (10)
+#define kRadix16 (16)
+#define kAutoDetect (100)
+#define kRadixUnknown (kAutoDetect+1)
+#endif
+
+class CBufDescriptor;
+
+
+ // declare nsString, et. al.
+#include "string-template-def-unichar.h"
+#include "nsTString.h"
+#include "string-template-undef.h"
+
+ // declare nsCString, et. al.
+#include "string-template-def-char.h"
+#include "nsTString.h"
+#include "string-template-undef.h"
+
+
+ /**
+ * CBufDescriptor
+ *
+ * Allows a nsC?AutoString to be configured to use a custom buffer.
+ */
+class CBufDescriptor
+ {
+ public:
+
+ CBufDescriptor(char* aString, PRBool aStackBased, PRUint32 aCapacity, PRInt32 aLength=-1)
+ {
+ mStr = aString;
+ mCapacity = aCapacity;
+ mLength = aLength;
+ mFlags = F_SINGLE_BYTE | (aStackBased ? F_STACK_BASED : 0);
+ }
+
+ CBufDescriptor(const char* aString, PRBool aStackBased, PRUint32 aCapacity, PRInt32 aLength=-1)
+ {
+ mStr = NS_CONST_CAST(char*, aString);
+ mCapacity = aCapacity;
+ mLength = aLength;
+ mFlags = F_SINGLE_BYTE | F_CONST | (aStackBased ? F_STACK_BASED : 0);
+ }
+
+ CBufDescriptor(PRUnichar* aString, PRBool aStackBased, PRUint32 aCapacity, PRInt32 aLength=-1)
+ {
+ mUStr = aString;
+ mCapacity = aCapacity;
+ mLength = aLength;
+ mFlags = F_DOUBLE_BYTE | (aStackBased ? F_STACK_BASED : 0);
+ }
+
+ CBufDescriptor(const PRUnichar* aString, PRBool aStackBased, PRUint32 aCapacity, PRInt32 aLength=-1)
+ {
+ mUStr = NS_CONST_CAST(PRUnichar*, aString);
+ mCapacity = aCapacity;
+ mLength = aLength;
+ mFlags = F_DOUBLE_BYTE | F_CONST | (aStackBased ? F_STACK_BASED : 0);
+ }
+
+ union
+ {
+ char* mStr;
+ PRUnichar* mUStr;
+ };
+
+ PRUint32 mCapacity;
+ PRInt32 mLength;
+
+ enum
+ {
+ F_CONST = (1 << 0),
+ F_STACK_BASED = (1 << 1),
+ F_SINGLE_BYTE = (1 << 2),
+ F_DOUBLE_BYTE = (1 << 3)
+ };
+
+ PRUint32 mFlags;
+ };
+
+
+ /**
+ * A helper class that converts a UTF-16 string to ASCII in a lossy manner
+ */
+class NS_LossyConvertUTF16toASCII : public nsCAutoString
+ {
+ public:
+ explicit
+ NS_LossyConvertUTF16toASCII( const PRUnichar* aString )
+ {
+ LossyAppendUTF16toASCII(aString, *this);
+ }
+
+ NS_LossyConvertUTF16toASCII( const PRUnichar* aString, PRUint32 aLength )
+ {
+ LossyCopyUTF16toASCII(nsDependentSubstring(aString, aString + aLength), *this);
+ }
+
+ explicit
+ NS_LossyConvertUTF16toASCII( const nsAString& aString )
+ {
+ LossyCopyUTF16toASCII(aString, *this);
+ }
+
+ private:
+ // NOT TO BE IMPLEMENTED
+ NS_LossyConvertUTF16toASCII( char );
+ };
+
+
+class NS_ConvertASCIItoUTF16 : public nsAutoString
+ {
+ public:
+ explicit
+ NS_ConvertASCIItoUTF16( const char* aCString )
+ {
+ AppendASCIItoUTF16(aCString, *this);
+ }
+
+ NS_ConvertASCIItoUTF16( const char* aCString, PRUint32 aLength )
+ {
+ CopyASCIItoUTF16(nsDependentCSubstring(aCString, aCString + aLength), *this);
+ }
+
+ explicit
+ NS_ConvertASCIItoUTF16( const nsACString& aCString )
+ {
+ CopyASCIItoUTF16(aCString, *this);
+ }
+
+ private:
+ // NOT TO BE IMPLEMENTED
+ NS_ConvertASCIItoUTF16( PRUnichar );
+ };
+
+
+ /**
+ * A helper class that converts a UTF-16 string to UTF-8
+ */
+class NS_ConvertUTF16toUTF8 : public nsCAutoString
+ {
+ public:
+ explicit
+ NS_ConvertUTF16toUTF8( const PRUnichar* aString )
+ {
+ CopyUTF16toUTF8(aString, *this);
+ }
+
+ NS_ConvertUTF16toUTF8( const PRUnichar* aString, PRUint32 aLength )
+ {
+ CopyUTF16toUTF8(nsDependentSubstring(aString, aString + aLength), *this);
+ }
+
+ explicit
+ NS_ConvertUTF16toUTF8( const nsAString& aString )
+ {
+ CopyUTF16toUTF8(aString, *this);
+ }
+
+ private:
+ // NOT TO BE IMPLEMENTED
+ NS_ConvertUTF16toUTF8( char );
+ };
+
+
+class NS_ConvertUTF8toUTF16 : public nsAutoString
+ {
+ public:
+ explicit
+ NS_ConvertUTF8toUTF16( const char* aCString )
+ {
+ CopyUTF8toUTF16(aCString, *this);
+ }
+
+ NS_ConvertUTF8toUTF16( const char* aCString, PRUint32 aLength )
+ {
+ CopyUTF8toUTF16(nsDependentCSubstring(aCString, aCString + aLength), *this);
+ }
+
+ explicit
+ NS_ConvertUTF8toUTF16( const nsACString& aCString )
+ {
+ CopyUTF8toUTF16(aCString, *this);
+ }
+
+ private:
+ NS_ConvertUTF8toUTF16( PRUnichar );
+ };
+
+
+// the following are included/declared for backwards compatibility
+
+typedef NS_ConvertUTF16toUTF8 NS_ConvertUCS2toUTF8;
+typedef NS_LossyConvertUTF16toASCII NS_LossyConvertUCS2toASCII;
+typedef NS_ConvertASCIItoUTF16 NS_ConvertASCIItoUCS2;
+typedef NS_ConvertUTF8toUTF16 NS_ConvertUTF8toUCS2;
+typedef nsAutoString nsVoidableString;
+
+#ifndef nsDependentString_h___
+#include "nsDependentString.h"
#endif
#ifndef nsLiteralString_h___
#include "nsLiteralString.h"
#endif
-#ifndef nsTDependentSubstring_h___
-#include "nsTDependentSubstring.h"
+#ifndef nsPromiseFlatString_h___
+#include "nsPromiseFlatString.h"
#endif
-#ifndef nsTPromiseFlatString_h___
-#include "nsTPromiseFlatString.h"
-#endif
-
-// need to include this for compatibility
+// need to include these for backwards compatibility
#include "nsMemory.h"
+#include
+#include
+#include "plhash.h"
#include NEW_H
inline PRInt32 MinInt(PRInt32 x, PRInt32 y)
diff --git a/mozilla/xpcom/string/public/nsStringBase.h b/mozilla/xpcom/string/public/nsStringBase.h
new file mode 100644
index 00000000000..513de14f16f
--- /dev/null
+++ b/mozilla/xpcom/string/public/nsStringBase.h
@@ -0,0 +1,65 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla.
+ *
+ * The Initial Developer of the Original Code is IBM Corporation.
+ * Portions created by IBM Corporation are Copyright (C) 2003
+ * IBM Corporation. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Darin Fisher
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef nsStringBase_h___
+#define nsStringBase_h___
+
+#ifndef nsAString_h___
+#include "nsAString.h"
+#endif
+
+static const PRInt32 kNotFound = -1;
+
+
+ // declare nsStringBase
+#include "string-template-def-unichar.h"
+#include "nsTStringBase.h"
+#include "string-template-undef.h"
+
+
+ // declare nsCStringBase
+#include "string-template-def-char.h"
+#include "nsTStringBase.h"
+#include "string-template-undef.h"
+
+
+#ifndef nsStringTuple_h___
+#include "nsStringTuple.h"
+#endif
+
+#endif // !defined(nsStringBase_h___)
diff --git a/mozilla/xpcom/string/public/nsStringFwd.h b/mozilla/xpcom/string/public/nsStringFwd.h
index c17748c7878..2566ab4f363 100644
--- a/mozilla/xpcom/string/public/nsStringFwd.h
+++ b/mozilla/xpcom/string/public/nsStringFwd.h
@@ -36,55 +36,56 @@
/**
- * template types:
+ * double-byte (PRUnichar) string types
*/
-template class nsTAString;
-template class nsTObsoleteAString;
-template class nsTStringBase;
-template class nsTStringTuple;
-template class nsTString;
-template class nsTAutoString;
-template class nsTDependentString;
-template class nsTDependentSubstring;
-template class nsTPromiseFlatString;
-template class nsTStringComparator;
-template class nsTDefaultStringComparator;
-template class nsTXPIDLString;
+class nsAString;
+class nsObsoleteAString;
+class nsStringBase;
+class nsStringTuple;
+class nsString;
+class nsAutoString;
+class nsDependentString;
+class nsDependentSubstring;
+class nsPromiseFlatString;
+class nsStringComparator;
+class nsDefaultStringComparator;
+class nsXPIDLString;
+
+
+ /**
+ * single-byte (char) string types
+ */
+
+class nsACString;
+class nsObsoleteACString;
+class nsCStringBase;
+class nsCStringTuple;
+class nsCString;
+class nsCAutoString;
+class nsDependentCString;
+class nsDependentCSubstring;
+class nsPromiseFlatCString;
+class nsCStringComparator;
+class nsDefaultCStringComparator;
+class nsXPIDLCString;
+
+
+ /**
+ * typedefs for backwards compatibility
+ */
+
+typedef nsString nsSharableString;
+typedef nsString nsAFlatString;
+typedef nsStringBase nsASingleFragmentString;
+typedef nsStringTuple nsDependentConcatenation;
+typedef nsDependentSubstring nsDependentSingleFragmentSubstring;
+
+typedef nsCString nsSharableCString;
+typedef nsCString nsAFlatCString;
+typedef nsCStringBase nsASingleFragmentCString;
+typedef nsCStringTuple nsDependentCConcatenation;
+typedef nsDependentCSubstring nsDependentSingleFragmentCSubstring;
- /**
- * for everything else, we typedef :-)
- */
-
-typedef nsTAString nsACString;
-typedef nsTStringBase nsASingleFragmentCString;
-typedef nsTString nsAFlatCString;
-typedef nsTStringTuple nsDependentCConcatenation;
-typedef nsTDependentSubstring nsDependentSingleFragmentCSubstring;
-typedef nsTDependentSubstring nsDependentCSubstring;
-typedef nsTDependentString nsDependentCString;
-typedef nsTPromiseFlatString nsPromiseFlatCString;
-typedef nsTString nsCString;
-typedef nsTAutoString nsCAutoString;
-typedef nsTXPIDLString nsXPIDLCString;
-typedef nsTString nsSharableCString;
-typedef nsTStringComparator nsCStringComparator;
-typedef nsTDefaultStringComparator nsDefaultCStringComparator;
-
-typedef nsTAString nsAString;
-typedef nsTStringBase nsASingleFragmentString;
-typedef nsTString nsAFlatString;
-typedef nsTStringTuple nsDependentConcatenation;
-typedef nsTDependentSubstring nsDependentSingleFragmentSubstring;
-typedef nsTDependentSubstring nsDependentSubstring;
-typedef nsTDependentString nsDependentString;
-typedef nsTPromiseFlatString nsPromiseFlatString;
-typedef nsTString nsString;
-typedef nsTAutoString nsAutoString;
-typedef nsTXPIDLString nsXPIDLString;
-typedef nsTString nsSharableString;
-typedef nsTStringComparator nsStringComparator;
-typedef nsTDefaultStringComparator nsDefaultStringComparator;
-
#endif /* !defined(nsStringFwd_h___) */
diff --git a/mozilla/xpcom/string/public/nsStringIterator.h b/mozilla/xpcom/string/public/nsStringIterator.h
index 5d3e8cea36b..7fd6c0df558 100644
--- a/mozilla/xpcom/string/public/nsStringIterator.h
+++ b/mozilla/xpcom/string/public/nsStringIterator.h
@@ -51,8 +51,10 @@ class nsReadingIterator
typedef const CharT& reference;
private:
- friend class nsTAString;
- friend class nsTStringBase;
+ friend class nsAString;
+ friend class nsACString;
+ friend class nsStringBase;
+ friend class nsCStringBase;
// unfortunately, the API for nsReadingIterator requires that the
// iterator know its start and end positions. this was needed when
@@ -187,8 +189,10 @@ class nsWritingIterator
typedef CharT& reference;
private:
- friend class nsTAString;
- friend class nsTStringBase;
+ friend class nsAString;
+ friend class nsACString;
+ friend class nsStringBase;
+ friend class nsCStringBase;
// unfortunately, the API for nsWritingIterator requires that the
// iterator know its start and end positions. this was needed when
diff --git a/mozilla/xpcom/string/public/nsStringTuple.h b/mozilla/xpcom/string/public/nsStringTuple.h
new file mode 100644
index 00000000000..94113ee890c
--- /dev/null
+++ b/mozilla/xpcom/string/public/nsStringTuple.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla.
+ *
+ * The Initial Developer of the Original Code is IBM Corporation.
+ * Portions created by IBM Corporation are Copyright (C) 2003
+ * IBM Corporation. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Darin Fisher
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef nsStringTuple_h___
+#define nsStringTuple_h___
+
+#ifndef nsStringBase_h___
+#include "nsStringBase.h"
+#endif
+
+ // declare nsStringTuple
+#include "string-template-def-unichar.h"
+#include "nsTStringTuple.h"
+#include "string-template-undef.h"
+
+ // declare nsCStringTuple
+#include "string-template-def-char.h"
+#include "nsTStringTuple.h"
+#include "string-template-undef.h"
+
+#endif // !defined(nsStringTuple_h___)
diff --git a/mozilla/xpcom/string/public/nsTAString.h b/mozilla/xpcom/string/public/nsTAString.h
index 0bcb07a1b11..a879885a082 100644
--- a/mozilla/xpcom/string/public/nsTAString.h
+++ b/mozilla/xpcom/string/public/nsTAString.h
@@ -36,55 +36,32 @@
*
* ***** END LICENSE BLOCK ***** */
-#ifndef nsTAString_h___
-#define nsTAString_h___
-
-#ifndef nsStringFwd_h___
-#include "nsStringFwd.h"
-#endif
-
-#ifndef nsStringIterator_h___
-#include "nsStringIterator.h"
-#endif
-
-#ifndef nsTObsoleteAString_h___
-#include "nsTObsoleteAString.h"
-#endif
-
/**
* The base for string comparators
*/
-template
-class NS_COM nsTStringComparator
+class NS_COM nsTStringComparator_CharT
{
public:
typedef CharT char_type;
- nsTStringComparator() {}
+ nsTStringComparator_CharT() {}
virtual int operator()( const char_type*, const char_type*, PRUint32 length ) const = 0;
virtual int operator()( char_type, char_type ) const = 0;
};
-template
-class NS_COM nsTDefaultStringComparator
- : public nsTStringComparator
+
+ /**
+ * The default string comparator (case-sensitive comparision)
+ */
+class NS_COM nsTDefaultStringComparator_CharT
+ : public nsTStringComparator_CharT
{
public:
typedef CharT char_type;
- nsTDefaultStringComparator() {}
-
- virtual int operator()( const char_type*, const char_type*, PRUint32 length ) const;
- virtual int operator()( char_type, char_type ) const;
- };
-
-class NS_COM nsCaseInsensitiveCStringComparator
- : public nsCStringComparator
- {
- public:
- typedef char char_type;
+ nsTDefaultStringComparator_CharT() {}
virtual int operator()( const char_type*, const char_type*, PRUint32 length ) const;
virtual int operator()( char_type, char_type ) const;
@@ -103,26 +80,25 @@ class NS_COM nsCaseInsensitiveCStringComparator
* other main abstract classes in the string hierarchy.
*/
-template
-class NS_COM nsTAString
+class NS_COM nsTAString_CharT
{
public:
typedef CharT char_type;
typedef nsCharTraits char_traits;
- typedef typename char_traits::incompatible_char_type incompatible_char_type;
+ typedef char_traits::incompatible_char_type incompatible_char_type;
- typedef nsTAString self_type;
- typedef nsTAString abstract_string_type;
- typedef nsTObsoleteAString obsolete_string_type;
- typedef nsTStringBase string_base_type;
- typedef nsTStringTuple string_tuple_type;
+ typedef nsTAString_CharT self_type;
+ typedef nsTAString_CharT abstract_string_type;
+ typedef nsTObsoleteAString_CharT obsolete_string_type;
+ typedef nsTStringBase_CharT string_base_type;
+ typedef nsTStringTuple_CharT string_tuple_type;
typedef nsReadingIterator const_iterator;
typedef nsWritingIterator iterator;
- typedef nsTStringComparator comparator_type;
+ typedef nsTStringComparator_CharT comparator_type;
typedef PRUint32 size_type;
typedef PRUint32 index_type;
@@ -130,7 +106,7 @@ class NS_COM nsTAString
public:
// this acts like a virtual destructor
- ~nsTAString();
+ ~nsTAString_CharT();
inline const_iterator& BeginReading( const_iterator& iter ) const
{
@@ -178,7 +154,7 @@ class NS_COM nsTAString
PRBool IsTerminated() const;
/**
- * these are contant time since nsTAString uses flat storage
+ * these are contant time since nsTAString_CharT uses flat storage
*/
char_type First() const;
char_type Last() const;
@@ -288,12 +264,13 @@ class NS_COM nsTAString
protected:
- friend class nsTStringTuple;
+ friend class nsTStringTuple_CharT;
+ // XXX still needed now that these aren't template types??
// GCC 3.2 erroneously needs these (they are subclasses!)
- friend class nsTStringBase;
- friend class nsTDependentSubstring;
- friend class nsTPromiseFlatString;
+ friend class nsTStringBase_CharT;
+ friend class nsTDependentSubstring_CharT;
+ friend class nsTPromiseFlatString_CharT;
/**
* the address of our virtual function table. required for backwards
@@ -310,10 +287,10 @@ class NS_COM nsTAString
PRUint32 mFlags;
/**
- * nsTAString must be subclassed before it can be instantiated.
+ * nsTAString_CharT must be subclassed before it can be instantiated.
*/
- nsTAString(char_type* data, size_type length, PRUint32 flags)
- : mVTable(nsTObsoleteAString::sCanonicalVTable)
+ nsTAString_CharT(char_type* data, size_type length, PRUint32 flags)
+ : mVTable(obsolete_string_type::sCanonicalVTable)
, mData(data)
, mLength(length)
, mFlags(flags)
@@ -324,8 +301,9 @@ class NS_COM nsTAString
*
* mData and mLength are intentionally left uninitialized.
*/
- nsTAString(PRUint32 flags)
- : mVTable(nsTObsoleteAString::sCanonicalVTable)
+ explicit
+ nsTAString_CharT(PRUint32 flags)
+ : mVTable(obsolete_string_type::sCanonicalVTable)
, mFlags(flags)
{}
@@ -335,8 +313,8 @@ class NS_COM nsTAString
* this is public to support automatic conversion of tuple to abstract
* string, which is necessary to support our API.
*/
- nsTAString(const string_tuple_type& tuple)
- : mVTable(nsTObsoleteAString::sCanonicalVTable)
+ nsTAString_CharT(const string_tuple_type& tuple)
+ : mVTable(obsolete_string_type::sCanonicalVTable)
, mData(nsnull)
, mLength(0)
, mFlags(0)
@@ -346,12 +324,6 @@ class NS_COM nsTAString
protected:
- //nsTAString( const self_type& readable );
- /*
- : mVTable(readable.mVTable)
- {}
- */
-
/**
* get pointer to internal string buffer (may not be null terminated).
* return length of buffer.
@@ -368,12 +340,7 @@ class NS_COM nsTAString
/**
* we can be converted to a const nsTStringBase (dependent on this)
*/
- const string_base_type ToString() const
- {
- const char_type* data;
- size_type length = GetReadableBuffer(&data);
- return string_base_type(NS_CONST_CAST(char_type*, data), length, 0);
- }
+ inline const string_base_type ToString() const;
private:
@@ -403,57 +370,42 @@ class NS_COM nsTAString
};
-template
NS_COM
-int Compare( const nsTAString& lhs, const nsTAString& rhs, const nsTStringComparator& = nsTDefaultStringComparator() );
+int Compare( const nsTAString_CharT& lhs, const nsTAString_CharT& rhs, const nsTStringComparator_CharT& = nsTDefaultStringComparator_CharT() );
-template
inline
-PRBool operator!=( const nsTAString& lhs, const nsTAString& rhs )
+PRBool operator!=( const nsTAString_CharT& lhs, const nsTAString_CharT& rhs )
{
return !lhs.Equals(rhs);
}
-template
inline
-PRBool operator< ( const nsTAString& lhs, const nsTAString& rhs )
+PRBool operator< ( const nsTAString_CharT& lhs, const nsTAString_CharT& rhs )
{
return Compare(lhs, rhs)< 0;
}
-template
inline
-PRBool operator<=( const nsTAString& lhs, const nsTAString& rhs )
+PRBool operator<=( const nsTAString_CharT& lhs, const nsTAString_CharT& rhs )
{
return Compare(lhs, rhs)<=0;
}
-template
inline
-PRBool operator==( const nsTAString& lhs, const nsTAString& rhs )
+PRBool operator==( const nsTAString_CharT& lhs, const nsTAString_CharT& rhs )
{
return lhs.Equals(rhs);
}
-template
inline
-PRBool operator>=( const nsTAString& lhs, const nsTAString& rhs )
+PRBool operator>=( const nsTAString_CharT& lhs, const nsTAString_CharT& rhs )
{
return Compare(lhs, rhs)>=0;
}
-template
inline
-PRBool operator> ( const nsTAString& lhs, const nsTAString& rhs )
+PRBool operator> ( const nsTAString_CharT& lhs, const nsTAString_CharT& rhs )
{
return Compare(lhs, rhs)> 0;
}
-
-
-#ifndef nsTStringTuple_h___
-#include "nsTStringTuple.h"
-#endif
-
-
-#endif // !defined(nsTAString_h___)
diff --git a/mozilla/xpcom/string/public/nsTDependentString.h b/mozilla/xpcom/string/public/nsTDependentString.h
index 8e3915bb2bb..9fee7153d98 100644
--- a/mozilla/xpcom/string/public/nsTDependentString.h
+++ b/mozilla/xpcom/string/public/nsTDependentString.h
@@ -36,20 +36,9 @@
*
* ***** END LICENSE BLOCK ***** */
-#ifndef nsTDependentString_h___
-#define nsTDependentString_h___
-
-#ifndef nsTString_h___
-#include "nsTString.h"
-#endif
-
-#ifndef nsDebug_h___
-#include "nsDebug.h"
-#endif
-
/**
- * nsTDependentString
+ * nsTDependentString_CharT
*
* Stores a null-terminated, immutable sequence of characters.
*
@@ -59,21 +48,20 @@
* nsTDependentString continues to reference valid memory for the
* duration of its use.
*/
-template
-class nsTDependentString : public nsTString
+class nsTDependentString_CharT : public nsTString_CharT
{
public:
- typedef CharT char_type;
+ typedef CharT char_type;
- typedef nsTDependentString self_type;
- typedef nsTString string_type;
+ typedef nsTDependentString_CharT self_type;
+ typedef nsTString_CharT string_type;
- typedef typename string_type::char_traits char_traits;
- typedef typename string_type::string_base_type string_base_type;
- typedef typename string_type::string_tuple_type string_tuple_type;
- typedef typename string_type::abstract_string_type abstract_string_type;
- typedef typename string_type::size_type size_type;
+ typedef string_type::char_traits char_traits;
+ typedef string_type::string_base_type string_base_type;
+ typedef string_type::string_tuple_type string_tuple_type;
+ typedef string_type::abstract_string_type abstract_string_type;
+ typedef string_type::size_type size_type;
public:
@@ -92,27 +80,27 @@ class nsTDependentString : public nsTString
* constructors
*/
- nsTDependentString( const char_type* start, const char_type* end )
+ nsTDependentString_CharT( const char_type* start, const char_type* end )
: string_type(NS_CONST_CAST(char_type*, start), end - start, F_TERMINATED)
{
AssertValid();
}
- nsTDependentString( const char_type* data, PRUint32 length )
+ nsTDependentString_CharT( const char_type* data, PRUint32 length )
: string_type(NS_CONST_CAST(char_type*, data), length, F_TERMINATED)
{
AssertValid();
}
explicit
- nsTDependentString( const char_type* data )
+ nsTDependentString_CharT( const char_type* data )
: string_type(NS_CONST_CAST(char_type*, data), char_traits::length(data), F_TERMINATED)
{
AssertValid();
}
explicit
- nsTDependentString( const string_base_type& str )
+ nsTDependentString_CharT( const string_base_type& str )
: string_type(NS_CONST_CAST(char_type*, str.Data()), str.Length(), F_TERMINATED)
{
AssertValid();
@@ -150,8 +138,6 @@ class nsTDependentString : public nsTString
private:
// NOT USED
- nsTDependentString( const string_tuple_type& );
- nsTDependentString( const abstract_string_type& );
+ nsTDependentString_CharT( const string_tuple_type& );
+ nsTDependentString_CharT( const abstract_string_type& );
};
-
-#endif // !defined(nsTDependentString_h___)
diff --git a/mozilla/xpcom/string/public/nsTDependentSubstring.h b/mozilla/xpcom/string/public/nsTDependentSubstring.h
index ebc0a5c05dd..9d6bd402334 100644
--- a/mozilla/xpcom/string/public/nsTDependentSubstring.h
+++ b/mozilla/xpcom/string/public/nsTDependentSubstring.h
@@ -36,30 +36,22 @@
*
* ***** END LICENSE BLOCK ***** */
-#ifndef nsTDependentSubstring_h___
-#define nsTDependentSubstring_h___
-
-#ifndef nsTStringBase_h___
-#include "nsTStringBase.h"
-#endif
-
/**
- * nsTDependentSubstring
+ * nsTDependentSubstring_CharT
*/
-template
-class nsTDependentSubstring : public nsTStringBase
+class nsTDependentSubstring_CharT : public nsTStringBase_CharT
{
public:
- typedef CharT char_type;
+ typedef CharT char_type;
- typedef nsTDependentSubstring self_type;
- typedef nsTStringBase string_base_type;
+ typedef nsTDependentSubstring_CharT self_type;
+ typedef nsTStringBase_CharT string_base_type;
- typedef typename string_base_type::abstract_string_type abstract_string_type;
- typedef typename string_base_type::const_iterator const_iterator;
- typedef typename string_base_type::size_type size_type;
+ typedef string_base_type::abstract_string_type abstract_string_type;
+ typedef string_base_type::const_iterator const_iterator;
+ typedef string_base_type::size_type size_type;
public:
@@ -69,26 +61,26 @@ class nsTDependentSubstring : public nsTStringBase
void Rebind( const char_type* start, const char_type* end )
{
NS_ASSERTION(start && end, "nsTDependentSubstring must wrap a non-NULL buffer");
- mData = start;
+ mData = NS_CONST_CAST(char_type*, start);
mLength = end - start;
}
- nsTDependentSubstring( const abstract_string_type& str, PRUint32 startPos, PRUint32 length = size_type(-1) )
+ nsTDependentSubstring_CharT( const abstract_string_type& str, PRUint32 startPos, PRUint32 length = size_type(-1) )
: string_base_type(F_NONE)
{
Rebind(str, startPos, length);
}
- nsTDependentSubstring( const string_base_type& str, PRUint32 startPos, PRUint32 length = size_type(-1) )
+ nsTDependentSubstring_CharT( const string_base_type& str, PRUint32 startPos, PRUint32 length = size_type(-1) )
: string_base_type(F_NONE)
{
Rebind(str, startPos, length);
}
- nsTDependentSubstring( const char_type* start, const char_type* end )
+ nsTDependentSubstring_CharT( const char_type* start, const char_type* end )
: string_base_type(NS_CONST_CAST(char_type*, start), end - start, F_NONE) {}
- nsTDependentSubstring( const const_iterator& start, const const_iterator& end )
+ nsTDependentSubstring_CharT( const const_iterator& start, const const_iterator& end )
: string_base_type(NS_CONST_CAST(char_type*, start.get()), end.get() - start.get(), F_NONE) {}
// auto-generated copy-constructor OK (XXX really?? what about base class copy-ctor?)
@@ -98,60 +90,58 @@ class nsTDependentSubstring : public nsTStringBase
void operator=( const self_type& ) {} // we're immutable, you can't assign into a substring
};
-template
-const nsTDependentSubstring
-Substring( const nsTAString& str, PRUint32 startPos, PRUint32 length = PRUint32(-1) )
+inline
+const nsTDependentSubstring_CharT
+Substring( const nsTAString_CharT& str, PRUint32 startPos, PRUint32 length = PRUint32(-1) )
{
- return nsTDependentSubstring(str, startPos, length);
+ return nsTDependentSubstring_CharT(str, startPos, length);
}
-template
-const nsTDependentSubstring
-Substring( const nsTStringBase& str, PRUint32 startPos, PRUint32 length = PRUint32(-1) )
+inline
+const nsTDependentSubstring_CharT
+Substring( const nsTStringBase_CharT& str, PRUint32 startPos, PRUint32 length = PRUint32(-1) )
{
- return nsTDependentSubstring(str, startPos, length);
+ return nsTDependentSubstring_CharT(str, startPos, length);
}
-template
-const nsTDependentSubstring
+inline
+const nsTDependentSubstring_CharT
Substring( const nsReadingIterator& start, const nsReadingIterator& end )
{
- return nsTDependentSubstring(start.get(), end.get());
+ return nsTDependentSubstring_CharT(start.get(), end.get());
}
-template
-const nsTDependentSubstring
+inline
+const nsTDependentSubstring_CharT
Substring( const CharT* start, const CharT* end )
{
- return nsTDependentSubstring(start, end);
+ return nsTDependentSubstring_CharT(start, end);
}
-template
-const nsTDependentSubstring
-StringHead( const nsTAString& str, PRUint32 count )
+inline
+const nsTDependentSubstring_CharT
+StringHead( const nsTAString_CharT& str, PRUint32 count )
{
- return nsTDependentSubstring(str, 0, count);
+ return nsTDependentSubstring_CharT(str, 0, count);
}
-template
-const nsTDependentSubstring
-StringHead( const nsTStringBase& str, PRUint32 count )
+inline
+const nsTDependentSubstring_CharT
+StringHead( const nsTStringBase_CharT& str, PRUint32 count )
{
- return nsTDependentSubstring(str, 0, count);
+ return nsTDependentSubstring_CharT(str, 0, count);
}
-template
-const nsTDependentSubstring
-StringTail( const nsTAString& str, PRUint32 count )
+inline
+const nsTDependentSubstring_CharT
+StringTail( const nsTAString_CharT& str, PRUint32 count )
{
- return nsTDependentSubstring(str, str.Length() - count, count);
+ return nsTDependentSubstring_CharT(str, str.Length() - count, count);
}
-template
-const nsTDependentSubstring
-StringTail( const nsTStringBase& str, PRUint32 count )
+inline
+const nsTDependentSubstring_CharT
+StringTail( const nsTStringBase_CharT& str, PRUint32 count )
{
- return nsTDependentSubstring(str, str.Length() - count, count);
+ return nsTDependentSubstring_CharT(str, str.Length() - count, count);
}
-
-#endif // !defined(nsTDependentSubstring_h___)
diff --git a/mozilla/xpcom/string/public/nsTObsoleteAString.h b/mozilla/xpcom/string/public/nsTObsoleteAString.h
index 86523ea0efb..9c93129c411 100644
--- a/mozilla/xpcom/string/public/nsTObsoleteAString.h
+++ b/mozilla/xpcom/string/public/nsTObsoleteAString.h
@@ -36,87 +36,13 @@
*
* ***** END LICENSE BLOCK ***** */
-#ifndef nsTObsoleteAString_h___
-#define nsTObsoleteAString_h___
-
-/****************************************************************************
-
- THIS FILE IS NOT FOR HUMAN CONSUMPTION. See nsAString instead.
-
- ****************************************************************************/
-
-#ifndef nsStringFwd_h___
-#include "nsStringFwd.h"
-#endif
-
-#ifndef nscore_h___
-#include "nscore.h"
-#endif
-
-
/**
- * An |nsFragmentRequest| is used to tell |GetReadableFragment| and
- * |GetWritableFragment| what to do.
- *
- * @see GetReadableFragment
- */
-enum nsFragmentRequest { kPrevFragment, kFirstFragment, kLastFragment, kNextFragment, kFragmentAt };
-
-
- /**
- * A |nsReadableFragment| provides |const| access to a contiguous hunk of
- * string of homogenous units, e.g., bytes (|char|). This doesn't mean it
- * represents a flat hunk. It could be a variable length encoding, for
- * instance UTF-8. And the fragment itself need not be zero-terminated.
- *
- * An |nsReadableFragment| is the underlying machinery that lets
- * |nsReadingIterator|s work.
- *
- * @see nsReadingIterator
- * @status FROZEN
- */
-template
-struct nsTObsoleteReadableFragment
- {
- const CharT* mStart;
- const CharT* mEnd;
- const void* mFragmentIdentifier;
-
- nsTObsoleteReadableFragment() : mStart(0), mEnd(0), mFragmentIdentifier(0) {}
- };
-
-
- /**
- * A |nsWritableFragment| provides non-|const| access to a contiguous hunk of
- * string of homogenous units, e.g., bytes (|char|). This doesn't mean it
- * represents a flat hunk. It could be a variable length encoding, for
- * instance UTF-8. And the fragment itself need not be zero-terminated.
- *
- * An |nsWritableFragment| is the underlying machinery that lets
- * |nsWritingIterator|s work.
- *
- * @see nsWritingIterator
- * @status FROZEN
- */
-template
-struct nsTObsoleteWritableFragment
- {
- CharT* mStart;
- CharT* mEnd;
- void* mFragmentIdentifier;
-
- nsTObsoleteWritableFragment() : mStart(0), mEnd(0), mFragmentIdentifier(0) {}
- };
-
-
- /**
- * nsTObsoleteAString : binary compatible with old nsAString vtable
+ * nsTObsoleteAString_CharT : binary compatible with old nsAC?String vtable
*
* @status FROZEN
*/
-template
-class NS_COM nsTObsoleteAString
+class NS_COM nsTObsoleteAString_CharT
{
public:
/**
@@ -125,27 +51,78 @@ class NS_COM nsTObsoleteAString
*/
static const void *sCanonicalVTable;
- protected:
+ /**
+ * An |nsFragmentRequest| is used to tell |GetReadableFragment| and
+ * |GetWritableFragment| what to do.
+ *
+ * @see GetReadableFragment
+ */
+ enum nsFragmentRequest { kPrevFragment, kFirstFragment, kLastFragment, kNextFragment, kFragmentAt };
- typedef CharT char_type;
+ /**
+ * A |nsReadableFragment| provides |const| access to a contiguous hunk of
+ * string of homogenous units, e.g., bytes (|char|). This doesn't mean it
+ * represents a flat hunk. It could be a variable length encoding, for
+ * instance UTF-8. And the fragment itself need not be zero-terminated.
+ *
+ * An |nsReadableFragment| is the underlying machinery that lets
+ * |nsReadingIterator|s work.
+ *
+ * @see nsReadingIterator
+ * @status FROZEN
+ */
+ struct nsReadableFragment
+ {
+ const CharT* mStart;
+ const CharT* mEnd;
+ const void* mFragmentIdentifier;
- typedef void buffer_handle_type;
- typedef void shared_buffer_handle_type;
- typedef nsTObsoleteReadableFragment const_fragment_type;
- typedef nsTObsoleteWritableFragment fragment_type;
+ nsReadableFragment() : mStart(0), mEnd(0), mFragmentIdentifier(0) {}
+ };
- typedef nsTObsoleteAString self_type;
- typedef nsTObsoleteAString obsolete_string_type;
- typedef PRUint32 size_type;
- typedef PRUint32 index_type;
+ /**
+ * A |nsWritableFragment| provides non-|const| access to a contiguous hunk of
+ * string of homogenous units, e.g., bytes (|char|). This doesn't mean it
+ * represents a flat hunk. It could be a variable length encoding, for
+ * instance UTF-8. And the fragment itself need not be zero-terminated.
+ *
+ * An |nsWritableFragment| is the underlying machinery that lets
+ * |nsWritingIterator|s work.
+ *
+ * @see nsWritingIterator
+ * @status FROZEN
+ */
+ struct nsWritableFragment
+ {
+ CharT* mStart;
+ CharT* mEnd;
+ void* mFragmentIdentifier;
+
+ nsWritableFragment() : mStart(0), mEnd(0), mFragmentIdentifier(0) {}
+ };
protected:
- friend class nsTAString;
- friend class nsTStringBase;
+ typedef CharT char_type;
- virtual ~nsTObsoleteAString() { }
+ typedef void buffer_handle_type;
+ typedef void shared_buffer_handle_type;
+ typedef nsReadableFragment const_fragment_type;
+ typedef nsWritableFragment fragment_type;
+
+ typedef nsTObsoleteAString_CharT self_type;
+ typedef nsTObsoleteAString_CharT obsolete_string_type;
+
+ typedef PRUint32 size_type;
+ typedef PRUint32 index_type;
+
+ protected:
+
+ friend class nsTAString_CharT;
+ friend class nsTStringBase_CharT;
+
+ virtual ~nsTObsoleteAString_CharT() { }
virtual PRUint32 GetImplementationFlags() const = 0;
virtual const buffer_handle_type* GetFlatBufferHandle() const = 0;
@@ -183,10 +160,5 @@ class NS_COM nsTObsoleteAString
virtual char_type* GetWritableFragment( fragment_type&, nsFragmentRequest, PRUint32 = 0 ) = 0;
};
-typedef nsTObsoleteAString nsObsoleteAString;
-typedef nsTObsoleteAString nsObsoleteACString;
-
// forward declare implementation
-template class nsTObsoleteAStringThunk;
-
-#endif // !defined(nsTObsoleteAString_h___)
+class nsTObsoleteAStringThunk_CharT;
diff --git a/mozilla/xpcom/string/public/nsTPromiseFlatString.h b/mozilla/xpcom/string/public/nsTPromiseFlatString.h
index 05cb8efd656..e0e42b2670e 100644
--- a/mozilla/xpcom/string/public/nsTPromiseFlatString.h
+++ b/mozilla/xpcom/string/public/nsTPromiseFlatString.h
@@ -36,12 +36,6 @@
*
* ***** END LICENSE BLOCK ***** */
-#ifndef nsTPromiseFlatString_h___
-#define nsTPromiseFlatString_h___
-
-#ifndef nsTString_h___
-#include "nsTString.h"
-#endif
/**
* XXX fix docs XXX
@@ -97,19 +91,18 @@
* the right thing happens.
*/
-template
-class NS_COM nsTPromiseFlatString : public nsTString
+class NS_COM nsTPromiseFlatString_CharT : public nsTString_CharT
{
public:
- typedef CharT char_type;
+ typedef CharT char_type;
- typedef nsTPromiseFlatString self_type;
- typedef nsTString string_type;
- typedef nsTStringBase string_base_type;
+ typedef nsTPromiseFlatString_CharT self_type;
+ typedef nsTString_CharT string_type;
+ typedef nsTStringBase_CharT string_base_type;
- typedef typename string_base_type::string_tuple_type string_tuple_type;
- typedef typename string_base_type::abstract_string_type abstract_string_type;
+ typedef string_base_type::string_tuple_type string_tuple_type;
+ typedef string_base_type::abstract_string_type abstract_string_type;
private:
@@ -122,21 +115,21 @@ class NS_COM nsTPromiseFlatString : public nsTString
public:
explicit
- nsTPromiseFlatString( const string_base_type& str )
+ nsTPromiseFlatString_CharT( const string_base_type& str )
: string_type()
{
Init(str);
}
explicit
- nsTPromiseFlatString( const abstract_string_type& readable )
+ nsTPromiseFlatString_CharT( const abstract_string_type& readable )
: string_type()
{
Init(readable);
}
explicit
- nsTPromiseFlatString( const string_tuple_type& tuple )
+ nsTPromiseFlatString_CharT( const string_tuple_type& tuple )
: string_type()
{
// nothing else to do here except assign the value of the tuple
@@ -144,54 +137,3 @@ class NS_COM nsTPromiseFlatString : public nsTString
Assign(tuple);
}
};
-
-
-inline
-const nsTPromiseFlatString
-PromiseFlatString( const nsTAString& str )
- {
- return nsTPromiseFlatString(str);
- }
-
- // e.g., PromiseFlatString(Substring(s))
-inline
-const nsTPromiseFlatString
-PromiseFlatString( const nsTStringBase& frag )
- {
- return nsTPromiseFlatString(frag);
- }
-
- // e.g., PromiseFlatString(a + b)
-inline
-const nsTPromiseFlatString
-PromiseFlatString( const nsTStringTuple& tuple )
- {
- return nsTPromiseFlatString(tuple);
- }
-
-
-inline
-const nsTPromiseFlatString
-PromiseFlatCString( const nsTAString& str )
- {
- return nsTPromiseFlatString(str);
- }
-
- // e.g., PromiseFlatString(Substring(s))
-inline
-const nsTPromiseFlatString
-PromiseFlatCString( const nsTStringBase