bug #69315: r=dbaron, a=ben. Remove unused experimental string files that have never been part of the build

This commit is contained in:
scc%mozilla.org 2001-02-19 01:34:34 +00:00
parent da9be4b8bb
commit 5ef8811e36
9 changed files with 0 additions and 5993 deletions

View File

@ -1,88 +0,0 @@
/*************************************************************************************
*
* DEVELOPMENT NOTES:
*
* 1. See nsStringImpl.h
*
* 2. I've used the uncommon template style of including a base type.
* The purpose is to allow callers to vary the underlying size of
* the buffer as a local optimization. It may turn out to be a
* bad idea, but for now I'm more focused on getting a workable
* autostring. Please be patient.
*
* FILE NOTES:
*
* 02.29.2000: Original files (rickg)
* 03.02.2000: Flesh out the interface to be compatible with old library (rickg)
*
*************************************************************************************/
#ifndef NS_AUTOSTRING_
#define NS_AUTOSTRING_
#include "nsStringImpl.h"
/********************************************************************
*
* This template provides the basic implementation for nsAutoString,
* nsAutoCString and so on. Note the typedefs at the bottom of this file.
*
********************************************************************/
template <class CharType, int DefaultBufferSize=32>
class nsAutoStringImpl : public nsStringImpl<CharType> {
public:
//default constructor
nsAutoStringImpl() : nsStringImpl<CharType> () {
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
mStringValue.mCapacity=DefaultBufferSize;
mStringValue.mBuffer=mInternalBuffer;
}
//copy constructor
nsAutoStringImpl(const nsAutoStringImpl& aCopy,PRInt32 aLength=-1) : nsStringImpl<CharType>() {
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
mStringValue.mCapacity=DefaultBufferSize;
mStringValue.mBuffer=mInternalBuffer;
Assign(aCopy);
}
//call this version for all ABT versions of readable strings
nsAutoStringImpl(const nsReadableString &aCopy,PRInt32 aLength=-1) : nsStringImpl<CharType> () {
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
mStringValue.mCapacity=DefaultBufferSize;
mStringValue.mBuffer=mInternalBuffer;
Assign(aCopy);
}
//call this version for ptrs to char-strings that match the internal char type
nsAutoStringImpl(const CharType* theString, PRInt32 aLength=-1) : nsStringImpl<CharType> () {
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
mStringValue.mCapacity=DefaultBufferSize;
mStringValue.mBuffer=mInternalBuffer;
Assign(theString,aLength);
}
virtual ~nsAutoStringImpl() { }
nsAutoStringImpl& operator=(const nsAutoStringImpl& aCopy) {
if(aCopy.mStringValue.mBuffer!=mStringValue.mBuffer) {
Assign(aCopy);
}
return *this;
}
nsAutoStringImpl& operator=(const CharType* aString) {
if(aCopy.mStringValue.mBuffer!=aString) {
Assign(aCopy);
}
return *this;
}
protected:
CharType mInternalBuffer[DefaultBufferSize];
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,145 +0,0 @@
/********************************************************************************************
*
* MODULES NOTES:
*
* 1. See nsStringImpl.h
* 2. I've included an mBuffer in this class data member as a fast-up implementation.
* I'll get rid of this shortly, reducing the members to only the mLength member. (rickg)
*
* FILE NOTES:
*
* 02.29.2000: Original files (rickg)
* 03.02.2000: Flesh out the interface to be compatible with old library (rickg)
*
********************************************************************************************/
#ifndef NS_IMMUTABLESTRING_
#define NS_IMMUTABLESTRING_
#include "nsStringImpl.h"
/**
* Immutable strings are intesting because their buffers get allocated
* at the same time as the actual string is allocated. (rickg)
*
**/
template <class CharType1>
class nsImmutableImpl : public nsReadableString {
public:
//construct from ptr to char* of internal type
static nsImmutableImpl* Create(const CharType1* aBuffer) {
size_t theBufSize=(aBuffer) ? stringlen(aBuffer) : 0;
nsImmutableImpl<CharType1> *result= new(theBufSize) nsImmutableImpl<CharType1>(aBuffer,theBufSize);
return result;
}
//copy construct
static nsImmutableImpl* Create(const nsImmutableImpl<CharType1>& aCopy) {
return 0;
}
//construct for all other ABT versions of readable strings
static nsImmutableImpl* Create(const nsReadableString& aCopy) {
return 0;
}
~nsImmutableImpl() {
}
//******************************************
// From the stringbasics interface...
//******************************************
virtual void* GetBuffer() {return mValue.mBuffer;}
virtual PRUint32 Length() {return mValue.mLength;}
virtual size_t GetCharSize() {return sizeof(CharType1);}
//******************************************
// Here are the accessor methods...
//******************************************
virtual nsReadableStringIterator* First() {return new nsReadableStringIterator(); }
virtual nsReadableStringIterator* Last() {return new nsReadableStringIterator(); }
virtual PRUnichar operator[](PRUint32 aOffset) {
return 0; //(*mBuffer)[aOffset];
}
/***********************************
These come from stringsearcher
***********************************/
virtual PRInt32 Find(const char* aTarget) {
return -1;
}
virtual PRInt32 FindChar(PRUnichar aChar) {
return -1;
}
//overloaded in order to free the object and the
//extra bytes for data that we allocated in new()
void operator delete(void *p, size_t aSize) {
if(p) {
nsImmutableImpl* theImmutable=static_cast<nsImmutableImpl*>(p);
size_t theBufLen=theImmutable->mValue.mLength+1;
::delete [] p;
}
}
protected:
/**
* Overloaded in order to get extra bytes for data.
* This needs to use our standard nsMemory (rickg)
*
**/
void* operator new(size_t aSize,size_t additionalBytes) {
CharType1* theBuf = ::new CharType1[aSize+additionalBytes+1];
memset(theBuf,0xff,aSize+additionalBytes+1);
return theBuf;
}
private:
nsImmutableImpl() {
}
//construct for ptr to internal char*
nsImmutableImpl(const CharType1* aBuffer,size_t aSize) {
mValue.mLength=aSize;
mValue.mBuffer=(CharType1*)this+sizeof(nsImmutableString);
strncopy(mValue.mBuffer,aBuffer,mValue.mLength+1);
}
//copy construct
nsImmutableImpl(const nsImmutableImpl<CharType1>& aString) {
}
//construct from reference to another (generic) readableString
//We can't assume very much about the readableString implementation,
//and should rely upon generics (like iterators) to do the work
nsImmutableImpl(const nsReadableString& aString) {
}
struct nsImmutableStringValue {
PRUint32 mLength; //data should follow
CharType1* mBuffer; //points to first char in data section of this object; this will soon go away
}
mValue;
};
/***********************************
Define the concrete immutables...
***********************************/
typedef nsImmutableImpl<PRUnichar> nsImmutableString;
typedef nsImmutableImpl<char> nsImmutableCString;
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,576 +0,0 @@
/*****************************************************************************************************************
*
* This template provides the basic implementation for nsString.
*
* Contributor(s):
* Rick Gessner <rickg@netscape.com>
*
* History:
*
* 02.29.2000: Original files (rickg)
* 03.02.2000: Expand the API's to be a bit more realistic (rickg):
* 1. Flesh out the interface to be compatible with old library
* 2. Enable both nsString-based interfaces and nsAReadableString interfaces
* 3. Build enough infrastructure to test nsString(s) and nsImmutableString constructions.
* 03.03.2000: Finished mapping original nsString functionality to template form (rickg)
*
*****************************************************************************************************************/
#ifndef _NS_STRING_
#define _NS_STRING_
#include "nsStringValue.h"
class NS_COM nsCString;
class NS_COM nsSubsumeStr;
/***************************************************************************
*
* This is the templatized base class from which stringvalues are derived. (rickg)
*
***************************************************************************/
struct UBufDescriptor {
UBufDescriptor(PRUnichar *aBuffer,PRUint32 aLength,PRUint32 aCapacity,PRBool aOwnsBuffer) {
mBuffer=aBuffer;
mLength=aLength;
mCapacity=aCapacity-1;
mOwnsBuffer=aOwnsBuffer;
}
PRUnichar* mBuffer;
PRUint32 mLength;
PRUint32 mCapacity;
PRBool mOwnsBuffer;
};
class NS_COM nsString {
public:
//******************************************
// Ctor's
//******************************************
nsString();
//copy constructor
nsString(const nsString& aString,PRInt32 aLength=-1);
//call this version for nsCString
nsString(const nsCString& aString,PRInt32 aLength=-1);
//call this version for prunichar*'s....
nsString(const PRUnichar* aString,PRInt32 aLength=-1) ;
//call this version for a single char of type char...
nsString(const char aChar);
//call this version for a single char of type prunichar...
nsString(const PRUnichar aChar);
//call this version for stack-based string buffers...
nsString(const nsSubsumeStr &aSubsumeString);
//call this version for stack-based string buffers...
nsString(nsSubsumeStr &aSubsumeString);
//call this version for char's....
nsString(const char* aString,PRInt32 aLength=-1) ;
//call this version for all other ABT versions of readable strings
nsString(const nsAReadableString &aString) ;
virtual ~nsString();
void Reinitialize(PRUnichar* aBuffer,PRUint32 aCapacity,PRInt32 aLength=-1);
//******************************************
// Concat operators
//******************************************
nsSubsumeStr operator+(const nsString &aString);
nsSubsumeStr operator+(const PRUnichar* aString);
nsSubsumeStr operator+(const char* aString);
nsSubsumeStr operator+(PRUnichar aChar);
//******************************************
// Assigment operators
//******************************************
nsString& operator=(const nsString& aString);
nsString& operator=(const nsCString& aString);
nsString& operator=(const nsSubsumeStr &aSubsumeString);
nsString& operator=(const PRUnichar* aString);
nsString& operator=(const char* aString);
nsString& operator=(const char aChar);
nsString& operator=(const PRUnichar aChar);
//******************************************
// Here are the simple accessor methods...
//******************************************
virtual nsresult SetLength(PRUint32 aLength) {
if(aLength>mStringValue.mLength)
SetCapacity(aLength);
Truncate(aLength);
return NS_OK;
}
virtual nsresult SetCapacity(PRUint32 aCapacity);
PRUnichar* GetUnicode() const { return mStringValue.mBuffer;}
PRUnichar operator[](PRUint32 aOffset) const {return CharAt(aOffset);}
// operator const char* const() {return mStringValue.mBuffer;}
PRUint32 Length() const {return mStringValue.mLength;}
PRUint32 Capacity() const {return mStringValue.mCapacity;}
size_t GetCharSize() const {return sizeof(char);}
PRBool IsUnicode() const {return PRBool(sizeof(PRUnichar)==sizeof(char));}
PRBool IsEmpty(void) const {return PRBool(mStringValue.mLength==0);}
PRUnichar CharAt(PRUint32 anIndex) const {
return (anIndex<mStringValue.mLength) ? mStringValue.mBuffer[anIndex] : 0;
}
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
PRUnichar First(void) const {
return CharAt(0);
}
PRUnichar Last(void) const {
return CharAt(mStringValue.mLength-1);
}
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
if (aResult) {
*aResult = sizeof(*this) + Capacity();
}
}
//******************************************
// Here are the Assignment methods,
// and other mutators...
//******************************************
virtual nsresult Truncate(PRUint32 anOffset=0);
/*
* This method assign from a stringimpl
* string at aString[anOffset].
*
* @update rickg 03.01.2000
* @param aString -- source String to be inserted into this
* @param aLength -- number of chars to be copied from aCopy
* @param aSrcOffset -- insertion position within this str
* @return this
*/
virtual nsresult Assign(const nsString& aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Assign(const PRUnichar* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Assign(const char* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
//assign from a stringValueImpl of a compatible type
virtual nsresult Assign(const nsCString& aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Assign(const nsAReadableString &aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Assign(char aChar);
virtual nsresult Assign(PRUnichar aChar);
nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {Assign(aString, aLength); return *this;}
nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {Assign(aString, aLength); return *this;}
//***************************************
// Here come the append methods...
//***************************************
/*
* This method appends a stringimpl starting at aString[aSrcOffset]
*
* @update rickg 03.01.2000
* @param aString -- source String to be inserted into this
* @param aLength -- number of chars to be copied from aCopy
* @param aSrcOffset -- insertion position within this str
* @return this
*/
virtual nsresult Append(const nsString &aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Append(const nsCString &aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Append(const PRUnichar* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Append(const char* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Append(const PRUnichar aChar) ;
virtual nsresult Append(const char aChar);
virtual nsresult Append(const nsAReadableString &aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Append(PRInt32 anInteger,PRInt32 aRadix=10);
virtual nsresult Append(float aFloat);
//***************************************
// Here come a few deletion methods...
//***************************************
nsresult Cut(PRUint32 anOffset,PRInt32 aCount);
nsresult Trim(const char* aTrimSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE,PRBool aIgnoreQuotes=PR_FALSE);
/**
* This method compresses multiple chars in a row into a single instance
* You can control whether chars are yanked from ends too.
*
* @update rickg 03.01.2000
* @param aEliminateLeading controls stripping of leading ws
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsresult CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**
* This method strips whitespace from string.
* You can control whether whitespace is yanked from
* start and end of string as well.
*
* @update rickg 03.01.2000
* @param aEliminateLeading controls stripping of leading ws
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsresult CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
//***************************************
// Here come a wad of insert methods...
//***************************************
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
* @update rickg 03.01.2000
* @param aString -- source String to be inserted into this
* @param anOffset -- insertion position within this str
* @param aCount -- number of chars to be copied from aCopy
* @return this
*/
nsresult Insert(const nsString& aString,PRUint32 anOffset=0,PRInt32 aCount=-1);
nsresult Insert(const char* aString,PRUint32 anOffset=0,PRInt32 aLength=-1);
nsresult Insert(const PRUnichar* aString,PRUint32 anOffset=0,PRInt32 aLength=-1);
nsresult Insert(char aChar,PRUint32 anOffset=0);
//*******************************************
// Here come inplace replacement methods...
//*******************************************
/**
* swaps occurence of 1 char for another
*
* @return this
*/
nsresult ReplaceChar(char anOldChar,char aNewChar);
nsresult ReplaceChar(const char* aSet,char aNewChar);
nsresult ReplaceSubstring( const nsString& aTarget,const nsString& aNewValue);
nsresult ReplaceSubstring(const char* aTarget,const char* aNewValue);
//*******************************************
// Here come the stripchar methods...
//*******************************************
/**
* This method is used to remove all occurances of the
* given character from this string.
*
* @update rickg 03.01.2000
* @param aChar -- char to be stripped
* @param anOffset -- where in this string to start stripping chars
* @return *this
*/
nsresult StripChar(PRUnichar aChar,PRUint32 anOffset=0);
nsresult StripChar(PRInt32 anInt,PRUint32 anOffset=0);
nsresult StripChars(const char* aSet,PRInt32 aLength=-1);
nsresult StripWhitespace();
//**************************************************
// Here are some methods that extract substrings...
//**************************************************
nsresult Left(nsString& aCopy,PRInt32 aCount) const;
nsresult Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
nsresult Right(nsString& aCopy,PRInt32 aCount) const;
//*******************************************
// Here come the operator+=() methods...
//*******************************************
nsString& operator+=(const nsString& aString);
nsString& operator+=(const char* aString);
nsString& operator+=(const PRUnichar* aString);
nsString& operator+=(const char aChar);
nsString& operator+=(const PRUnichar aChar);
nsString& operator+=(const int anInt);
nsString& operator+=(const nsSubsumeStr &aSubsumeString) {
//XXX NOT IMPLEMENTED
return *this;
}
/***********************************
Comparison methods...
***********************************/
PRBool operator==(const nsString& aString) const {return Equals(aString);}
PRBool operator==(const nsCString& aString) const {return Equals(aString);}
PRBool operator==(const char* aString) const {return Equals(aString);}
PRBool operator==(char* aString) const {return Equals(aString);}
PRBool operator==(const PRUnichar* aString) const {return Equals(aString);}
PRBool operator==(PRUnichar* aString) const {return Equals(aString);}
PRBool operator!=(const nsString& aString) const {return PRBool(Compare(aString)!=0);}
PRBool operator!=(const nsCString& aString) const {return PRBool(Compare(aString)!=0);}
PRBool operator!=(const char* aString) const {return PRBool(Compare(aString)!=0);}
PRBool operator!=(const PRUnichar* aString) const {return PRBool(Compare(aString)!=0);}
PRBool operator<(const nsString& aString) const {return PRBool(Compare(aString)<0);}
PRBool operator<(const nsCString& aString) const {return PRBool(Compare(aString)<0);}
PRBool operator<(const char* aString) const {return PRBool(Compare(aString)<0);}
PRBool operator<(const PRUnichar* aString) const {return PRBool(Compare(aString)<0);}
PRBool operator>(const nsString& aString) const {return PRBool(Compare(aString)>0);}
PRBool operator>(const nsCString& aString) const {return PRBool(Compare(aString)>0);}
PRBool operator>(const char* aString) const {return PRBool(Compare(aString)>0);}
PRBool operator>(const PRUnichar* aString) const {return PRBool(Compare(aString)>0);}
PRBool operator<=(const nsString& aString) const {return PRBool(Compare(aString)<=0);}
PRBool operator<=(const nsCString& aString) const {return PRBool(Compare(aString)<=0);}
PRBool operator<=(const char* aString) const {return PRBool(Compare(aString)<=0);}
PRBool operator<=(const PRUnichar* aString) const {return PRBool(Compare(aString)<=0);}
PRBool operator>=(const nsString& aString) const {return PRBool(Compare(aString)>=0);}
PRBool operator>=(const nsCString& aString) const {return PRBool(Compare(aString)>=0);}
PRBool operator>=(const char* aString) const {return PRBool(Compare(aString)>=0);}
PRBool operator>=(const PRUnichar* aString) const {return PRBool(Compare(aString)>=0);}
PRInt32 Compare(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRInt32 Compare(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const ;
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
PRBool Equals(const PRUnichar* aLHS,const PRUnichar* aRHS,PRBool aIgnoreCase=PR_FALSE) const;
PRBool EqualsIgnoreCase(const nsString &aString) const {return Equals(aString,PR_TRUE);}
PRBool EqualsIgnoreCase(const nsCString &aString) const {return Equals(aString,PR_TRUE);}
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const {return Equals(aString,PR_TRUE,aCount);}
PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const {return Equals(aString,PR_TRUE,aCount);}
PRBool EqualsIgnoreCase(const PRUnichar* aLHS, const PRUnichar* aRHS) const {return Equals(aLHS,aRHS,PR_TRUE);}
PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const {return Equals(aAtom,PR_TRUE);}
/***************************************
These are string searching methods...
***************************************/
/**
* search for given string within this string
*
* @update rickg 03.01.2000
* @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 aRepCount tells us how many iterations to make starting at the given offset
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 Find(const nsString& aTarget,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const;
PRInt32 Find(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const;
PRInt32 FindChar(char aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aRepCount=-1) const ;
PRInt32 FindCharInSet(const nsString& aString,PRUint32 anOffset=0) const;
PRInt32 FindCharInSet(const char *aString,PRUint32 anOffset=0) const;
PRInt32 FindCharInSet(const PRUnichar *aString,PRUint32 anOffset=0) const;
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const;
PRInt32 RFind(const nsCString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const;
PRInt32 RFind(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const;
PRInt32 RFindChar(char aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const;
PRInt32 RFindCharInSet(const nsString& aString,PRInt32 anOffset=-1) const ;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
/***************************************
These convert to a different type
***************************************/
static void Recycle(nsString* aString);
static nsString* CreateString(void);
nsString* ToNewString() const;
char* ToNewCString() const;
char* ToNewUTF8String() const;
PRUnichar* ToNewUnicode() const;
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
//******************************************
// Utility methods
//******************************************
PRInt32 CountChar(PRUnichar aChar);
//This will not work correctly for any unicode set other than ascii
void DebugDump(void) const;
/**
* 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* anErrorCode,PRUint32 aRadix=kAutoDetect) const;
void ToLowerCase();
void ToLowerCase(nsString &aString) const;
void ToUpperCase();
void ToUpperCase(nsString &aString) const;
protected:
nsresult Append(const nsStringValueImpl<char> &aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
nsStringValueImpl<PRUnichar> mStringValue;
friend class nsCString;
friend class nsSubsumeStr;
};
class NS_COM nsSubsumeStr : public nsString {
public:
nsSubsumeStr(nsString& aString);
nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
PRBool mOwnsBuffer;
};
/*****************************************************************
Now we declare the nsAutoString class
*****************************************************************/
class NS_COM nsAutoString : public nsString {
public:
nsAutoString();
//call this version nsAutoString derivatives...
nsAutoString(const nsAutoString& aString,PRInt32 aLength=-1);
//call this version for nsString and the autostrings
nsAutoString(const nsString& aString,PRInt32 aLength=-1);
//call this version with nsCString (start of COW)
nsAutoString(const nsCString& aString);
//call this version for char*'s....
nsAutoString(const char* aString,PRInt32 aLength=-1);
//call this version for a single char of type char...
nsAutoString(PRUnichar aChar);
nsAutoString(char aChar);
//call this version for PRUnichar*'s....
nsAutoString(const PRUnichar* aString,PRInt32 aLength=-1);
//call this version for all other ABT versions of readable strings
nsAutoString(const nsAReadableString &aString);
nsAutoString(const UBufDescriptor &aBuffer) ;
nsAutoString(const nsSubsumeStr& aSubsumeStringX) ;
virtual ~nsAutoString();
nsAutoString& operator=(const nsAutoString& aCopy);
nsAutoString& operator=(const nsString& aString);
nsAutoString& operator=(const nsCString& aString);
nsAutoString& operator=(const PRUnichar* aString);
nsAutoString& operator=(const char* aString) ;
nsAutoString& operator=(const PRUnichar aChar);
nsAutoString& operator=(const nsSubsumeStr &aSubsumeString);
protected:
PRUnichar mInternalBuffer[kDefaultStringSize+1];
};
extern NS_COM int fputs(const nsString& aString, FILE* out);
extern PRUint32 HashCode(const nsString& aDest);
extern NS_COM void Recycle( PRUnichar* aBuffer);
#endif

View File

@ -1,515 +0,0 @@
/*****************************************************************************************************************
*
* This template provides the basic implementation for all the original
* nsString classes (nsString, nsCString) and serve as the basis for
* thier autostring forms.
*
* DEVELOPMENT NOTES:
*
* 0. Note that I've explictly created interfaces for both the nsString(s),
* and for the nsReadableString (ABT). This will allow the nsString
* form to be optimized (as in the original), while the nsReadable
* interfaces can use a new, more generic approach (including iterators).
* SEE Append() as an example.
*
* 1. Flesh out more of the nsReadableString and nsReadableStringIterator interfaces.
* Note the use of the readableStringIterator in the version of Append() that
* accepts an nsReadableString&. This is because the readableString may have
* almost any form (e.g. segmentString), and we can't rely upon a linear
* layout of buffer memory as we can with nsString class deriviates.
*
* I fully expect this pattern to get replaced with a legitimate form.
*
*
* 2. I don't really think it's necessary to go crazy with virtual methods
* but I've done so for now as a matter of consistency. Once this file
* gets further along, and I have a workable nsAutoString, then I'll start
* backing off from virtual methods whereever possible. Please be patient.
*
* 3. I'm being lazy for the time being, and NOT encoding the buffer-ownership
* flag into the high-order bit of the length field. This needs to be done
* "real soon" but it's not worth doing (today) while I'm still designing.
*
* 4. I explictly implemented the orthodox canonical form.
*
* 5. Before anyone get's too critical of this design, note that I'm using
* the dual-class template form to make interoperability between char*
* and prunichar* obvious. I recognize that it's better to switch to
* an nsReadableString interface, but I've done this for now ONLY to
* make the conversion from our existing nsString class easier. Once
* I get over a few hurdles there, I'll re-examine this approach.
* Once again: please be patient (I'm only 5 hours into this effort).
*
* 6. I've quickly hooked up some of the low level routines (in the
* file nsBufferManager.h). Don't expect it all to work just yet --
* they're mostly placeholders. You CAN already construct and copy
* construct an nsString, nsCString and the autostring forms.
*
* 7. Note that the basic nsString interfaces (append, assign, etc) are not
* perfectly equivalent to the originals. All I tried to do was capture
* the gist of the originals to flesh out these interfaces.
*
* 8. Next Up: Mapping of more nsString functions (insert, delete, the
* boolean operators, the searching methods, etc.
*
* *** NOTE: I've begun to map the existing nsString functions --
* most are empty covers, to be used as a placeholder.
*
* 9. After I'm done with #8, I'll split this implementation into 2 files.
*
* FILE NOTES:
*
* 02.29.2000: Original files (rickg)
* 03.02.2000: Expand the API's to be a bit more realistic (rickg):
* 1. Flesh out the interface to be compatible with old library
* 2. Enable both nsString-based interfaces and nsReadableString interfaces
* 3. Build enough infrastructure to test nsString(s) and nsImmutableString constructions.
*
*****************************************************************************************************************/
#ifndef NS_STRINGIMPL_
#define NS_STRINGIMPL_
#include "nsStringValue.h"
#include "nsBufferManager.h"
/***************************************************************************
*
* The following is the basic interface nsString searching...
*
* We will merge this into nsReadableString very soon, but I've kept it
* seperate until I can map and factor the original nsString methods.
*
***************************************************************************/
class nsSearchableString {
public:
//We need to decide how deep (and generic) this API can go...
};
/***************************************************************************
*
* This isn't intended as a real class, but only to illustrate that for
* nsReadableString, we want a common access pattern to get at the underlying
* buffer. Iterators make perfect sense, but it will take a real implementation.
*
* Note: This class is intended to replace direct calls to GetBuffer()
* in cases where iteration on an nsReadableString is taking place.
*
***************************************************************************/
class nsReadableStringIterator {
public:
nsReadableStringIterator() { }
};
/***************************************************************************
*
* The following is the basic interface anyone who wants to be passed
* as a string should define.
*
***************************************************************************/
class nsReadableString : public nsSearchableString {
public:
virtual PRUint32 Length() =0;
virtual size_t GetCharSize() =0;
virtual PRUnichar operator[](PRUint32) = 0;
virtual nsReadableStringIterator* First() = 0; //These are here so that nsReadable strings can offer a standard mechanism for
virtual nsReadableStringIterator* Last() = 0; //callers to access underlying data. Feel free to replace with a better pattern.
//by moving to iterators, we can support segmented content models...
//virtual nsStringIterator GetIterator() = 0;
//virtual PRBool IsEmpty(void) = 0;
//etc.
};
/***************************************************************************
*
* Now the basic nsStringImpl implementation, that becomes the functional
* base for genericized strings storing a given chartype.for nsString,
nsCStirng and the autoString pairs.
*
***************************************************************************/
template <class CharType>
class nsStringImpl: public nsReadableString {
public:
nsStringImpl() : mStringValue() {
}
//call this version for nsString,nsCString and the autostrings
nsStringImpl(const nsStringImpl& aString,PRInt32 aLength=-1) : mStringValue() {
Assign(aString,aLength);
}
//call this version for nsString,nsCString and the autostrings
nsStringImpl(const CharType* aString,PRInt32 aLength=-1) : mStringValue() {
Assign(aString,aLength);
}
//call this version for all other ABT versions of readable strings
nsStringImpl(const nsReadableString &aString) : mStringValue() {
Assign(aString);
}
virtual ~nsStringImpl() { }
nsStringImpl& operator=(const nsStringImpl<CharType>& aString) {
if(aString.mStringValue.mBuffer!=mStringValue.mBuffer) {
Assign(aString);
}
return *this;
}
//******************************************
// Here are the accessor methods...
//******************************************
virtual nsresult SetLength(PRUint32 aLength) {
return NS_OK;
}
virtual nsresult SetCapacity(PRUint32 aCapacity) {
return NS_OK;
}
operator CharType*() {return mStringValue.mBuffer;}
PRUint32 Length() {return mStringValue.mLength;}
size_t GetCharSize() {return sizeof(CharType);}
PRBool IsEmpty(void) {return PRBool(mStringValue.mLength==0);}
PRUnichar operator[](PRUint32 aOffset) {return mStringValue[aOffset];}
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex) {return PR_FALSE;}
PRUnichar CharAt(PRUint32 anIndex) const {return mStringValue[aOffset];}
PRUnichar First(void) const {return mStringValue[0];}
PRUnichar Last(void) const {return mStringValue[mStringValue.mLength];}
//these aren't the real deal, but serve as a placeholder for us to implement iterators.
virtual nsReadableStringIterator* First() {return new nsReadableStringIterator(); }
virtual nsReadableStringIterator* Last() {return new nsReadableStringIterator(); }
PRInt32 CountChar(PRUnichar aChar) { return 0; }
void DebugDump(void) const { }
//******************************************
// Here are the mutation methods...
//******************************************
virtual nsresult Truncate(PRUint32 offset=0) {
if(mStringValue) {
mStringValue[0]=0;
mStringValue.mLength=0;
}
return NS_OK;
}
//assign from a stringimpl
nsresult Assign(const nsStringImpl& aString) {
nsresult result=NS_OK;
if(mStringValue.mBuffer!=aString.mStringValue.mBuffer){
Truncate();
result=Append(aString);
}
return result;
}
//assign from a compatible string pointer
virtual nsresult Assign(const CharType* aString,PRInt32 aLength=-1) {
nsresult result=NS_OK;
if(mStringValue.mBuffer!=aString){
Truncate();
result=Append(aString,aLength);
}
return result;
}
//assign from an nsReadableString (the ABT)
virtual nsresult Assign(const nsReadableString &aString,PRInt32 aLength=-1) {
nsresult result=NS_OK;
Truncate();
SVAppendReadable<CharType>(mStringValue,aString,0,aLength);
return result;
}
//append from a stringimpl
virtual nsresult Append(const nsStringImpl<CharType> &aString,PRInt32 aLength=-1) {
SVAppend< CharType, CharType > (mStringValue,aString.mStringValue,0,aString.mStringValue.mLength);
return NS_OK;
}
//append from a type compatible string pointer
virtual nsresult Append(const CharType* aString,PRInt32 aLength=-1) {
nsresult result=NS_OK;
if(aString) {
nsStringValueImpl<CharType> theStringValue(const_cast<CharType*>(aString),aLength);
SVAppend< CharType, CharType > (mStringValue,theStringValue,0,aLength);
}
return result;
}
//append from an nsReadableString (the ABT)
virtual nsresult Append(const nsReadableString &aString,PRInt32 aLength=-1) {
SVAppendReadable<CharType> (mStringValue,aString,0,aLength);
return NS_OK;
}
//append an integer
virtual nsresult Append(PRInt32 aInteger,PRInt32 aRadix=10) {
nsresult result=NS_OK;
return result;
}
//Append a float
virtual nsresult Append(float aFloat) {
nsresult result=NS_OK;
return result;
}
//***************************************
// Here come a few deletion methods...
//***************************************
nsStringImpl<CharType>& Cut(PRUint32 anOffset,PRInt32 aCount) {
return *this;
}
nsStringImpl<CharType>& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE,PRBool aIgnoreQuotes=PR_FALSE) {
return *this;
}
nsStringImpl<CharType>& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE){
return *this;
}
nsStringImpl<CharType>& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE){
return *this;
}
//***************************************
// Here come a wad of insert methods...
//***************************************
nsStringImpl<CharType>& Insert(const nsStringImpl<CharType>& aCopy,PRUint32 anOffset,PRInt32 aCount=-1) {
return *this;
}
nsStringImpl<CharType>& Insert(const CharType* aChar,PRUint32 anOffset,PRInt32 aCount=-1){
return *this;
}
nsStringImpl<CharType>& Insert(CharType aChar,PRUint32 anOffset){
return *this;
}
//*******************************************
// Here come inplace replacement methods...
//*******************************************
nsStringImpl<CharType>& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar){
return *this;
}
nsStringImpl<CharType>& ReplaceChar(const char* aSet,PRUnichar aNewChar){
return *this;
}
nsStringImpl<CharType>& ReplaceSubstring( const nsStringImpl<CharType>& aTarget,
const nsStringImpl<CharType>& aNewValue){
return *this;
}
nsStringImpl<CharType>& ReplaceSubstring(const CharType* aTarget,const CharType* aNewValue) {
return *this;
}
//*******************************************
// Here come the stripchar methods...
//*******************************************
nsStringImpl<CharType>& StripChars(const char* aSet){
return *this;
}
nsStringImpl<CharType>& StripChar(CharType aChar,PRInt32 anOffset=0){
return *this;
}
nsStringImpl<CharType>& StripChar(PRInt32 anInt,PRInt32 anOffset=0) {return StripChar((PRUnichar)anInt,anOffset); }
nsStringImpl<CharType>& StripWhitespace() {
return *this;
}
//**************************************************
// Here are some methods that extract substrings...
//**************************************************
PRUint32 Left(nsStringImpl<CharType>& aCopy,PRInt32 aCount) const {
}
PRUint32 Mid(nsStringImpl<CharType>& aCopy,PRUint32 anOffset,PRInt32 aCount) const {
}
PRUint32 Right(nsStringImpl<CharType>& aCopy,PRInt32 aCount) const {
}
//*******************************************
// Here come the operator+=() methods...
//*******************************************
nsStringImpl<CharType>& operator+=(const nsStringImpl<CharType>& aString){
Append(aString,aString.mStringValue.mLength);
return *this;
}
nsStringImpl<CharType>& operator+=(const CharType* aString) {
Append(aString);
return *this;
}
nsStringImpl<CharType>& operator+=(const CharType aChar) {
return *this;
}
nsStringImpl<CharType>& operator+=(const int anInt){
Append(anInt,10);
return *this;
}
void ToLowerCase() {
}
void ToLowerCase(nsStringImpl<CharType> &aString) const {
}
void ToUpperCase() {
}
void ToUpperCase(nsStringImpl<CharType> &aString) const {
}
/***********************************
Comparison methods...
***********************************/
PRBool operator==(const nsStringImpl<CharType>& aString) const {return Equals(aString);}
PRBool operator==(const CharType* aString) const {return Equals(aString);}
PRBool operator!=(const nsStringImpl<CharType>& aString) const {return PRBool(Compare(aString)!=0);}
PRBool operator!=(const CharType* aString) const {return PRBool(Compare(aString)!=0);}
PRBool operator<(const nsStringImpl<CharType>& aString) const {return PRBool(Compare(aString)<0);}
PRBool operator<(const CharType* aString) const {return PRBool(Compare(aString)<0);}
PRBool operator>(const nsStringImpl<CharType>& aString) const {return PRBool(Compare(aString)>0);}
PRBool operator>(const CharType* aString) const {return PRBool(Compare(aString)>0);}
PRBool operator<=(const nsStringImpl<CharType>& aString) const {return PRBool(Compare(aString)<=0);}
PRBool operator<=(const CharType* aString) const {return PRBool(Compare(aString)<=0);}
PRBool operator>=(const nsStringImpl<CharType>& aString) const {return PRBool(Compare(aString)>=0);}
PRBool operator>=(const CharType* aString) const {return PRBool(Compare(aString)>=0);}
PRInt32 Compare(const nsStringImpl<CharType>& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRInt32 Compare(const CharType* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsStringImpl<CharType> &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const CharType* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
// PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
/***************************************
These are string searching methods...
***************************************/
PRInt32 FindChar(PRUnichar aChar) {
return -1;
}
PRInt32 Find(const nsStringImpl<CharType>& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const {
return -1;
}
PRInt32 Find(const CharType* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const {
return -1;
}
PRInt32 FindCharInSet(const nsStringImpl<CharType>& aString,PRInt32 anOffset=-1) const{
return -1;
}
PRInt32 FindCharInSet(const CharType* aString,PRInt32 anOffset=-1) const{
return -1;
}
PRInt32 FindChar(CharType aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const {
return -1;
}
PRInt32 RFindChar(CharType aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const{
return -1;
}
PRInt32 RFind(const nsStringImpl<CharType>& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const{
return -1;
}
PRInt32 RFind(const CharType* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const{
return -1;
}
PRInt32 RFindCharInSet(const nsStringImpl<CharType>& aString,PRInt32 anOffset=-1) const {
return -1;
}
PRInt32 RFindCharInSet(const CharType* aString,PRInt32 anOffset=-1) const{
return -1;
}
/***************************************
These convert to a different type
***************************************/
char* ToNewCString() const {
}
char* ToNewUTF8String() const {
}
PRUnichar* ToNewUnicode() const {
}
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const {
}
float ToFloat(PRInt32* aErrorCode) const {
}
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const{
}
nsStringValueImpl<CharType> mStringValue;
};
#endif

View File

@ -1,211 +0,0 @@
!
/*************************************************************************************
*
* MODULES NOTES:
*
* 1. See nsStringImpl.h
* 2. We still have the ownership flag (bool) as a seperate data member. This will
* get merged into the length or capacity field after things stabilize a bit.
* (Likely only a few more days).
*
* Contributor(s):
* Rick Gessner <rickg@netscape.com>
*
* History: *
* 02.29.2000: Original files (rickg)
* 03.02.2000: Flesh out the interface to be compatible with old library (rickg)
*
*************************************************************************************/
#ifndef NSSTRINGVALUE_
#define NSSTRINGVALUE_
#include "nsIAtom.h"
#include "nscore.h"
#include "nsMemory.h"
#include <string.h>
#if 0
typedef int PRInt32;
typedef unsigned int PRUint32;
typedef short int PRUnichar;
typedef int nsresult;
typedef char PRBool;
#define NS_OK 0
#define NS_MEMORY_ERROR 1000
#define PR_TRUE 1
#define PR_FALSE 0
#define NS_SUCCEEDED(x) (NS_OK==x)
#endif
typedef long int _RefCountType;
static const int kRadix10=10;
static const int kRadix16=16;
static const int kAutoDetect=100;
static const int kRadixUnknown=kAutoDetect+1;
static const int kDefaultStringSize=64;
static const int kNotFound=-1;
#define IGNORE_CASE (PR_TRUE)
class nsAReadableString {
public:
virtual PRUint32 Length() const =0;
};
#define MODERN_CPP //make this false for aix/solaris...
#ifdef MODERN_CPP
#define CONST_CAST(type,arg) const_cast<type>(arg)
#else
#define CONST_CAST(type,arg) (type)arg
#endif
/***************************************************************************
*
* The following (hack) template functions will go away, but for now they
* provide basic string copying and appending for my prototype. (rickg)
*
***************************************************************************/
template <class T1,class T2>
inline PRInt32 MinInt(T1 anInt1,T2 anInt2){
return (anInt1<(T1)anInt2) ? anInt1 : anInt2;
}
template <class T1,class T2>
inline PRInt32 MaxInt(T1 anInt1,T2 anInt2){
return (anInt1<(T1)anInt2) ? anInt2 : anInt1;
}
inline size_t stringlen(const PRUnichar* theString) {
const PRUnichar* theEnd=theString;
while(*theEnd++); //skip to end of aDest...
size_t result=theEnd-theString-1;
return result;
}
inline size_t stringlen(const char* theString) {
return ::strlen(theString);
}
//----------------------------------------------------------------------------------------
/***************************************************************************
*
* This is the templatized base class from which stringvalues are derived. (rickg)
*
***************************************************************************/
template <class CharType>
struct nsStackBuffer {
nsStackBuffer(CharType *aBuffer,PRUint32 aLength,PRUint32 aCapacity) {
mBuffer=aBuffer;
mLength=aLength;
mCapacity=aCapacity;
}
CharType* mBuffer;
PRUint32 mLength;
PRUint32 mCapacity;
};
#if 0
template <class CharType>
struct RCBuffer {
void* operator new(size_t aSize) {
CharType* theBuf = ::new CharType[aSize+1+sizeof(_RefCountType)];
memset(theBuf,0xff,aSize+additionalBytes+1);
return theBuf;
}
void operator delete(void *p, size_t aSize) {
::delete [] p;
}
_RefCountType mRefCount;
CharType mBuffer[1];
};
#endif
/***************************************************************************
*
* This is the templatized base class from which stringvalues are derived. (rickg)
*
***************************************************************************/
template <class CharType>
struct nsStringValueImpl {
nsStringValueImpl() {
mBuffer=(CharType*)gCommonEmptyBuffer;
mLength=mCapacity=0;
mRefCount=2; //so we don't ever try to free the shared buffer
}
nsStringValueImpl(const nsStringValueImpl<CharType>& aCopy) {
mBuffer=aCopy.mBuffer;
mLength=aCopy.mLength;
mCapacity=aCopy.mCapacity;
mRefCount=1;
}
nsStringValueImpl(const nsStringValueImpl<CharType>& aCopy,PRInt32 aLength){
mBuffer=aCopy.mBuffer;
mLength=aLength;
mCapacity=aCopy.mCapacity;
mRefCount=1;
}
nsStringValueImpl(CharType* theString,PRInt32 aLength=-1,PRUint32 aCapacity=0) {
if(theString) {
mLength = (-1==aLength) ? stringlen(theString) : aLength;
mCapacity=(0==aCapacity) ? mLength+1 : aCapacity;
mBuffer=theString;
}
else {
mBuffer=(CharType*)gCommonEmptyBuffer;
mLength=mCapacity=0;
}
mRefCount=1;
}
nsStringValueImpl(const nsStackBuffer<CharType> &aBuffer) {
mCapacity=aBuffer.mCapacity;
mLength=aBuffer.mLength;
mBuffer=aBuffer.mBuffer;
mRefCount=2; //set it to 2 so we don't try to free it.
}
void operator=(const nsStringValueImpl<CharType>& aCopy) {
mBuffer=aCopy.mBuffer;
mLength=aCopy.mLength;
mCapacity=aCopy.mCapacity;
mRefCount=aCopy.mRefCount;
}
void* GetBuffer() {return mBuffer;}
PRUint32 GetLength() {return mLength;}
PRUint32 GetCapacity() {return mCapacity;}
size_t GetCharSize() {return sizeof(CharType);}
CharType* mBuffer;
PRUint32 mLength;
PRUint32 mCapacity;
PRUint32 mRefCount;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,525 +0,0 @@
/*****************************************************************************************************************
*
* This template provides the basic implementation for nsCString.
*
* Contributor(s):
* Rick Gessner <rickg@netscape.com>
*
* History:
*
* 02.29.2000: Original files (rickg)
* 03.02.2000: Expand the API's to be a bit more realistic (rickg):
* 1. Flesh out the interface to be compatible with old library
* 2. Enable both nsCString-based interfaces and nsAReadableString interfaces
* 3. Build enough infrastructure to test nsCString(s) and nsImmutableString constructions.
* 03.03.2000: Finished mapping original nsCString functionality to template form (rickg)
*
*****************************************************************************************************************/
#ifndef _NS_CSTRING_
#define _NS_CSTRING_
#include "nsStringValue.h"
#include "nsString2.h"
#include <stddef.h>
class NS_COM nsSubsumeCStr;
/***************************************************************************
*
* This is the templatized base class from which stringvalues are derived. (rickg)
*
***************************************************************************/
struct CBufDescriptor {
CBufDescriptor(char *aBuffer,PRUint32 aLength,PRUint32 aCapacity,PRBool aOwnsBuffer) {
mBuffer=aBuffer;
mLength=aLength;
mCapacity=aCapacity-1;
mOwnsBuffer=aOwnsBuffer;
}
char* mBuffer;
PRUint32 mLength;
PRUint32 mCapacity;
PRBool mOwnsBuffer;
};
class NS_COM nsCString {
public:
//******************************************
// Ctor's
//******************************************
nsCString();
//copy constructor
nsCString(const nsCString& aString,PRInt32 aLength=-1);
//constructor from nsString
nsCString(const nsString& aString,PRInt32 aLength=-1);
//call this version for char*'s....
nsCString(const char* aString,PRInt32 aLength=-1) ;
//call this version for a single char
nsCString(const char aChar);
//call this version for PRUnichar*'s....
nsCString(const PRUnichar* aString,PRInt32 aLength=-1) ;
//call this version for stack-based string buffers...
nsCString(const nsSubsumeCStr &aSubsumeString);
//call this version for stack-based string buffers...
nsCString(nsSubsumeCStr &aSubsumeString);
//call this version for cbufdescriptor string buffers...
nsCString(const CBufDescriptor &aSubsumeString);
//call this version for all other ABT versions of readable strings
nsCString(const nsAReadableString &aString) ;
virtual ~nsCString();
void Reinitialize(char* aBuffer,PRUint32 aCapacity,PRInt32 aLength=-1);
//******************************************
// Concat operators
//******************************************
nsSubsumeCStr operator+(const nsCString &aCString);
nsSubsumeCStr operator+(const char* aCString);
nsSubsumeCStr operator+(char aChar);
//******************************************
// Assigment operators
//******************************************
nsCString& operator=(const nsCString& aString);
nsCString& operator=(const nsString& aString);
nsCString& operator=(const char* aString);
nsCString& operator=(const PRUnichar* aString);
nsCString& operator=(const char aChar);
nsCString& operator=(const nsSubsumeCStr &aBufDescriptor);
//******************************************
// Here are the accessor methods...
//******************************************
virtual nsresult SetLength(PRUint32 aLength) {
if(aLength>mStringValue.mLength)
SetCapacity(aLength);
Truncate(aLength);
return NS_OK;
}
virtual nsresult SetCapacity(PRUint32 aCapacity);
char* GetBuffer() const { return mStringValue.mBuffer;}
char operator[](PRUint32 aOffset) const {return CharAt(aOffset);}
operator const char*() const {return (const char*)mStringValue.mBuffer;}
operator char*() const {return mStringValue.mBuffer;}
PRUint32 Length() const {return mStringValue.mLength;}
PRUint32 Capacity() const {return mStringValue.mCapacity;}
size_t GetCharSize() const {return sizeof(mStringValue.mBuffer[0]);}
PRBool IsUnicode() const {return PR_FALSE;}
PRBool IsEmpty(void) const {return PRBool(mStringValue.mLength==0);}
char CharAt(PRUint32 anIndex) const {
return (anIndex<mStringValue.mLength) ? mStringValue.mBuffer[anIndex] : 0;
}
PRBool SetCharAt(char aChar,PRUint32 anIndex);
char First(void) const {
return CharAt(0);
}
char Last(void) const {
return CharAt(mStringValue.mLength-1);
}
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
if (aResult) {
*aResult = sizeof(*this) + Capacity();
}
}
//******************************************
// Here are the Assignment methods,
// and other mutators...
//******************************************
virtual nsresult Truncate(PRUint32 anOffset=0);
/*
* This method assign from a stringimpl
* string at aString[anOffset].
*
* @update rickg 03.01.2000
* @param aString -- source String to be inserted into this
* @param aLength -- number of PRUnichars to be copied from aCopy
* @param aSrcOffset -- insertion position within this str
* @return this
*/
virtual nsresult Assign(const nsCString& aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Assign(const nsString& aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Assign(const char* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Assign(const PRUnichar* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Assign(const nsAReadableString &aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Assign(char aChar);
nsCString& SetString(const char* aString,PRInt32 aLength=-1) {Assign(aString, aLength); return *this;}
nsCString& SetString(const nsCString& aString,PRInt32 aLength=-1) {Assign(aString, aLength); return *this;}
//***************************************
// Here come the append methods...
//***************************************
/*
* This method appends a stringimpl starting at aString[aSrcOffset]
*
* @update rickg 03.01.2000
* @param aString -- source String to be inserted into this
* @param aLength -- number of PRUnichars to be copied from aCopy
* @param aSrcOffset -- insertion position within this str
* @return this
*/
virtual nsresult Append(const nsCString &aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Append(const nsString &aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Append(const char* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Append(const PRUnichar* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Append(const char aChar) ;
virtual nsresult Append(const PRUnichar aChar);
virtual nsresult Append(const nsAReadableString &aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
virtual nsresult Append(PRInt32 anInteger,PRInt32 aRadix=10);
virtual nsresult Append(float aFloat);
//***************************************
// Here come a few deletion methods...
//***************************************
nsresult Cut(PRUint32 anOffset,PRInt32 aCount);
nsresult Trim(const char* aTrimSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE,PRBool aIgnoreQuotes=PR_FALSE);
/**
* This method strips PRUnichars in given set from string.
* You can control whether PRUnichars are yanked from
* start and end of string as well.
*
* @update rickg 03.01.2000
* @param aEliminateLeading controls stripping of leading ws
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsresult CompressSet(const char* aSet, char aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
/**
* This method compresses whitespace within a string. Multiple ws in a row get compressed 1.
* You can also control whether whitespace is yanked from each end.
*
* @update rickg 03.01.2000
* @param aEliminateLeading controls stripping of leading ws
* @param aEliminateTrailing controls stripping of trailing ws
* @return this
*/
nsresult CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
//***************************************
// Here come a wad of insert methods...
//***************************************
/*
* This method inserts n PRUnichars from given string into this
* string at str[anOffset].
*
* @update rickg 03.01.2000
* @param aString -- source String to be inserted into this
* @param anOffset -- insertion position within this str
* @param aCount -- number of chars to be copied from aCopy
* @return this
*/
nsresult Insert(const nsCString& aString,PRUint32 anOffset=0,PRInt32 aCount=-1);
nsresult Insert(const char* aString,PRUint32 anOffset=0,PRInt32 aLength=-1);
nsresult Insert(char aChar,PRUint32 anOffset=0);
//*******************************************
// Here come inplace replacement methods...
//*******************************************
/**
* swaps occurence of target for another
*
* @return this
*/
nsresult ReplaceSubstring( const nsCString& aTarget,const nsCString& aNewValue);
nsresult ReplaceChar(char anOldChar, char aNewChar);
nsresult ReplaceChar(const char* aSet,char aNewPRUnichar);
nsresult ReplaceSubstring(const char* aTarget,const char* aNewValue);
//*******************************************
// Here come the stripPRUnichar methods...
//*******************************************
/**
* This method is used to remove all occurances of the
* given char(s) from this string.
*
* @update rickg 03.01.2000
* @param aChar -- PRUnichar to be stripped
* @param anOffset -- where in this string to start stripping PRUnichars
* @return *this
*/
nsresult StripChar(char aChar,PRUint32 anOffset=0);
nsresult StripChar(PRInt32 anInt,PRUint32 anOffset=0);
nsresult StripChars(const char* aSet,PRInt32 aLength=-1);
nsresult StripWhitespace();
//**************************************************
// Here are some methods that extract substrings...
//**************************************************
nsresult Left(nsCString& aCopy,PRInt32 aCount) const;
nsresult Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
nsresult Right(nsCString& aCopy,PRInt32 aCount) const;
//*******************************************
// Here come the operator+=() methods...
//*******************************************
nsCString& operator+=(const nsCString& aString);
nsCString& operator+=(const PRUnichar* aString);
nsCString& operator+=(const char* aString);
nsCString& operator+=(const PRUnichar aChar);
nsCString& operator+=(const char aChar);
nsCString& operator+=(const int anInt);
nsCString& operator+=(const nsSubsumeCStr &aBuffer);
/***********************************
Comparison methods...
***********************************/
PRBool operator==(const nsCString& aString) const {return Equals(aString);}
PRBool operator==(const PRUnichar* aString) const {return Equals(aString);}
PRBool operator==(const char* aString) const {return Equals(aString);}
PRBool operator==(char* aString) const {return Equals(aString);}
PRBool operator!=(const nsCString& aString) const {return PRBool(Compare(aString)!=0);}
PRBool operator!=(const PRUnichar* aString) const {return PRBool(Compare(aString)!=0);}
PRBool operator!=(const char* aString) const {return PRBool(Compare(aString)!=0);}
PRBool operator<(const nsCString& aString) const {return PRBool(Compare(aString)<0);}
PRBool operator<(const PRUnichar* aString) const {return PRBool(Compare(aString)<0);}
PRBool operator<(const char* aString) const {return PRBool(Compare(aString)<0);}
PRBool operator>(const nsCString& aString) const {return PRBool(Compare(aString)>0);}
PRBool operator>(const PRUnichar* aString) const {return PRBool(Compare(aString)>0);}
PRBool operator>(const char* aString) const {return PRBool(Compare(aString)>0);}
PRBool operator<=(const nsCString& aString) const {return PRBool(Compare(aString)<=0);}
PRBool operator<=(const PRUnichar* aString) const {return PRBool(Compare(aString)<=0);}
PRBool operator<=(const char* aString) const {return PRBool(Compare(aString)<=0);}
PRBool operator>=(const nsCString& aString) const {return PRBool(Compare(aString)>=0);}
PRBool operator>=(const PRUnichar* aString) const {return PRBool(Compare(aString)>=0);}
PRBool operator>=(const char* aString) const {return PRBool(Compare(aString)>=0);}
PRInt32 Compare(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const ;
PRBool Equals(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
PRBool EqualsIgnoreCase(const nsCString &aString) const {return Equals(aString,PR_TRUE);}
PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const {return Equals(aString,PR_TRUE);}
PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const;
/***************************************
These are string searching methods...
***************************************/
/**
* search for given string within this string
*
* @update rickg 03.01.2000
* @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 aRepCount tells us how many iterations to make starting at the given offset
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 Find(const nsCString& aTarget,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const;
PRInt32 Find(const nsString& aTarget,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const;
PRInt32 FindChar(char aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aRepCount=-1) const ;
PRInt32 FindCharInSet(const nsCString& aString,PRUint32 anOffset=0) const;
PRInt32 FindCharInSet(const nsString& aString,PRUint32 anOffset=0) const;
PRInt32 FindCharInSet(const char *aString,PRUint32 anOffset=0) const;
PRInt32 RFind(const nsCString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const;
PRInt32 RFind(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const;
PRInt32 RFindChar(char aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const;
PRInt32 RFindCharInSet(const nsCString& aString,PRInt32 anOffset=-1) const ;
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
/***************************************
These convert to a different type
***************************************/
static void Recycle(nsCString* aString);
static nsCString* CreateString(void);
nsCString* ToNewString() const;
char* ToNewCString() const;
char* ToNewUTF8String() const;
PRUnichar* ToNewUnicode() const;
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
//******************************************
// Utility methods
//******************************************
PRInt32 CountChar(char aChar);
//This will not work correctly for any unicode set other than ascii
void DebugDump(void) const;
/**
* 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* anErrorCode,PRUint32 aRadix=kAutoDetect) const;
void ToLowerCase();
void ToLowerCase(nsCString &aString) const;
void ToUpperCase();
void ToUpperCase(nsCString &aString) const;
protected:
nsStringValueImpl<char> mStringValue;
friend class nsString;
friend class nsSubsumeCStr;
friend class nsCAutoString;
};
/*****************************************************************
Now we declare the nsSubsumeCStr class
*****************************************************************/
class NS_COM nsSubsumeCStr : public nsCString {
public:
nsSubsumeCStr(nsCString& aString);
nsSubsumeCStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
PRBool mOwnsBuffer;
};
/*****************************************************************
Now we declare the nsCAutoString class
*****************************************************************/
class NS_COM nsCAutoString : public nsCString {
public:
nsCAutoString() ;
//call this version nsAutoString derivatives...
nsCAutoString(const nsCAutoString& aString,PRInt32 aLength=-1);
//call this version for nsCString,nsCString and the autostrings
nsCAutoString(const nsCString& aString,PRInt32 aLength=-1) ;
//call this version for char*'s....
nsCAutoString(const char* aString,PRInt32 aLength=-1);
//call this version for a single char of type char...
nsCAutoString(const char aChar) ;
//call this version for PRUnichar*'s....
nsCAutoString(const PRUnichar* aString,PRInt32 aLength=-1) ;
//call this version for all other ABT versions of readable strings
nsCAutoString(const nsAReadableString &aString);
nsCAutoString(const CBufDescriptor&aBuffer) ;
nsCAutoString(const nsSubsumeCStr& aSubsumeString) ;
virtual ~nsCAutoString() ;
nsCAutoString& operator=(const nsCAutoString& aCopy) ;
nsCAutoString& operator=(const nsCString& aString) ;
nsCAutoString& operator=(const char* aString) ;
nsCAutoString& operator=(const PRUnichar* aString) ;
nsCAutoString& operator=(const char aChar) ;
nsCAutoString& operator=(const nsSubsumeCStr &aSubsumeString);
protected:
char mInternalBuffer[kDefaultStringSize+1];
};
extern PRUint32 HashCode(const nsCString& aDest);
extern NS_COM int fputs(const nsCString& aString, FILE* out);
extern NS_COM void Recycle( char* aBuffer);
#endif