making all string construction explicit; plus (now that the DOM APIs are turned on and you can no longer build without NEW_STRING_APIS) chopping out |#ifdef|ed code

This commit is contained in:
scc%mozilla.org 2000-09-02 20:53:31 +00:00
parent 57422a219a
commit 96b9a39082
15 changed files with 93 additions and 4965 deletions

View File

@ -17,22 +17,11 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author:
* Rick Gessner <rickg@netscape.com>
*
* Contributor(s):
* Rick Gessner <rickg@netscape.com> (original author)
* Scott Collins <scc@mozilla.org>
*/
#ifndef NEW_STRING_APIS
#define NEW_STRING_APIS 1
#endif //NEW_STRING_APIS
// Need this to enable comparison profiling for a while
#ifdef OLD_STRING_APIS
#undef NEW_STRING_APIS
#endif
/***********************************************************************
MODULE NOTES:
@ -431,21 +420,6 @@ struct NS_COM nsStr {
*/
static PRUint32 HashCode(const nsStr& aDest);
#ifndef NEW_STRING_APIS
static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount) {
StrAppend(aDest, aSource, anOffset, aCount);
}
static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount) {
StrAssign(aDest, aSource, anOffset, aCount);
}
static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount) {
StrInsert(aDest, aDestOffset, aSource, aSrcOffset, aCount);
}
static PRInt32 Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) {
return StrCompare(aDest, aSource, aCount, aIgnoreCase);
}
#endif
#ifdef NS_STR_STATS
/**
* Prints an nsStr. If truncate is true, the string is only printed up to

View File

@ -70,12 +70,10 @@ nsCString::nsCString() {
Initialize(*this,eOneByte);
}
#ifdef NEW_STRING_APIS
nsCString::nsCString(const char* aCString) {
Initialize(*this,eOneByte);
Assign(aCString);
}
#endif
/**
* This constructor accepts an ascii string
@ -137,7 +135,6 @@ nsCString::~nsCString() {
Destroy(*this);
}
#ifdef NEW_STRING_APIS
const char* nsCString::GetReadableFragment( nsReadableFragment<char>& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const {
switch ( aRequest ) {
case kFirstFragment:
@ -172,7 +169,6 @@ nsCString::nsCString( const nsAReadableCString& aReadable ) {
Initialize(*this,eOneByte);
Assign(aReadable);
}
#endif
void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
if (aResult) {
@ -232,35 +228,6 @@ const char* nsCString::GetBuffer(void) const {
return mStr;
}
#ifndef NEW_STRING_APIS
/**
* Get nth character.
*/
PRUnichar nsCString::operator[](PRUint32 anIndex) const {
return GetCharAt(*this,anIndex);
}
/**
* Get nth character.
*/
PRUnichar nsCString::CharAt(PRUint32 anIndex) const {
return GetCharAt(*this,anIndex);
}
/**
* Get 1st character.
*/
PRUnichar nsCString::First(void) const{
return GetCharAt(*this,0);
}
/**
* Get last character.
*/
PRUnichar nsCString::Last(void) const{
return (char)GetCharAt(*this,mLength-1);
}
#endif // !defined(NEW_STRING_APIS)
/**
* set a char inside this string at given index
@ -281,57 +248,6 @@ PRBool nsCString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
/*********************************************************
append (operator+) METHODS....
*********************************************************/
#ifndef NEW_STRING_APIS
/**
* Create a new string by appending given string to this
* @update gess 01/04/99
* @param aString -- 2nd string to be appended
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeCStr nsCString::operator+(const nsCString& aString){
nsCString temp(*this); //make a temp string the same size as this...
nsStr::StrAppend(temp,aString,0,aString.mLength);
return nsSubsumeCStr(temp);
}
/**
* create a new string by adding this to the given buffer.
* @update gess 01/04/99
* @param aCString is a ptr to cstring to be added to this
* @return newly created subsumable string
*/
nsSubsumeCStr nsCString::operator+(const char* aCString) {
nsCString temp(*this);
temp.Append(aCString);
return nsSubsumeCStr(temp);
}
/**
* create a new string by adding this to the given char.
* @update gess 01/04/99
* @param aChar is a char to be added to this
* @return newly created subsumable string
*/
nsSubsumeCStr nsCString::operator+(PRUnichar aChar) {
nsCString temp(*this);
temp.Append(aChar);
return nsSubsumeCStr(temp);
}
/**
* create a new string by adding this to the given char.
* @update gess 01/04/99
* @param aChar is a char to be added to this
* @return newly created string
*/
nsSubsumeCStr nsCString::operator+(char aChar) {
nsCString temp(*this);
temp.Append(aChar);
return nsSubsumeCStr(temp);
}
#endif // !defined(NEW_STRING_APIS)
/**********************************************************************
Lexomorphic transforms...
@ -843,73 +759,6 @@ PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
String manipulation methods...
*********************************************************************/
#ifndef NEW_STRING_APIS
/**
* assign given nsStr (or derivative) to this one
* @update gess 01/04/99
* @param aString: string to be appended
* @return this
*/
nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
if(this!=&aString){
nsStr::Truncate(*this,0);
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
StrAssign(*this,aString,0,aCount);
}
return *this;
}
/**
* 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
*/
nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
nsStr::Truncate(*this,0);
if(aCString){
Append(aCString,aCount);
}
return *this;
}
/**
* assign given char to this string
* @update gess 01/04/99
* @param aChar: char to be assignd to this
* @return this
*/
nsCString& nsCString::Assign(char aChar) {
nsStr::Truncate(*this,0);
return Append(aChar);
}
/**
* WARNING! THIS IS A VERY SPECIAL METHOD.
* This method "steals" the contents of aSource and hands it to aDest.
* Ordinarily a copy is made, but not in this version.
* @update gess10/30/98
* @param
* @return
*/
#if defined(AIX) || defined(XP_OS2_VACPP)
nsCString& nsCString::operator=(const nsSubsumeCStr& aSubsumeString) {
nsSubsumeCStr temp(aSubsumeString); // a temp is needed for the AIX and VAC++ compiler
CSubsume(*this,temp);
#else
nsCString& nsCString::operator=(nsSubsumeCStr& aSubsumeString) {
CSubsume(*this,aSubsumeString);
#endif // AIX || XP_OS2_VACPP
return *this;
}
#endif
/**
* assign given unichar* to this string
@ -952,7 +801,6 @@ void nsCString::AssignWithConversion( const nsString& aString ) {
AssignWithConversion(aString.GetUnicode(), aString.Length());
}
#ifdef NEW_STRING_APIS
void nsCString::AssignWithConversion( const nsAReadableString& aString ) {
nsStr::Truncate(*this,0);
PRInt32 count = aString.Length();
@ -976,9 +824,7 @@ void nsCString::AssignWithConversion( const nsAReadableString& aString ) {
}
}
}
#endif
#ifdef NEW_STRING_APIS
void nsCString::AppendWithConversion( const nsAReadableString& aString ) {
PRInt32 count = aString.Length();
@ -1001,7 +847,6 @@ void nsCString::AppendWithConversion( const nsAReadableString& aString ) {
}
}
}
#endif
/**
* assign given unichar to this string
@ -1014,7 +859,6 @@ void nsCString::AssignWithConversion(PRUnichar aChar) {
AppendWithConversion(aChar);
}
#ifdef NEW_STRING_APIS
void nsCString::do_AppendFromReadable( const nsAReadableCString& aReadable )
{
if ( SameImplementation( NS_STATIC_CAST(const nsAReadableCString&, *this), aReadable) )
@ -1022,87 +866,7 @@ void nsCString::do_AppendFromReadable( const nsAReadableCString& aReadable )
else
nsAWritableCString::do_AppendFromReadable(aReadable);
}
#endif
#ifndef NEW_STRING_APIS
/**
* append given string to this string
* @update gess 01/04/99
* @param aString : string to be appended to this
* @return this
*/
nsCString& nsCString::Append(const nsCString& aString,PRInt32 aCount) {
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
StrAppend(*this,aString,0,aCount);
return *this;
}
#if 0
/**
* append given string to this string;
* @update gess 01/04/99
* @param aString : string to be appended to this
* @return this
*/
nsCString& nsCString::Append(const nsStr& aString,PRInt32 aCount) {
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
StrAppend(*this,aString,0,aCount);
return *this;
}
#endif
/**
* append given c-string to this string
* @update gess 01/04/99
* @param aString : string to be appended to this
* @param aCount: #of chars to be copied; -1 means to copy the whole thing
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
*
* @return this
*/
nsCString& nsCString::Append(const char* aCString,PRInt32 aCount) {
if(aCString){
nsStr temp;
nsStr::Initialize(temp,eOneByte);
temp.mStr=(char*)aCString;
if(0<aCount) {
temp.mLength=aCount;
}
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(0<aCount)
StrAppend(*this,temp,0,aCount);
}
return *this;
}
/**
* append given unichar to this string
* @update gess 01/04/99
* @param aChar: char to be appended to this
* @return this
*/
nsCString& nsCString::Append(char aChar) {
char buf[2]={0,0};
buf[0]=aChar;
nsStr temp;
nsStr::Initialize(temp,eOneByte);
temp.mStr=buf;
temp.mLength=1;
StrAppend(*this,temp,0,1);
return *this;
}
#endif
/**
* append given char to this string
@ -1272,7 +1036,6 @@ void nsCString::InsertWithConversion(PRUnichar aChar,PRUint32 anOffset){
StrInsert(*this,anOffset,temp,0,1);
}
#ifdef NEW_STRING_APIS
void nsCString::do_InsertFromReadable( const nsAReadableCString& aReadable, PRUint32 atPosition )
{
if ( SameImplementation( NS_STATIC_CAST(const nsAReadableCString&, *this), aReadable) )
@ -1280,99 +1043,10 @@ void nsCString::do_InsertFromReadable( const nsAReadableCString& aReadable, PRUi
else
nsAWritableCString::do_InsertFromReadable(aReadable, atPosition);
}
#endif
#ifndef NEW_STRING_APIS
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
* @update gess 4/1/98
* @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
*/
void nsCString::Insert(const nsCString& aString,PRUint32 anOffset,PRInt32 aCount) {
StrInsert(*this,anOffset,aString,0,aCount);
}
/**
* 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 aCounttells us how many chars to insert
* @return this
*/
void nsCString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount){
if(aCString){
nsStr temp;
nsStr::Initialize(temp,eOneByte);
temp.mStr=(char*)aCString;
if(0<aCount) {
temp.mLength=aCount;
// If this assertion fires, the caller is probably lying about the length of
// the passed-in string. File a bug on the caller.
#ifdef NS_DEBUG
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
if(kNotFound<len) {
NS_WARNING(kPossibleNull);
}
#endif
}
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(temp.mLength && (0<aCount)){
StrInsert(*this,anOffset,temp,0,aCount);
}
}
}
/**
* Insert a single uni-char into this string at
* a specified offset.
*
* @update gess4/22/98
* @param aChar char to be inserted into this string
* @param anOffset is insert pos in str
* @return this
*/
void nsCString::Insert(char aChar,PRUint32 anOffset){
char theBuffer[2]={0,0};
theBuffer[0]=aChar;
nsStr temp;
nsStr::Initialize(temp,eOneByte);
temp.mStr=theBuffer;
temp.mLength=1;
StrInsert(*this,anOffset,temp,0,1);
}
#endif
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
* @update gess 01/04/99
* @param anOffset -- start pos for cut operation
* @param aCount -- number of chars to be cut
* @return *this
*/
#ifndef NEW_STRING_APIS
void nsCString::Cut(PRUint32 anOffset, PRInt32 aCount) {
if(0<aCount) {
nsStr::Delete(*this,anOffset,aCount);
}
}
#endif
/**********************************************************************
Searching methods...
*********************************************************************/
@ -1676,55 +1350,6 @@ PRInt32 nsCString::CompareWithConversion(const char *aCString,PRBool aIgnoreCase
return 0;
}
#ifndef NEW_STRING_APIS
/**
* Compare given nsStr with this cstring.
*
* @param aString is an nsStr instance to be compared
* @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 nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
return nsStr::StrCompare(*this,aString,aCount,aIgnoreCase);
}
#endif
#ifndef NEW_STRING_APIS
/**
* Here come a whole bunch of operator functions that are self-explanatory...
*/
PRBool nsCString::operator==(const nsStr& S) const {return Equals(S);}
PRBool nsCString::operator==(const char* s) const {return Equals(s);}
//PRBool nsCString::operator==(const PRUnichar* s) const {return Equals(s);}
PRBool nsCString::operator!=(const nsStr& S) const {return PRBool(Compare(S)!=0);}
PRBool nsCString::operator!=(const char* s) const {return PRBool(Compare(nsCAutoString(s))!=0);}
//PRBool nsCString::operator!=(const PRUnichar* s) const {return PRBool(Compare(s)!=0);}
PRBool nsCString::operator<(const nsStr& S) const {return PRBool(Compare(S)<0);}
PRBool nsCString::operator<(const char* s) const {return PRBool(Compare(nsCAutoString(s))<0);}
//PRBool nsCString::operator<(const PRUnichar* s) const {return PRBool(Compare(s)<0);}
PRBool nsCString::operator>(const nsStr& S) const {return PRBool(Compare(S)>0);}
PRBool nsCString::operator>(const char* s) const {return PRBool(Compare(nsCAutoString(s))>0);}
//PRBool nsCString::operator>(const PRUnichar* s) const {return PRBool(Compare(s)>0);}
PRBool nsCString::operator<=(const nsStr& S) const {return PRBool(Compare(S)<=0);}
PRBool nsCString::operator<=(const char* s) const {return PRBool(Compare(nsCAutoString(s))<=0);}
//PRBool nsCString::operator<=(const PRUnichar* s) const {return PRBool(Compare(s)<=0);}
PRBool nsCString::operator>=(const nsStr& S) const {return PRBool(Compare(S)>=0);}
PRBool nsCString::operator>=(const char* s) const {return PRBool(Compare(nsCAutoString(s))>=0);}
//PRBool nsCString::operator>=(const PRUnichar* s) const {return PRBool(Compare(s)>=0);}
#endif
#ifndef NEW_STRING_APIS
PRBool nsCString::EqualsIgnoreCase(const nsStr& aString) const {
return Equals(aString,PR_TRUE);
}
#endif
PRBool nsCString::EqualsIgnoreCase(const char* aString,PRInt32 aLength) const {
return EqualsWithConversion(aString,PR_TRUE,aLength);
}
@ -1734,22 +1359,6 @@ PRBool nsCString::EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aLength) con
}
#ifndef NEW_STRING_APIS
/**
* Compare this to given string; note that we compare full strings here.
*
* @update gess 01/04/99
* @param aString is the other nsCString to be compared to
* @param aIgnoreCase tells us how to treat case
* @param aCount tells us how many chars to test; -1 implies full length
* @return TRUE if equal
*/
PRBool nsCString::Equals(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
PRInt32 theAnswer=nsStr::StrCompare(*this,aString,aCount,aIgnoreCase);
PRBool result=PRBool(0==theAnswer);
return result;
}
#endif
/**
* Compare this to given string; note that we compare full strings here.
@ -1935,7 +1544,6 @@ void nsCString::DebugDump(void) const {
//----------------------------------------------------------------------
#ifdef NEW_STRING_APIS
NS_ConvertUCS2toUTF8::NS_ConvertUCS2toUTF8( const nsAReadableString& aString )
{
nsReadingIterator<PRUnichar> start(aString.BeginReading());
@ -1947,7 +1555,6 @@ NS_ConvertUCS2toUTF8::NS_ConvertUCS2toUTF8( const nsAReadableString& aString )
start += start.size_forward();
}
}
#endif
void
NS_ConvertUCS2toUTF8::Append( const PRUnichar* aString, PRUint32 aLength )

View File

@ -17,10 +17,8 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author:
* Rick Gessner <rickg@netscape.com>
*
* Contributor(s):
* Rick Gessner <rickg@netscape.com> (original author)
* Scott Collins <scc@mozilla.org>
*/
@ -38,15 +36,6 @@
4. Subsumable strings
***********************************************************************/
#ifndef NEW_STRING_APIS
#define NEW_STRING_APIS 1
#endif //NEW_STRING_APIS
// Need this to enable comparison profiling for a while
#ifdef OLD_STRING_APIS
#undef NEW_STRING_APIS
#endif
#ifndef _nsCString_
#define _nsCString_
@ -57,45 +46,19 @@
#include "nsStr.h"
#include "nsIAtom.h"
#ifdef NEW_STRING_APIS
#include "nsAWritableString.h"
#else
#define NS_LITERAL_STRING(s) (s)
#define NS_LITERAL_CSTRING(s) (s)
#define NS_DEF_DERIVED_STRING_OPERATOR_PLUS(_StringT, _CharT)
#define NS_DEF_2_STRING_STRING_OPERATOR_PLUS(_String1T, _String2T, _CharT)
inline
char
nsLiteralChar( char c )
{
return c;
}
inline
PRUnichar
nsLiteralPRUnichar( PRUnichar c )
{
return c;
}
#endif
class NS_COM nsSubsumeCStr;
class NS_COM nsCString :
#ifdef NEW_STRING_APIS
public nsAWritableCString,
#endif
public nsStr {
#ifdef NEW_STRING_APIS
protected:
virtual const void* Implementation() const { return "nsCString"; }
virtual const char* GetReadableFragment( nsReadableFragment<char>&, nsFragmentRequest, PRUint32 ) const;
virtual char* GetWritableFragment( nsWritableFragment<char>&, nsFragmentRequest, PRUint32 );
#endif
public:
/**
@ -109,36 +72,16 @@ public:
*/
nsCString(const nsCString& aString);
#ifdef NEW_STRING_APIS
explicit nsCString( const nsAReadableCString& );
nsCString(const char*);
explicit nsCString(const char*);
nsCString(const char*, PRInt32);
#else
/**
* This constructor accepts an isolatin string
* @param aCString is a ptr to a 1-byte cstr
*/
nsCString(const char* aCString,PRInt32 aLength=-1);
/**
* This constructor accepts a unichar string
* @param aCString is a ptr to a 2-byte cstr
*/
//nsCString(const PRUnichar* aString,PRInt32 aLength=-1);
/**
* This is a copy constructor that accepts an nsStr
* @param reference to another nsCString
*/
//nsCString(const nsStr&);
#endif
/**
* This constructor takes a subsumestr
* @param reference to subsumestr
*/
nsCString(nsSubsumeCStr& aSubsumeStr);
explicit nsCString(nsSubsumeCStr& aSubsumeStr);
/**
* Destructor
@ -186,17 +129,6 @@ public:
SetLength(anIndex);
}
#ifndef NEW_STRING_APIS
/**
* Determine whether or not this string has a length of 0
*
* @return TRUE if empty.
*/
PRBool IsEmpty(void) const {
return PRBool(0==mLength);
}
#endif
/**********************************************************************
Accessor methods...
*********************************************************************/
@ -207,49 +139,8 @@ public:
*/
const char* GetBuffer(void) const;
#ifndef NEW_STRING_APIS
/**
* Get nth character.
*/
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
#endif
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
/**********************************************************************
String creation methods...
*********************************************************************/
#ifndef NEW_STRING_APIS
/**
* Create a new string by appending given string to this
* @param aString -- 2nd string to be appended
* @return new string
*/
nsSubsumeCStr operator+(const nsCString& aString);
/**
* create a new string by adding this to the given char*.
* @param aCString is a ptr to cstring to be added to this
* @return newly created string
*/
nsSubsumeCStr operator+(const char* aCString);
/**
* create a new string by adding this to the given char.
* @param aChar is a char to be added to this
* @return newly created string
*/
nsSubsumeCStr operator+(PRUnichar aChar);
nsSubsumeCStr operator+(char aChar);
#endif
/**********************************************************************
Lexomorphic transforms...
*********************************************************************/
@ -419,50 +310,16 @@ public:
*/
nsCString& operator=( const nsCString& aString ) { Assign(aString); return *this; }
#ifdef NEW_STRING_APIS
nsCString& operator=( const nsAReadableCString& aReadable ) { Assign(aReadable); return *this; }
nsCString& operator=( const nsPromiseReadable<char>& aReadable ) { Assign(aReadable); return *this; }
nsCString& operator=( const char* aPtr ) { Assign(aPtr); return *this; }
nsCString& operator=( char aChar ) { Assign(aChar); return *this; }
#endif
void AssignWithConversion(const PRUnichar*,PRInt32=-1);
void AssignWithConversion( const nsString& aString );
#ifdef NEW_STRING_APIS
void AssignWithConversion( const nsAReadableString& aString );
#endif
void AssignWithConversion(PRUnichar);
#ifndef NEW_STRING_APIS
nsCString& Assign(const char* aString,PRInt32 aCount=-1);
nsCString& Assign(char aChar);
nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1);
//nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1) { AssignWithConversion(aString, aCount); return *this; }
//nsCString& Assign(PRUnichar aChar) { AssignWithConversion(aChar); return *this; }
/**
* here come a bunch of assignment operators...
* @param aString: string to be added to this
* @return this
*/
//nsCString& operator=(PRUnichar aChar) {AssignWithConversion(aChar); return *this;}
nsCString& operator=(char aChar) {return Assign(aChar);}
//nsCString& operator=(const PRUnichar* aString) {AssignWithConversion(aString); return *this;}
//nsCString& operator=(const nsStr& aString) {return Assign(aString);}
nsCString& operator=(const char* aCString) {return Assign(aCString);}
// Yes, I know this makes assignment from a |nsSubsumeString| not do the special thing
// |nsSubsumeString| needs to go away
#if defined(AIX) || defined(XP_OS2_VACPP)
nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX and VAC++ requires a const here
#else
nsCString& operator=(nsSubsumeCStr& aSubsumeString);
#endif
#endif
/*
* Appends n characters from given string to this,
*
@ -475,42 +332,13 @@ public:
void AppendWithConversion(const nsString&, PRInt32=-1);
void AppendWithConversion(PRUnichar aChar);
#ifdef NEW_STRING_APIS
void AppendWithConversion( const nsAReadableString& aString );
#endif
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 );
#ifdef NEW_STRING_APIS
virtual void do_AppendFromReadable( const nsAReadableCString& );
#endif
#ifndef NEW_STRING_APIS
//nsCString& Append(const nsStr& aString,PRInt32 aCount=-1);
nsCString& Append(const nsCString& aString,PRInt32 aCount);
nsCString& Append(const nsCString& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsCString& Append(const char* aString,PRInt32 aCount=-1);
nsCString& Append(char aChar);
//nsCString& Append(PRUnichar aChar) {AppendWithConversion(aChar); return *this;}
//nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10) {AppendInt(aInteger,aRadix); return *this;}
//nsCString& Append(float aFloat) {AppendFloat(aFloat); return *this;}
/**
* Here's a bunch of methods that append varying types...
* @param various...
* @return this
*/
nsCString& operator+=(const nsCString& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsCString& operator+=(const char* aCString) {return Append(aCString);}
//nsCString& operator+=(const PRUnichar aChar) {return Append(aChar);}
nsCString& operator+=(const char aChar) {return Append(aChar);}
//nsCString& operator+=(const int anInt) {return Append(anInt,10);}
#endif
/*
* Copies n characters from this string to given string,
* starting at the leftmost offset.
@ -548,57 +376,7 @@ public:
void InsertWithConversion(PRUnichar aChar,PRUint32 anOffset);
// Why no |InsertWithConversion(PRUnichar*)|?
#ifdef NEW_STRING_APIS
virtual void do_InsertFromReadable( const nsAReadableCString&, PRUint32 );
#endif
#ifndef NEW_STRING_APIS
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
* @param aCopy -- String to be inserted into this
* @param anOffset -- insertion position within this str
* @param aCount -- number of chars to be copied from aCopy
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
*
* @return number of chars inserted into this.
*/
void Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
/**
* Insert a given string into this string at
* a specified offset.
*
* @param aString* to be inserted into this string
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
void Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
/**
* Insert a single char into this string at
* a specified offset.
*
* @param character to be inserted into this string
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
//void Insert(PRUnichar aChar,PRUint32 anOffset) {InsertWithConversion(aChar,anOffset);}
void Insert(char aChar,PRUint32 anOffset);
#endif
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
* @param anOffset -- start pos for cut operation
* @param aCount -- number of chars to be cut
* @return *this
*/
#ifndef NEW_STRING_APIS
void Cut(PRUint32 anOffset,PRInt32 aCount);
#endif
/**********************************************************************
@ -699,96 +477,6 @@ public:
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const;
#ifndef NEW_STRING_APIS
//virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return CompareWithConversion(aString,aIgnoreCase,aCount);
//}
//virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return CompareWithConversion(aString,aIgnoreCase,aCount);
//}
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
/**
* Compare this to given string; note that we compare full strings here.
* The optional length argument just lets us know how long the given string is.
* If you provide a length, it is compared to length of this string as an
* optimization.
*
* @param aString -- the string to compare to this
* @param aCount -- number of chars in given string you want to compare
* @return TRUE if equal
*/
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
return EqualsWithConversion(aString,aIgnoreCase,aCount);
}
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
return EqualsWithConversion(aString,aIgnoreCase,aCount);
}
//PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return EqualsWithConversion(aString,aIgnoreCase,aCount);
//}
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const nsStr& aString) const;
/**
* These methods compare a given string type to this one
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char* aString) const;
//PRBool operator==(const PRUnichar* aString) const;
/**
* These methods perform a !compare of a given string type to this
* @param aString is the string to be compared to this
* @return TRUE
*/
PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const;
//PRBool operator!=(const PRUnichar* aString) const;
/**
* These methods test if a given string is < than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const;
//PRBool operator<(const PRUnichar* aString) const;
/**
* These methods test if a given string is > than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const;
//PRBool operator>(const PRUnichar* aString) const;
/**
* These methods test if a given string is <= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const;
//PRBool operator<=(const PRUnichar* aString) const;
/**
* These methods test if a given string is >= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const;
//PRBool operator>=(const PRUnichar* aString) const;
#endif // !defined(NEW_STRING_APIS)
void DebugDump(void) const;
@ -799,28 +487,14 @@ public:
private:
// NOT TO BE IMPLEMENTED
// these signatures help clients not accidentally call the wrong thing helped by C++ automatic integral promotion
#ifdef NEW_STRING_APIS
void operator=( PRUnichar );
#endif
void AssignWithConversion( char );
void AssignWithConversion( const char*, PRInt32=-1 );
void AppendWithConversion( char );
void InsertWithConversion( char, PRUint32 );
};
#if 0 // #ifdef NEW_STRING_APIS
inline
nsPromiseConcatenation<char>
operator+( const nsPromiseConcatenation<char>& lhs, const nsCString& rhs )
{
return nsPromiseConcatenation<char>(lhs, rhs);
}
#endif
#ifdef NEW_STRING_APIS
NS_DEF_STRING_COMPARISON_OPERATORS(nsCString, char)
// NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsCString, char);
#endif
extern NS_COM int fputs(const nsCString& aString, FILE* out);
//ostream& operator<<(ostream& aStream,const nsCString& aString);
@ -839,27 +513,20 @@ public:
virtual ~nsCAutoString();
nsCAutoString();
nsCAutoString(const nsCString& );
nsCAutoString(const nsAReadableCString& aString);
nsCAutoString(const char* aString);
explicit nsCAutoString(const nsCString& );
explicit nsCAutoString(const nsAReadableCString& aString);
explicit nsCAutoString(const char* aString);
nsCAutoString(const char* aString,PRInt32 aLength);
nsCAutoString(const CBufDescriptor& aBuffer);
#ifndef NEW_STRING_APIS
// nsCAutoString(const PRUnichar* aString,PRInt32 aLength=-1);
// nsCAutoString(const nsStr& aString);
// nsCAutoString(PRUnichar aChar);
#endif
explicit nsCAutoString(const CBufDescriptor& aBuffer);
#if defined(AIX) || defined(XP_OS2_VACPP)
nsCAutoString(const nsSubsumeCStr& aSubsumeStr); // AIX and VAC++ require a const
explicit nsCAutoString(const nsSubsumeCStr& aSubsumeStr); // AIX and VAC++ require a const
#else
nsCAutoString(nsSubsumeCStr& aSubsumeStr);
explicit nsCAutoString(nsSubsumeCStr& aSubsumeStr);
#endif // AIX || XP_OS2_VACPP
nsCAutoString& operator=( const nsCAutoString& aString ) { Assign(aString); return *this; }
#ifdef NEW_STRING_APIS
private:
void operator=( PRUnichar ); // NOT TO BE IMPLEMENTED
public:
@ -867,13 +534,6 @@ public:
nsCAutoString& operator=( const nsPromiseReadable<char>& aReadable ) { Assign(aReadable); return *this; }
nsCAutoString& operator=( const char* aPtr ) { Assign(aPtr); return *this; }
nsCAutoString& operator=( char aChar ) { Assign(aChar); return *this; }
#else
nsCAutoString& operator=(const nsCString& aString) {nsCString::Assign(aString); return *this;}
nsCAutoString& operator=(const char* aCString) {nsCString::Assign(aCString); return *this;}
// nsCAutoString& operator=(const PRUnichar* aString) {nsCString::Assign(aString); return *this;}
// nsCAutoString& operator=(PRUnichar aChar) {nsCString::Assign(aChar); return *this;}
nsCAutoString& operator=(char aChar) {nsCString::Assign(aChar); return *this;}
#endif
/**
* Retrieve the size of this string
@ -884,14 +544,6 @@ public:
char mBuffer[kDefaultStringSize];
};
#if 0//def NEW_STRING_APIS
NS_DEF_STRING_COMPARISON_OPERATORS(nsCAutoString, char)
#endif
#ifdef NEW_STRING_APIS
NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsCAutoString, char)
#endif
/**
* A helper class that converts a UCS2 string to UTF8
*/
@ -902,6 +554,7 @@ class NS_COM NS_ConvertUCS2toUTF8
*/
{
public:
explicit
NS_ConvertUCS2toUTF8( const PRUnichar* aString )
{
Append( aString, ~PRUint32(0) /* MAXINT */);
@ -912,14 +565,13 @@ class NS_COM NS_ConvertUCS2toUTF8
Append( aString, aLength );
}
explicit
NS_ConvertUCS2toUTF8( PRUnichar aChar )
{
Append( &aChar, 1 );
}
#ifdef NEW_STRING_APIS
NS_ConvertUCS2toUTF8( const nsAReadableString& aString );
#endif
explicit NS_ConvertUCS2toUTF8( const nsAReadableString& aString );
operator const char*() const
{
@ -950,19 +602,17 @@ class NS_COM NS_ConvertUCS2toUTF8
***************************************************************/
class NS_COM nsSubsumeCStr : public nsCString {
public:
nsSubsumeCStr(nsStr& aString);
explicit nsSubsumeCStr(nsStr& aString);
nsSubsumeCStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
nsSubsumeCStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
nsSubsumeCStr& operator=( const nsSubsumeCStr& aString ) { Assign(aString); return *this; }
#ifdef NEW_STRING_APIS
nsSubsumeCStr& operator=( const nsAReadableCString& aReadable ) { Assign(aReadable); return *this; }
nsSubsumeCStr& operator=( const nsPromiseReadable<char>& aReadable ) { Assign(aReadable); return *this; }
nsSubsumeCStr& operator=( const char* aPtr ) { Assign(aPtr); return *this; }
nsSubsumeCStr& operator=( char aChar ) { Assign(aChar); return *this; }
private:
void operator=( PRUnichar ); // NOT TO BE IMPLEMENTED
#endif
};

View File

@ -17,10 +17,8 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author:
* Rick Gessner <rickg@netscape.com>
*
* Contributor(s):
* Rick Gessner <rickg@netscape.com> (original author)
* Scott Collins <scc@mozilla.org>
*/
@ -69,25 +67,10 @@ nsString::nsString() {
Initialize(*this,eTwoByte);
}
#if 0
/**
* 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
*/
nsString::nsString(const char* aCString,PRInt32 aCount){
Initialize(*this,eTwoByte);
AssignWithConversion(aCString,aCount);
}
#endif
#ifdef NEW_STRING_APIS
nsString::nsString(const PRUnichar* aString) {
Initialize(*this,eTwoByte);
Assign(aString);
}
#endif
/**
* This constructor accepts a unicode string
@ -100,18 +83,6 @@ nsString::nsString(const PRUnichar* aString,PRInt32 aCount) {
Assign(aString,aCount);
}
#if 0
/**
* This constructor works for all other nsSTr derivatives
* @update gess 1/4/99
* @param reference to another nsCString
*/
nsString::nsString(const nsStr &aString) {
Initialize(*this,eTwoByte);
StrAssign(*this,aString,0,aString.mLength);
}
#endif
/**
* This is our copy constructor
* @update gess 1/4/99
@ -149,7 +120,6 @@ nsString::~nsString() {
nsStr::Destroy(*this);
}
#ifdef NEW_STRING_APIS
const PRUnichar* nsString::GetReadableFragment( nsReadableFragment<PRUnichar>& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const {
switch ( aRequest ) {
case kFirstFragment:
@ -199,7 +169,6 @@ nsString::nsString( const nsAReadableString& aReadable ) {
Initialize(*this,eTwoByte);
Assign(aReadable);
}
#endif
void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
if (aResult) {
@ -275,36 +244,6 @@ const PRUnichar* nsString::GetUnicode(void) const {
return result;
}
#ifndef NEW_STRING_APIS
/**
* Get nth character.
*/
PRUnichar nsString::operator[](PRUint32 anIndex) const {
return GetCharAt(*this,anIndex);
}
/**
* Get nth character.
*/
PRUnichar nsString::CharAt(PRUint32 anIndex) const {
return GetCharAt(*this,anIndex);
}
/**
* Get 1st character.
*/
PRUnichar nsString::First(void) const{
return GetCharAt(*this,0);
}
/**
* Get last character.
*/
PRUnichar nsString::Last(void) const{
return GetCharAt(*this,mLength-1);
}
#endif // !defined(NEW_STRING_APIS)
/**
* set a char inside this string at given index
* @param aChar is the char you want to write into this string
@ -330,81 +269,6 @@ PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
append (operator+) METHODS....
*********************************************************/
#ifndef NEW_STRING_APIS
/**
* Create a new string by appending given string to this
* @update gess 01/04/99
* @param aString -- 2nd string to be appended
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(const nsStr& aString){
nsString temp(*this); //make a temp string the same size as this...
nsStr::StrAppend(temp,aString,0,aString.mLength);
return nsSubsumeStr(temp);
}
/**
* Create a new string by appending given string to this
* @update gess 01/04/99
* @param aString -- 2nd string to be appended
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(const nsString& aString){
nsString temp(*this); //make a temp string the same size as this...
nsStr::StrAppend(temp,aString,0,aString.mLength);
return nsSubsumeStr(temp);
}
/**
* create a new string by adding this to the given buffer.
* @update gess 01/04/99
* @param aCString is a ptr to cstring to be added to this
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(const char* aCString) {
nsString temp(*this);
temp.AppendWithConversion(aCString);
return nsSubsumeStr(temp);
}
/**
* create a new string by adding this to the given char.
* @update gess 01/04/99
* @param aChar is a char to be added to this
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(char aChar) {
nsString temp(*this);
temp.Append(char(aChar));
return nsSubsumeStr(temp);
}
/**
* create a new string by adding this to the given buffer.
* @update gess 01/04/99
* @param aString is a ptr to unistring to be added to this
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(const PRUnichar* aString) {
nsString temp(*this);
temp.Append(aString);
return nsSubsumeStr(temp);
}
/**
* create a new string by adding this to the given char.
* @update gess 01/04/99
* @param aChar is a unichar to be added to this
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(PRUnichar aChar) {
nsString temp(*this);
temp.Append(char(aChar));
return nsSubsumeStr(temp);
}
#endif // !defined(NEW_STRING_APIS)
/**********************************************************************
Lexomorphic transforms...
@ -952,26 +816,6 @@ PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
*********************************************************************/
#ifndef NEW_STRING_APIS
/**
* assign given nsStr (or derivative) to this one
* @update gess 01/04/99
* @param aString: nsStr to be appended
* @return this
*/
nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
if(this!=&aString){
nsStr::Truncate(*this,0);
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
StrAssign(*this,aString,0,aCount);
}
return *this;
}
#endif
/**
* assign given char* to this string
@ -989,33 +833,13 @@ void nsString::AssignWithConversion(const char* aCString,PRInt32 aCount) {
}
}
#ifdef NEW_STRING_APIS
void nsString::AssignWithConversion(const char* aCString) {
nsStr::Truncate(*this,0);
if(aCString){
AppendWithConversion(aCString);
}
}
#endif
#ifndef NEW_STRING_APIS
/**
* assign given unichar* to this string
* @update gess 01/04/99
* @param aString: 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
*/
nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
nsStr::Truncate(*this,0);
if(aString){
Append(aString,aCount);
}
return *this;
}
#endif
/**
* assign given char to this string
@ -1028,39 +852,6 @@ void nsString::AssignWithConversion(char aChar) {
AppendWithConversion(aChar);
}
#ifndef NEW_STRING_APIS
/**
* assign given unichar to this string
* @update gess 01/04/99
* @param aChar: char to be assignd to this
* @return this
*/
nsString& nsString::Assign(PRUnichar aChar) {
nsStr::Truncate(*this,0);
return Append(aChar);
}
#endif
#ifndef NEW_STRING_APIS
/**
* WARNING! THIS IS A VERY SPECIAL METHOD.
* This method "steals" the contents of aSource and hands it to aDest.
* Ordinarily a copy is made, but not in this version.
* @update gess10/30/98
* @param
* @return
*/
#if defined(AIX) || defined(XP_OS2_VACPP)
nsString& nsString::operator=(const nsSubsumeStr& aSubsumeString) {
nsSubsumeStr temp(aSubsumeString); // a temp is needed for the AIX and VAC++ compilers
Subsume(*this,temp);
#else
nsString& nsString::operator=(nsSubsumeStr& aSubsumeString) {
Subsume(*this,aSubsumeString);
#endif // AIX || XP_OS2_VACPP
return *this;
}
#endif
/**
* append given c-string to this string
@ -1169,96 +960,6 @@ void nsString::AppendFloat(double aFloat){
}
#ifndef NEW_STRING_APIS
/**
* append given string to this string;
* @update gess 01/04/99
* @param aString : string to be appended to this
* @return this
*/
#if 0
nsString& nsString::Append(const nsStr& aString,PRInt32 aCount) {
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
StrAppend(*this,aString,0,aCount);
return *this;
}
#endif
/**
* append given string to this string
* I don't think we need this method now that we have the previous one.
* @update gess 01/04/99
* @param aString : string to be appended to this
* @return this
*/
nsString& nsString::Append(const nsString& aString,PRInt32 aCount) {
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
StrAppend(*this,aString,0,aCount);
return *this;
}
/**
* append given unicode string to this
* @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
*/
nsString& nsString::Append(const PRUnichar* aString,PRInt32 aCount) {
if(aString && aCount){ //if astring is null or count==0 there's nothing to do
nsStr temp;
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=(PRUnichar*)aString;
if(0<aCount) {
temp.mLength=aCount;
// If this assertion fires, the caller is probably lying about the length of
// the passed-in string. File a bug on the caller.
#ifdef NS_DEBUG
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
if(kNotFound<len) {
NS_WARNING(kPossibleNull);
}
#endif
}
else aCount=temp.mLength=nsCRT::strlen(aString);
if(0<aCount)
StrAppend(*this,temp,0,aCount);
}
return *this;
}
/**
* append given unichar to this string
* @update gess 01/04/99
* @param aChar: char to be appended to this
* @return this
*/
nsString& nsString::Append(PRUnichar aChar) {
PRUnichar buf[2]={0,0};
buf[0]=aChar;
nsStr temp;
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=buf;
temp.mLength=1;
StrAppend(*this,temp,0,1);
return *this;
}
#endif
/*
* Copies n characters from this left of this string to given string,
@ -1349,98 +1050,8 @@ void nsString::InsertWithConversion(const char* aCString,PRUint32 anOffset,PRInt
}
}
#ifndef NEW_STRING_APIS
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
* @update gess 4/1/98
* @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
*/
void nsString::Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) {
StrInsert(*this,anOffset,aCopy,0,aCount);
}
/**
* Insert a unicode* into this string at a specified offset.
*
* @update gess4/22/98
* @param aChar char to be inserted into this string
* @param anOffset is insert pos in str
* @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::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aCount){
if(aString && aCount){
nsStr temp;
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=(PRUnichar*)aString;
if(0<aCount) {
temp.mLength=aCount;
// If this assertion fires, the caller is probably lying about the length of
// the passed-in string. File a bug on the caller.
#ifdef NS_DEBUG
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
if(kNotFound<len) {
NS_WARNING(kPossibleNull);
}
#endif
}
else aCount=temp.mLength=nsCRT::strlen(aString);
if(0<aCount){
StrInsert(*this,anOffset,temp,0,aCount);
}
}
}
/**
* Insert a single uni-char into this string at
* a specified offset.
*
* @update gess4/22/98
* @param aChar char to be inserted into this string
* @param anOffset is insert pos in str
* @return this
*/
void nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
PRUnichar theBuffer[2]={0,0};
theBuffer[0]=aChar;
nsStr temp;
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=theBuffer;
temp.mLength=1;
StrInsert(*this,anOffset,temp,0,1);
}
#endif
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
* @update gess 01/04/99
* @param anOffset -- start pos for cut operation
* @param aCount -- number of chars to be cut
* @return *this
*/
#ifndef NEW_STRING_APIS
void nsString::Cut(PRUint32 anOffset, PRInt32 aCount) {
if(0<aCount) {
nsStr::Delete(*this,anOffset,aCount);
}
}
#endif
/**********************************************************************
Searching methods...
*********************************************************************/
@ -1823,55 +1434,7 @@ PRInt32 nsString::CompareWithConversion(const PRUnichar* aString,PRBool aIgnoreC
return 0;
}
#ifndef NEW_STRING_APIS
/**
* Compare given nsStr with this cstring.
*
* @param aString is an nsStr instance to be compared
* @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::Compare(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
return nsStr::StrCompare(*this,aString,aCount,aIgnoreCase);
}
#endif
#ifndef NEW_STRING_APIS
/**
* Here come a whole bunch of operator functions that are self-explanatory...
*/
PRBool nsString::operator==(const nsString& S) const {return Equals(S);}
//PRBool nsString::operator==(const nsStr& S) const {return Equals(S);}
//PRBool nsString::operator==(const char* s) const {return Equals(s);}
PRBool nsString::operator==(const PRUnichar* s) const {return Equals(nsAutoString(s));}
PRBool nsString::operator!=(const nsString& S) const {return PRBool(Compare(S)!=0);}
//PRBool nsString::operator!=(const nsStr& S) const {return PRBool(Compare(S)!=0);}
//PRBool nsString::operator!=(const char* s) const {return PRBool(Compare(s)!=0);}
PRBool nsString::operator!=(const PRUnichar* s) const {return PRBool(Compare(nsAutoString(s))!=0);}
PRBool nsString::operator<(const nsString& S) const {return PRBool(Compare(S)<0);}
//PRBool nsString::operator<(const nsStr& S) const {return PRBool(Compare(S)<0);}
//PRBool nsString::operator<(const char* s) const {return PRBool(Compare(s)<0);}
PRBool nsString::operator<(const PRUnichar* s) const {return PRBool(Compare(nsAutoString(s))<0);}
PRBool nsString::operator>(const nsString& S) const {return PRBool(Compare(S)>0);}
//PRBool nsString::operator>(const nsStr& S) const {return PRBool(Compare(S)>0);}
//PRBool nsString::operator>(const char* s) const {return PRBool(Compare(s)>0);}
PRBool nsString::operator>(const PRUnichar* s) const {return PRBool(Compare(nsAutoString(s))>0);}
PRBool nsString::operator<=(const nsString& S) const {return PRBool(Compare(S)<=0);}
//PRBool nsString::operator<=(const nsStr& S) const {return PRBool(Compare(S)<=0);}
//PRBool nsString::operator<=(const char* s) const {return PRBool(Compare(s)<=0);}
PRBool nsString::operator<=(const PRUnichar* s) const {return PRBool(Compare(nsAutoString(s))<=0);}
PRBool nsString::operator>=(const nsString& S) const {return PRBool(Compare(S)>=0);}
//PRBool nsString::operator>=(const nsStr& S) const {return PRBool(Compare(S)>=0);}
//PRBool nsString::operator>=(const char* s) const {return PRBool(Compare(s)>=0);}
PRBool nsString::operator>=(const PRUnichar* s) const {return PRBool(Compare(nsAutoString(s))>=0);}
#endif // !defined(NEW_STRING_APIS)
PRBool nsString::EqualsIgnoreCase(const nsString& aString) const {
return EqualsWithConversion(aString,PR_TRUE);
@ -1881,12 +1444,6 @@ PRBool nsString::EqualsIgnoreCase(const char* aString,PRInt32 aLength) const {
return EqualsWithConversion(aString,PR_TRUE,aLength);
}
#ifndef NEW_STRING_APIS
PRBool nsString::EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const {
return Equals(s1,s2,PR_TRUE);
}
#endif
/**
* Compare this to given string; note that we compare full strings here.
*
@ -1963,40 +1520,6 @@ PRBool nsString::EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const {
return EqualsAtom(aAtom,PR_TRUE);
}
#ifndef NEW_STRING_APIS
/**
* Compare this to given string; note that we compare full strings here.
*
* @update gess 01/04/99
* @param aString is the other nsString to be compared to
* @param aCount tells us how many chars to test; -1 implies full length
* @return TRUE if equal
*/
PRBool nsString::Equals(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
PRInt32 theAnswer=nsStr::StrCompare(*this,aString,aCount,aIgnoreCase);
PRBool result=PRBool(0==theAnswer);
return result;
}
/**
* Compare given strings
* @update gess 7/27/98
* @param s1 -- first unichar string to be compared
* @param s2 -- second unichar string to be compared
* @return TRUE if equal
*/
PRBool nsString::Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase) const {
NS_ASSERTION(0!=s1,kNullPointerError);
NS_ASSERTION(0!=s2,kNullPointerError);
PRBool result=PR_FALSE;
if((s1) && (s2)){
PRInt32 cmp=(aIgnoreCase) ? nsCRT::strcasecmp(s1,s2) : nsCRT::strcmp(s1,s2);
result=PRBool(0==cmp);
}
return result;
}
#endif
/**
* Determine if given char in valid alpha range
@ -2321,21 +1844,6 @@ NS_ConvertASCIItoUCS2::NS_ConvertASCIItoUCS2( char aChar )
AppendWithConversion(aChar);
}
#if 0
#ifdef NEW_STRING_APIS
NS_ConvertASCIItoUCS2::NS_ConvertASCIItoUCS2( const nsAReadableCString& )
{
// ...
}
#else
NS_ConvertASCIItoUCS2::NS_ConvertASCIItoUCS2( const nsCString& )
{
// ...
}
#endif
#endif
void
NS_ConvertUTF8toUCS2::Init( const char* aCString, PRUint32 aLength )
{

View File

@ -17,10 +17,8 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author:
* Rick Gessner <rickg@netscape.com>
*
* Contributor(s):
* Rick Gessner <rickg@netscape.com> (original author)
* Scott Collins <scc@mozilla.org>
*/
@ -39,16 +37,6 @@
4. Subsumable strings
***********************************************************************/
#ifndef NEW_STRING_APIS
#define NEW_STRING_APIS 1
#endif //NEW_STRING_APIS
// Need this to enable comparison profiling for a while
#ifdef OLD_STRING_APIS
#undef NEW_STRING_APIS
#endif
#ifndef _nsString_
#define _nsString_
@ -60,9 +48,7 @@
#include "nsStr.h"
#include "nsCRT.h"
#ifdef NEW_STRING_APIS
#include "nsAWritableString.h"
#endif
#ifdef STANDALONE_MI_STRING_TESTS
class nsAReadableString { public: virtual ~nsAReadableString() { } };
@ -78,17 +64,13 @@ class nsISizeOfHandler;
class NS_COM nsSubsumeStr;
class NS_COM nsString :
#if defined(NEW_STRING_APIS) || defined(STANDALONE_MI_STRING_TESTS)
public nsAWritableString,
#endif
public nsStr {
#ifdef NEW_STRING_APIS
protected:
virtual const void* Implementation() const { return "nsString"; }
virtual const PRUnichar* GetReadableFragment( nsReadableFragment<PRUnichar>&, nsFragmentRequest, PRUint32 ) const;
virtual PRUnichar* GetWritableFragment( nsWritableFragment<PRUnichar>&, nsFragmentRequest, PRUint32 );
#endif
public:
@ -103,30 +85,10 @@ public:
*/
nsString(const nsString& aString);
#ifdef NEW_STRING_APIS
explicit nsString(const nsAReadableString&);
nsString(const PRUnichar*);
explicit nsString(const PRUnichar*);
nsString(const PRUnichar*, PRInt32);
#else
/**
* This constructor accepts a unichar string
* @param aCString is a ptr to a 2-byte cstr
*/
nsString(const PRUnichar* aString,PRInt32 aCount=-1);
/**
* This constructor accepts an isolatin string
* @param aCString is a ptr to a 1-byte cstr
*/
//nsString(const char* aCString,PRInt32 aCount=-1);
/**
* This is a copy constructor that accepts an nsStr
* @param reference to another nsString
*/
//nsString(const nsStr&);
#endif
/**
@ -134,9 +96,9 @@ public:
* @param reference to subsumestr
*/
#if defined(AIX) || defined(XP_OS2_VACPP)
nsString(const nsSubsumeStr& aSubsumeStr); // AIX and VAC++ require a const here
explicit nsString(const nsSubsumeStr& aSubsumeStr); // AIX and VAC++ require a const here
#else
nsString(nsSubsumeStr& aSubsumeStr);
explicit nsString(nsSubsumeStr& aSubsumeStr);
#endif
/**
@ -198,17 +160,6 @@ public:
return result;
}
#ifndef NEW_STRING_APIS
/**
* Determine whether or not this string has a length of 0
*
* @return TRUE if empty.
*/
PRBool IsEmpty(void) const {
return PRBool(0==mLength);
}
#endif
/**********************************************************************
Getters/Setters...
*********************************************************************/
@ -219,63 +170,12 @@ public:
const char* GetBuffer(void) const;
const PRUnichar* GetUnicode(void) const;
#ifndef NEW_STRING_APIS
/**
* Get nth character.
*/
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
#endif // !defined(NEW_STRING_APIS)
/**
* Set nth character.
*/
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
#ifndef NEW_STRING_APIS
/**********************************************************************
String concatenation methods...
*********************************************************************/
/**
* Create a new string by appending given string to this
* @param aString -- 2nd string to be appended
* @return new subsumable string
*/
nsSubsumeStr operator+(const nsStr& aString);
nsSubsumeStr operator+(const nsString& aString);
/**
* create a new string by adding this to the given cstring
* @param aCString is a ptr to cstring to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(const char* aCString);
/**
* create a new string by adding this to the given prunichar*.
* @param aString is a ptr to UC-string to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(const PRUnichar* aString);
/**
* create a new string by adding this to the given char.
* @param aChar is a char to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(char aChar);
/**
* create a new string by adding this to the given char.
* @param aChar is a unichar to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(PRUnichar aChar);
#endif
/**********************************************************************
Lexomorphic transforms...
@ -449,47 +349,14 @@ public:
*/
nsString& operator=( const nsString& aString ) { Assign(aString); return *this; }
#ifdef NEW_STRING_APIS
nsString& operator=( const nsAReadableString& aReadable ) { Assign(aReadable); return *this; }
nsString& operator=( const nsPromiseReadable<PRUnichar>& aReadable ) { Assign(aReadable); return *this; }
nsString& operator=( const PRUnichar* aPtr ) { Assign(aPtr); return *this; }
nsString& operator=( PRUnichar aChar ) { Assign(aChar); return *this; }
#endif
void AssignWithConversion(char);
#ifdef NEW_STRING_APIS
void AssignWithConversion(const char*);
void AssignWithConversion(const char*, PRInt32);
#else
void AssignWithConversion(const char*, PRInt32=-1);
nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Assign(PRUnichar aChar);
nsString& Assign(const nsStr& aString,PRInt32 aCount=-1);
//nsString& Assign(const char* aString,PRInt32 aCount=-1) { AssignWithConversion(aString, aCount); return *this; }
//nsString& Assign(char aChar) { AssignWithConversion(aChar); return *this; }
/**
* here come a bunch of assignment operators...
* @param aString: string to be added to this
* @return this
*/
nsString& operator=(PRUnichar aChar) {Assign(aChar); return *this;}
//nsString& operator=(char aChar) {AssignWithConversion(aChar); return *this;}
//nsString& operator=(const char* aCString) {AssignWithConversion(aCString); return *this;}
//nsString& operator=(const nsStr& aString) {return Assign(aString);}
nsString& operator=(const PRUnichar* aString) {return Assign(aString);}
// Yes, I know this makes assignment from a |nsSubsumeString| not do the special thing
// |nsSubsumeString| needs to go away
#if defined(AIX) || defined(XP_OS2_VACPP)
nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX and VAC++ requires a const here
#else
nsString& operator=(nsSubsumeStr& aSubsumeString);
#endif
#endif
/*
@ -507,42 +374,6 @@ public:
virtual void do_AppendFromElement( PRUnichar );
#ifndef NEW_STRING_APIS
/*
* 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
*/
//nsString& Append(const nsStr& aString,PRInt32 aCount);
//nsString& Append(const nsStr& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsString& Append(const nsString& aString,PRInt32 aCount);
nsString& Append(const nsString& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Append(PRUnichar aChar);
//nsString& Append(const char* aString,PRInt32 aCount=-1) { AppendWithConversion(aString,aCount); return *this; }
//nsString& Append(char aChar) { AppendWithConversion(aChar); return *this; }
//nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10) { AppendInt(aInteger,aRadix); return *this; }
//nsString& Append(float aFloat) { AppendFloat(aFloat); return *this; }
/**
* Here's a bunch of methods that append varying types...
* @param various...
* @return this
*/
//nsString& operator+=(const char* aCString) {return Append(aCString);}
//nsString& operator+=(const char aChar) {return Append((PRUnichar) (unsigned char)aChar);}
nsString& operator+=(const PRUnichar aChar) {return Append(aChar);}
//nsString& operator+=(const int anInt) {return Append(anInt,10);}
//nsString& operator+=(const nsStr& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsString& operator+=(const nsString& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);}
#endif
/*
* Copies n characters from this string to given string,
@ -581,55 +412,6 @@ public:
//void InsertWithConversion(char);
void InsertWithConversion(const char*, PRUint32, PRInt32=-1);
#ifndef NEW_STRING_APIS
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
* @param aCopy -- String to be inserted into this
* @param anOffset -- insertion position within this str
* @param aCount -- number of chars to be copied from aCopy
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
*
* @return number of chars inserted into this.
*/
void Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
/**
* Insert a given string into this string at
* a specified offset.
*
* @param aString* to be inserted into this string
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
//nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1) {InsertWithConversion(aChar, anOffset, aCount); return *this;}
void Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
/**
* Insert a single char into this string at
* a specified offset.
*
* @param character to be inserted into this string
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
//nsString& Insert(char aChar,PRUint32 anOffset) {InsertWithConversion(aChar,anOffset); return *this;}
void Insert(PRUnichar aChar,PRUint32 anOffset);
#endif
#ifndef NEW_STRING_APIS
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
* @param anOffset -- start pos for cut operation
* @param aCount -- number of chars to be cut
* @return *this
*/
void Cut(PRUint32 anOffset,PRInt32 aCount);
#endif
/**********************************************************************
@ -739,110 +521,6 @@ public:
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const;
#ifndef NEW_STRING_APIS
//virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return CompareWithConversion(aString,aIgnoreCase,aCount);
//}
//virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return CompareWithConversion(aString,aIgnoreCase,aCount);
//}
//virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return CompareWithConversion(aString,aIgnoreCase,aCount);
//}
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
/**
* Compare this to given string; note that we compare full strings here.
* The optional length argument just lets us know how long the given string is.
* If you provide a length, it is compared to length of this string as an
* optimization.
*
* @param aString -- the string to compare to this
* @param aCount -- number of chars to be compared.
* @return TRUE if equal
*/
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
return EqualsWithConversion(aString,aIgnoreCase,aCount);
}
//PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return EqualsWithConversion(aString,aIgnoreCase,aCount);
//}
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
return EqualsWithConversion(aString,aIgnoreCase,aCount);
}
//PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const { return EqualsAtom(anAtom, aIgnoreCase); }
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
/**
* These methods compare a given string type to this one
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator==(const nsString &aString) const;
//PRBool operator==(const nsStr &aString) const;
//PRBool operator==(const char *aString) const;
PRBool operator==(const PRUnichar* aString) const;
/**
* These methods perform a !compare of a given string type to this
* @param aString is the string to be compared to this
* @return TRUE
*/
PRBool operator!=(const nsString &aString) const;
//PRBool operator!=(const nsStr &aString) const;
//PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const;
/**
* These methods test if a given string is < than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<(const nsString &aString) const;
//PRBool operator<(const nsStr &aString) const;
//PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const;
/**
* These methods test if a given string is > than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>(const nsString &aString) const;
//PRBool operator>(const nsStr &S) const;
//PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const;
/**
* These methods test if a given string is <= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<=(const nsString &aString) const;
//PRBool operator<=(const nsStr &S) const;
//PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const;
/**
* These methods test if a given string is >= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>=(const nsString &aString) const;
//PRBool operator>=(const nsStr &S) const;
//PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const;
#endif // !defined(NEW_STRING_APIS)
/**
* Determine if given buffer is plain ascii
@ -884,9 +562,7 @@ public:
private:
// NOT TO BE IMPLEMENTED
// these signatures help clients not accidentally call the wrong thing helped by C++ automatic integral promotion
#ifdef NEW_STRING_APIS
void operator=( char );
#endif
void AssignWithConversion( PRUnichar );
void AssignWithConversion( const PRUnichar*, PRInt32=-1 );
void AppendWithConversion( PRUnichar );
@ -894,19 +570,7 @@ private:
void InsertWithConversion( const PRUnichar*, PRUint32, PRInt32=-1 );
};
#ifdef NEW_STRING_APIS
NS_DEF_STRING_COMPARISON_OPERATORS(nsString, PRUnichar)
// NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsString, PRUnichar)
#endif
#if 0 // #ifdef NEW_STRING_APIS
inline
nsPromiseConcatenation<PRUnichar>
operator+( const nsPromiseConcatenation<PRUnichar>& lhs, const nsString& rhs )
{
return nsPromiseConcatenation<PRUnichar>(lhs, rhs);
}
#endif
extern NS_COM int fputs(const nsString& aString, FILE* out);
//ostream& operator<<(ostream& aStream,const nsString& aString);
@ -924,27 +588,21 @@ public:
virtual ~nsAutoString();
nsAutoString();
nsAutoString(const nsAutoString& aString);
nsAutoString(const nsAReadableString& aString);
nsAutoString(const nsString& aString);
nsAutoString(const PRUnichar* aString);
explicit nsAutoString(const nsAReadableString& aString);
explicit nsAutoString(const nsString& aString);
explicit nsAutoString(const PRUnichar* aString);
nsAutoString(const PRUnichar* aString,PRInt32 aLength);
nsAutoString(PRUnichar aChar);
nsAutoString(const CBufDescriptor& aBuffer);
#ifndef NEW_STRING_APIS
// nsAutoString(const char* aCString,PRInt32 aLength=-1);
// nsAutoString(const nsStr& aString);
#endif
explicit nsAutoString(PRUnichar aChar);
explicit nsAutoString(const CBufDescriptor& aBuffer);
#if defined(AIX) || defined(XP_OS2_VACPP)
nsAutoString(const nsSubsumeStr& aSubsumeStr); // AIX and VAC++ requires a const
explicit nsAutoString(const nsSubsumeStr& aSubsumeStr); // AIX and VAC++ requires a const
#else
nsAutoString(nsSubsumeStr& aSubsumeStr);
explicit nsAutoString(nsSubsumeStr& aSubsumeStr);
#endif // AIX || XP_OS2_VACPP
nsAutoString& operator=( const nsAutoString& aString ) { Assign(aString); return *this; }
#ifdef NEW_STRING_APIS
private:
void operator=( char ); // NOT TO BE IMPLEMENTED
public:
@ -952,13 +610,6 @@ public:
nsAutoString& operator=( const nsPromiseReadable<PRUnichar>& aReadable ) { Assign(aReadable); return *this; }
nsAutoString& operator=( const PRUnichar* aPtr ) { Assign(aPtr); return *this; }
nsAutoString& operator=( PRUnichar aChar ) { Assign(aChar); return *this; }
#else
nsAutoString& operator=(const nsStr& aString) {nsString::Assign(aString); return *this;}
// nsAutoString& operator=(const char* aCString) {nsString::Assign(aCString); return *this;}
// nsAutoString& operator=(char aChar) {nsString::Assign(aChar); return *this;}
nsAutoString& operator=(const PRUnichar* aBuffer) {nsString::Assign(aBuffer); return *this;}
nsAutoString& operator=(PRUnichar aChar) {nsString::Assign(aChar); return *this;}
#endif
/**
* Retrieve the size of this string
@ -969,10 +620,6 @@ public:
char mBuffer[kDefaultStringSize<<eTwoByte];
};
#ifdef NEW_STRING_APIS
NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsAutoString, PRUnichar)
#endif
class NS_COM NS_ConvertASCIItoUCS2
: public nsAutoString
/*
@ -980,19 +627,10 @@ class NS_COM NS_ConvertASCIItoUCS2
*/
{
public:
NS_ConvertASCIItoUCS2( const char* );
explicit NS_ConvertASCIItoUCS2( const char* );
NS_ConvertASCIItoUCS2( const char*, PRUint32 );
NS_ConvertASCIItoUCS2( char );
#if 0
#ifdef NEW_STRING_APIS
NS_ConvertASCIItoUCS2( const nsAReadableCString& );
#else
class nsCString;
NS_ConvertASCIItoUCS2( const nsCString& );
#endif
#endif
explicit NS_ConvertASCIItoUCS2( char );
#ifdef NEW_STRING_APIS
operator const PRUnichar*() const
{
return GetUnicode();
@ -1002,7 +640,6 @@ class NS_COM NS_ConvertASCIItoUCS2
{
return nsLiteralString(mUStr, mLength);
}
#endif
private:
// NOT TO BE IMPLEMENTED
@ -1036,6 +673,7 @@ class NS_COM NS_ConvertUTF8toUCS2
: public nsAutoString
{
public:
explicit
NS_ConvertUTF8toUCS2( const char* aCString )
{
Init( aCString, ~PRUint32(0) /* MAXINT */ );
@ -1046,6 +684,7 @@ class NS_COM NS_ConvertUTF8toUCS2
Init( aCString, aLength );
}
explicit
NS_ConvertUTF8toUCS2( char aChar )
{
Init( &aChar, 1 );
@ -1079,20 +718,18 @@ class NS_COM NS_ConvertUTF8toUCS2
class NS_COM nsSubsumeStr : public nsString {
public:
nsSubsumeStr();
nsSubsumeStr(nsStr& aString);
explicit nsSubsumeStr(nsStr& aString);
nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
int Subsume(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
nsSubsumeStr& operator=( const nsSubsumeStr& aReadable ) { Assign(aReadable); return *this; }
#ifdef NEW_STRING_APIS
nsSubsumeStr& operator=( const nsAReadableString& aReadable ) { Assign(aReadable); return *this; }
nsSubsumeStr& operator=( const nsPromiseReadable<PRUnichar>& aReadable ) { Assign(aReadable); return *this; }
nsSubsumeStr& operator=( const PRUnichar* aPtr ) { Assign(aPtr); return *this; }
nsSubsumeStr& operator=( PRUnichar aChar ) { Assign(aChar); return *this; }
private:
void operator=( char ); // NOT TO BE IMPLEMENTED
#endif
};

View File

@ -17,22 +17,11 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author:
* Rick Gessner <rickg@netscape.com>
*
* Contributor(s):
* Rick Gessner <rickg@netscape.com> (original author)
* Scott Collins <scc@mozilla.org>
*/
#ifndef NEW_STRING_APIS
#define NEW_STRING_APIS 1
#endif //NEW_STRING_APIS
// Need this to enable comparison profiling for a while
#ifdef OLD_STRING_APIS
#undef NEW_STRING_APIS
#endif
/***********************************************************************
MODULE NOTES:
@ -431,21 +420,6 @@ struct NS_COM nsStr {
*/
static PRUint32 HashCode(const nsStr& aDest);
#ifndef NEW_STRING_APIS
static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount) {
StrAppend(aDest, aSource, anOffset, aCount);
}
static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount) {
StrAssign(aDest, aSource, anOffset, aCount);
}
static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount) {
StrInsert(aDest, aDestOffset, aSource, aSrcOffset, aCount);
}
static PRInt32 Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) {
return StrCompare(aDest, aSource, aCount, aIgnoreCase);
}
#endif
#ifdef NS_STR_STATS
/**
* Prints an nsStr. If truncate is true, the string is only printed up to

View File

@ -70,12 +70,10 @@ nsCString::nsCString() {
Initialize(*this,eOneByte);
}
#ifdef NEW_STRING_APIS
nsCString::nsCString(const char* aCString) {
Initialize(*this,eOneByte);
Assign(aCString);
}
#endif
/**
* This constructor accepts an ascii string
@ -137,7 +135,6 @@ nsCString::~nsCString() {
Destroy(*this);
}
#ifdef NEW_STRING_APIS
const char* nsCString::GetReadableFragment( nsReadableFragment<char>& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const {
switch ( aRequest ) {
case kFirstFragment:
@ -172,7 +169,6 @@ nsCString::nsCString( const nsAReadableCString& aReadable ) {
Initialize(*this,eOneByte);
Assign(aReadable);
}
#endif
void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
if (aResult) {
@ -232,35 +228,6 @@ const char* nsCString::GetBuffer(void) const {
return mStr;
}
#ifndef NEW_STRING_APIS
/**
* Get nth character.
*/
PRUnichar nsCString::operator[](PRUint32 anIndex) const {
return GetCharAt(*this,anIndex);
}
/**
* Get nth character.
*/
PRUnichar nsCString::CharAt(PRUint32 anIndex) const {
return GetCharAt(*this,anIndex);
}
/**
* Get 1st character.
*/
PRUnichar nsCString::First(void) const{
return GetCharAt(*this,0);
}
/**
* Get last character.
*/
PRUnichar nsCString::Last(void) const{
return (char)GetCharAt(*this,mLength-1);
}
#endif // !defined(NEW_STRING_APIS)
/**
* set a char inside this string at given index
@ -281,57 +248,6 @@ PRBool nsCString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
/*********************************************************
append (operator+) METHODS....
*********************************************************/
#ifndef NEW_STRING_APIS
/**
* Create a new string by appending given string to this
* @update gess 01/04/99
* @param aString -- 2nd string to be appended
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeCStr nsCString::operator+(const nsCString& aString){
nsCString temp(*this); //make a temp string the same size as this...
nsStr::StrAppend(temp,aString,0,aString.mLength);
return nsSubsumeCStr(temp);
}
/**
* create a new string by adding this to the given buffer.
* @update gess 01/04/99
* @param aCString is a ptr to cstring to be added to this
* @return newly created subsumable string
*/
nsSubsumeCStr nsCString::operator+(const char* aCString) {
nsCString temp(*this);
temp.Append(aCString);
return nsSubsumeCStr(temp);
}
/**
* create a new string by adding this to the given char.
* @update gess 01/04/99
* @param aChar is a char to be added to this
* @return newly created subsumable string
*/
nsSubsumeCStr nsCString::operator+(PRUnichar aChar) {
nsCString temp(*this);
temp.Append(aChar);
return nsSubsumeCStr(temp);
}
/**
* create a new string by adding this to the given char.
* @update gess 01/04/99
* @param aChar is a char to be added to this
* @return newly created string
*/
nsSubsumeCStr nsCString::operator+(char aChar) {
nsCString temp(*this);
temp.Append(aChar);
return nsSubsumeCStr(temp);
}
#endif // !defined(NEW_STRING_APIS)
/**********************************************************************
Lexomorphic transforms...
@ -843,73 +759,6 @@ PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
String manipulation methods...
*********************************************************************/
#ifndef NEW_STRING_APIS
/**
* assign given nsStr (or derivative) to this one
* @update gess 01/04/99
* @param aString: string to be appended
* @return this
*/
nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
if(this!=&aString){
nsStr::Truncate(*this,0);
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
StrAssign(*this,aString,0,aCount);
}
return *this;
}
/**
* 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
*/
nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
nsStr::Truncate(*this,0);
if(aCString){
Append(aCString,aCount);
}
return *this;
}
/**
* assign given char to this string
* @update gess 01/04/99
* @param aChar: char to be assignd to this
* @return this
*/
nsCString& nsCString::Assign(char aChar) {
nsStr::Truncate(*this,0);
return Append(aChar);
}
/**
* WARNING! THIS IS A VERY SPECIAL METHOD.
* This method "steals" the contents of aSource and hands it to aDest.
* Ordinarily a copy is made, but not in this version.
* @update gess10/30/98
* @param
* @return
*/
#if defined(AIX) || defined(XP_OS2_VACPP)
nsCString& nsCString::operator=(const nsSubsumeCStr& aSubsumeString) {
nsSubsumeCStr temp(aSubsumeString); // a temp is needed for the AIX and VAC++ compiler
CSubsume(*this,temp);
#else
nsCString& nsCString::operator=(nsSubsumeCStr& aSubsumeString) {
CSubsume(*this,aSubsumeString);
#endif // AIX || XP_OS2_VACPP
return *this;
}
#endif
/**
* assign given unichar* to this string
@ -952,7 +801,6 @@ void nsCString::AssignWithConversion( const nsString& aString ) {
AssignWithConversion(aString.GetUnicode(), aString.Length());
}
#ifdef NEW_STRING_APIS
void nsCString::AssignWithConversion( const nsAReadableString& aString ) {
nsStr::Truncate(*this,0);
PRInt32 count = aString.Length();
@ -976,9 +824,7 @@ void nsCString::AssignWithConversion( const nsAReadableString& aString ) {
}
}
}
#endif
#ifdef NEW_STRING_APIS
void nsCString::AppendWithConversion( const nsAReadableString& aString ) {
PRInt32 count = aString.Length();
@ -1001,7 +847,6 @@ void nsCString::AppendWithConversion( const nsAReadableString& aString ) {
}
}
}
#endif
/**
* assign given unichar to this string
@ -1014,7 +859,6 @@ void nsCString::AssignWithConversion(PRUnichar aChar) {
AppendWithConversion(aChar);
}
#ifdef NEW_STRING_APIS
void nsCString::do_AppendFromReadable( const nsAReadableCString& aReadable )
{
if ( SameImplementation( NS_STATIC_CAST(const nsAReadableCString&, *this), aReadable) )
@ -1022,87 +866,7 @@ void nsCString::do_AppendFromReadable( const nsAReadableCString& aReadable )
else
nsAWritableCString::do_AppendFromReadable(aReadable);
}
#endif
#ifndef NEW_STRING_APIS
/**
* append given string to this string
* @update gess 01/04/99
* @param aString : string to be appended to this
* @return this
*/
nsCString& nsCString::Append(const nsCString& aString,PRInt32 aCount) {
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
StrAppend(*this,aString,0,aCount);
return *this;
}
#if 0
/**
* append given string to this string;
* @update gess 01/04/99
* @param aString : string to be appended to this
* @return this
*/
nsCString& nsCString::Append(const nsStr& aString,PRInt32 aCount) {
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
StrAppend(*this,aString,0,aCount);
return *this;
}
#endif
/**
* append given c-string to this string
* @update gess 01/04/99
* @param aString : string to be appended to this
* @param aCount: #of chars to be copied; -1 means to copy the whole thing
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
*
* @return this
*/
nsCString& nsCString::Append(const char* aCString,PRInt32 aCount) {
if(aCString){
nsStr temp;
nsStr::Initialize(temp,eOneByte);
temp.mStr=(char*)aCString;
if(0<aCount) {
temp.mLength=aCount;
}
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(0<aCount)
StrAppend(*this,temp,0,aCount);
}
return *this;
}
/**
* append given unichar to this string
* @update gess 01/04/99
* @param aChar: char to be appended to this
* @return this
*/
nsCString& nsCString::Append(char aChar) {
char buf[2]={0,0};
buf[0]=aChar;
nsStr temp;
nsStr::Initialize(temp,eOneByte);
temp.mStr=buf;
temp.mLength=1;
StrAppend(*this,temp,0,1);
return *this;
}
#endif
/**
* append given char to this string
@ -1272,7 +1036,6 @@ void nsCString::InsertWithConversion(PRUnichar aChar,PRUint32 anOffset){
StrInsert(*this,anOffset,temp,0,1);
}
#ifdef NEW_STRING_APIS
void nsCString::do_InsertFromReadable( const nsAReadableCString& aReadable, PRUint32 atPosition )
{
if ( SameImplementation( NS_STATIC_CAST(const nsAReadableCString&, *this), aReadable) )
@ -1280,99 +1043,10 @@ void nsCString::do_InsertFromReadable( const nsAReadableCString& aReadable, PRUi
else
nsAWritableCString::do_InsertFromReadable(aReadable, atPosition);
}
#endif
#ifndef NEW_STRING_APIS
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
* @update gess 4/1/98
* @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
*/
void nsCString::Insert(const nsCString& aString,PRUint32 anOffset,PRInt32 aCount) {
StrInsert(*this,anOffset,aString,0,aCount);
}
/**
* 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 aCounttells us how many chars to insert
* @return this
*/
void nsCString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount){
if(aCString){
nsStr temp;
nsStr::Initialize(temp,eOneByte);
temp.mStr=(char*)aCString;
if(0<aCount) {
temp.mLength=aCount;
// If this assertion fires, the caller is probably lying about the length of
// the passed-in string. File a bug on the caller.
#ifdef NS_DEBUG
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
if(kNotFound<len) {
NS_WARNING(kPossibleNull);
}
#endif
}
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(temp.mLength && (0<aCount)){
StrInsert(*this,anOffset,temp,0,aCount);
}
}
}
/**
* Insert a single uni-char into this string at
* a specified offset.
*
* @update gess4/22/98
* @param aChar char to be inserted into this string
* @param anOffset is insert pos in str
* @return this
*/
void nsCString::Insert(char aChar,PRUint32 anOffset){
char theBuffer[2]={0,0};
theBuffer[0]=aChar;
nsStr temp;
nsStr::Initialize(temp,eOneByte);
temp.mStr=theBuffer;
temp.mLength=1;
StrInsert(*this,anOffset,temp,0,1);
}
#endif
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
* @update gess 01/04/99
* @param anOffset -- start pos for cut operation
* @param aCount -- number of chars to be cut
* @return *this
*/
#ifndef NEW_STRING_APIS
void nsCString::Cut(PRUint32 anOffset, PRInt32 aCount) {
if(0<aCount) {
nsStr::Delete(*this,anOffset,aCount);
}
}
#endif
/**********************************************************************
Searching methods...
*********************************************************************/
@ -1676,55 +1350,6 @@ PRInt32 nsCString::CompareWithConversion(const char *aCString,PRBool aIgnoreCase
return 0;
}
#ifndef NEW_STRING_APIS
/**
* Compare given nsStr with this cstring.
*
* @param aString is an nsStr instance to be compared
* @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 nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
return nsStr::StrCompare(*this,aString,aCount,aIgnoreCase);
}
#endif
#ifndef NEW_STRING_APIS
/**
* Here come a whole bunch of operator functions that are self-explanatory...
*/
PRBool nsCString::operator==(const nsStr& S) const {return Equals(S);}
PRBool nsCString::operator==(const char* s) const {return Equals(s);}
//PRBool nsCString::operator==(const PRUnichar* s) const {return Equals(s);}
PRBool nsCString::operator!=(const nsStr& S) const {return PRBool(Compare(S)!=0);}
PRBool nsCString::operator!=(const char* s) const {return PRBool(Compare(nsCAutoString(s))!=0);}
//PRBool nsCString::operator!=(const PRUnichar* s) const {return PRBool(Compare(s)!=0);}
PRBool nsCString::operator<(const nsStr& S) const {return PRBool(Compare(S)<0);}
PRBool nsCString::operator<(const char* s) const {return PRBool(Compare(nsCAutoString(s))<0);}
//PRBool nsCString::operator<(const PRUnichar* s) const {return PRBool(Compare(s)<0);}
PRBool nsCString::operator>(const nsStr& S) const {return PRBool(Compare(S)>0);}
PRBool nsCString::operator>(const char* s) const {return PRBool(Compare(nsCAutoString(s))>0);}
//PRBool nsCString::operator>(const PRUnichar* s) const {return PRBool(Compare(s)>0);}
PRBool nsCString::operator<=(const nsStr& S) const {return PRBool(Compare(S)<=0);}
PRBool nsCString::operator<=(const char* s) const {return PRBool(Compare(nsCAutoString(s))<=0);}
//PRBool nsCString::operator<=(const PRUnichar* s) const {return PRBool(Compare(s)<=0);}
PRBool nsCString::operator>=(const nsStr& S) const {return PRBool(Compare(S)>=0);}
PRBool nsCString::operator>=(const char* s) const {return PRBool(Compare(nsCAutoString(s))>=0);}
//PRBool nsCString::operator>=(const PRUnichar* s) const {return PRBool(Compare(s)>=0);}
#endif
#ifndef NEW_STRING_APIS
PRBool nsCString::EqualsIgnoreCase(const nsStr& aString) const {
return Equals(aString,PR_TRUE);
}
#endif
PRBool nsCString::EqualsIgnoreCase(const char* aString,PRInt32 aLength) const {
return EqualsWithConversion(aString,PR_TRUE,aLength);
}
@ -1734,22 +1359,6 @@ PRBool nsCString::EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aLength) con
}
#ifndef NEW_STRING_APIS
/**
* Compare this to given string; note that we compare full strings here.
*
* @update gess 01/04/99
* @param aString is the other nsCString to be compared to
* @param aIgnoreCase tells us how to treat case
* @param aCount tells us how many chars to test; -1 implies full length
* @return TRUE if equal
*/
PRBool nsCString::Equals(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
PRInt32 theAnswer=nsStr::StrCompare(*this,aString,aCount,aIgnoreCase);
PRBool result=PRBool(0==theAnswer);
return result;
}
#endif
/**
* Compare this to given string; note that we compare full strings here.
@ -1935,7 +1544,6 @@ void nsCString::DebugDump(void) const {
//----------------------------------------------------------------------
#ifdef NEW_STRING_APIS
NS_ConvertUCS2toUTF8::NS_ConvertUCS2toUTF8( const nsAReadableString& aString )
{
nsReadingIterator<PRUnichar> start(aString.BeginReading());
@ -1947,7 +1555,6 @@ NS_ConvertUCS2toUTF8::NS_ConvertUCS2toUTF8( const nsAReadableString& aString )
start += start.size_forward();
}
}
#endif
void
NS_ConvertUCS2toUTF8::Append( const PRUnichar* aString, PRUint32 aLength )

View File

@ -17,10 +17,8 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author:
* Rick Gessner <rickg@netscape.com>
*
* Contributor(s):
* Rick Gessner <rickg@netscape.com> (original author)
* Scott Collins <scc@mozilla.org>
*/
@ -38,15 +36,6 @@
4. Subsumable strings
***********************************************************************/
#ifndef NEW_STRING_APIS
#define NEW_STRING_APIS 1
#endif //NEW_STRING_APIS
// Need this to enable comparison profiling for a while
#ifdef OLD_STRING_APIS
#undef NEW_STRING_APIS
#endif
#ifndef _nsCString_
#define _nsCString_
@ -57,45 +46,19 @@
#include "nsStr.h"
#include "nsIAtom.h"
#ifdef NEW_STRING_APIS
#include "nsAWritableString.h"
#else
#define NS_LITERAL_STRING(s) (s)
#define NS_LITERAL_CSTRING(s) (s)
#define NS_DEF_DERIVED_STRING_OPERATOR_PLUS(_StringT, _CharT)
#define NS_DEF_2_STRING_STRING_OPERATOR_PLUS(_String1T, _String2T, _CharT)
inline
char
nsLiteralChar( char c )
{
return c;
}
inline
PRUnichar
nsLiteralPRUnichar( PRUnichar c )
{
return c;
}
#endif
class NS_COM nsSubsumeCStr;
class NS_COM nsCString :
#ifdef NEW_STRING_APIS
public nsAWritableCString,
#endif
public nsStr {
#ifdef NEW_STRING_APIS
protected:
virtual const void* Implementation() const { return "nsCString"; }
virtual const char* GetReadableFragment( nsReadableFragment<char>&, nsFragmentRequest, PRUint32 ) const;
virtual char* GetWritableFragment( nsWritableFragment<char>&, nsFragmentRequest, PRUint32 );
#endif
public:
/**
@ -109,36 +72,16 @@ public:
*/
nsCString(const nsCString& aString);
#ifdef NEW_STRING_APIS
explicit nsCString( const nsAReadableCString& );
nsCString(const char*);
explicit nsCString(const char*);
nsCString(const char*, PRInt32);
#else
/**
* This constructor accepts an isolatin string
* @param aCString is a ptr to a 1-byte cstr
*/
nsCString(const char* aCString,PRInt32 aLength=-1);
/**
* This constructor accepts a unichar string
* @param aCString is a ptr to a 2-byte cstr
*/
//nsCString(const PRUnichar* aString,PRInt32 aLength=-1);
/**
* This is a copy constructor that accepts an nsStr
* @param reference to another nsCString
*/
//nsCString(const nsStr&);
#endif
/**
* This constructor takes a subsumestr
* @param reference to subsumestr
*/
nsCString(nsSubsumeCStr& aSubsumeStr);
explicit nsCString(nsSubsumeCStr& aSubsumeStr);
/**
* Destructor
@ -186,17 +129,6 @@ public:
SetLength(anIndex);
}
#ifndef NEW_STRING_APIS
/**
* Determine whether or not this string has a length of 0
*
* @return TRUE if empty.
*/
PRBool IsEmpty(void) const {
return PRBool(0==mLength);
}
#endif
/**********************************************************************
Accessor methods...
*********************************************************************/
@ -207,49 +139,8 @@ public:
*/
const char* GetBuffer(void) const;
#ifndef NEW_STRING_APIS
/**
* Get nth character.
*/
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
#endif
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
/**********************************************************************
String creation methods...
*********************************************************************/
#ifndef NEW_STRING_APIS
/**
* Create a new string by appending given string to this
* @param aString -- 2nd string to be appended
* @return new string
*/
nsSubsumeCStr operator+(const nsCString& aString);
/**
* create a new string by adding this to the given char*.
* @param aCString is a ptr to cstring to be added to this
* @return newly created string
*/
nsSubsumeCStr operator+(const char* aCString);
/**
* create a new string by adding this to the given char.
* @param aChar is a char to be added to this
* @return newly created string
*/
nsSubsumeCStr operator+(PRUnichar aChar);
nsSubsumeCStr operator+(char aChar);
#endif
/**********************************************************************
Lexomorphic transforms...
*********************************************************************/
@ -419,50 +310,16 @@ public:
*/
nsCString& operator=( const nsCString& aString ) { Assign(aString); return *this; }
#ifdef NEW_STRING_APIS
nsCString& operator=( const nsAReadableCString& aReadable ) { Assign(aReadable); return *this; }
nsCString& operator=( const nsPromiseReadable<char>& aReadable ) { Assign(aReadable); return *this; }
nsCString& operator=( const char* aPtr ) { Assign(aPtr); return *this; }
nsCString& operator=( char aChar ) { Assign(aChar); return *this; }
#endif
void AssignWithConversion(const PRUnichar*,PRInt32=-1);
void AssignWithConversion( const nsString& aString );
#ifdef NEW_STRING_APIS
void AssignWithConversion( const nsAReadableString& aString );
#endif
void AssignWithConversion(PRUnichar);
#ifndef NEW_STRING_APIS
nsCString& Assign(const char* aString,PRInt32 aCount=-1);
nsCString& Assign(char aChar);
nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1);
//nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1) { AssignWithConversion(aString, aCount); return *this; }
//nsCString& Assign(PRUnichar aChar) { AssignWithConversion(aChar); return *this; }
/**
* here come a bunch of assignment operators...
* @param aString: string to be added to this
* @return this
*/
//nsCString& operator=(PRUnichar aChar) {AssignWithConversion(aChar); return *this;}
nsCString& operator=(char aChar) {return Assign(aChar);}
//nsCString& operator=(const PRUnichar* aString) {AssignWithConversion(aString); return *this;}
//nsCString& operator=(const nsStr& aString) {return Assign(aString);}
nsCString& operator=(const char* aCString) {return Assign(aCString);}
// Yes, I know this makes assignment from a |nsSubsumeString| not do the special thing
// |nsSubsumeString| needs to go away
#if defined(AIX) || defined(XP_OS2_VACPP)
nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX and VAC++ requires a const here
#else
nsCString& operator=(nsSubsumeCStr& aSubsumeString);
#endif
#endif
/*
* Appends n characters from given string to this,
*
@ -475,42 +332,13 @@ public:
void AppendWithConversion(const nsString&, PRInt32=-1);
void AppendWithConversion(PRUnichar aChar);
#ifdef NEW_STRING_APIS
void AppendWithConversion( const nsAReadableString& aString );
#endif
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 );
#ifdef NEW_STRING_APIS
virtual void do_AppendFromReadable( const nsAReadableCString& );
#endif
#ifndef NEW_STRING_APIS
//nsCString& Append(const nsStr& aString,PRInt32 aCount=-1);
nsCString& Append(const nsCString& aString,PRInt32 aCount);
nsCString& Append(const nsCString& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsCString& Append(const char* aString,PRInt32 aCount=-1);
nsCString& Append(char aChar);
//nsCString& Append(PRUnichar aChar) {AppendWithConversion(aChar); return *this;}
//nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10) {AppendInt(aInteger,aRadix); return *this;}
//nsCString& Append(float aFloat) {AppendFloat(aFloat); return *this;}
/**
* Here's a bunch of methods that append varying types...
* @param various...
* @return this
*/
nsCString& operator+=(const nsCString& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsCString& operator+=(const char* aCString) {return Append(aCString);}
//nsCString& operator+=(const PRUnichar aChar) {return Append(aChar);}
nsCString& operator+=(const char aChar) {return Append(aChar);}
//nsCString& operator+=(const int anInt) {return Append(anInt,10);}
#endif
/*
* Copies n characters from this string to given string,
* starting at the leftmost offset.
@ -548,57 +376,7 @@ public:
void InsertWithConversion(PRUnichar aChar,PRUint32 anOffset);
// Why no |InsertWithConversion(PRUnichar*)|?
#ifdef NEW_STRING_APIS
virtual void do_InsertFromReadable( const nsAReadableCString&, PRUint32 );
#endif
#ifndef NEW_STRING_APIS
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
* @param aCopy -- String to be inserted into this
* @param anOffset -- insertion position within this str
* @param aCount -- number of chars to be copied from aCopy
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
*
* @return number of chars inserted into this.
*/
void Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
/**
* Insert a given string into this string at
* a specified offset.
*
* @param aString* to be inserted into this string
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
void Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
/**
* Insert a single char into this string at
* a specified offset.
*
* @param character to be inserted into this string
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
//void Insert(PRUnichar aChar,PRUint32 anOffset) {InsertWithConversion(aChar,anOffset);}
void Insert(char aChar,PRUint32 anOffset);
#endif
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
* @param anOffset -- start pos for cut operation
* @param aCount -- number of chars to be cut
* @return *this
*/
#ifndef NEW_STRING_APIS
void Cut(PRUint32 anOffset,PRInt32 aCount);
#endif
/**********************************************************************
@ -699,96 +477,6 @@ public:
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const;
#ifndef NEW_STRING_APIS
//virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return CompareWithConversion(aString,aIgnoreCase,aCount);
//}
//virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return CompareWithConversion(aString,aIgnoreCase,aCount);
//}
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
/**
* Compare this to given string; note that we compare full strings here.
* The optional length argument just lets us know how long the given string is.
* If you provide a length, it is compared to length of this string as an
* optimization.
*
* @param aString -- the string to compare to this
* @param aCount -- number of chars in given string you want to compare
* @return TRUE if equal
*/
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
return EqualsWithConversion(aString,aIgnoreCase,aCount);
}
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
return EqualsWithConversion(aString,aIgnoreCase,aCount);
}
//PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return EqualsWithConversion(aString,aIgnoreCase,aCount);
//}
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const nsStr& aString) const;
/**
* These methods compare a given string type to this one
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char* aString) const;
//PRBool operator==(const PRUnichar* aString) const;
/**
* These methods perform a !compare of a given string type to this
* @param aString is the string to be compared to this
* @return TRUE
*/
PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const;
//PRBool operator!=(const PRUnichar* aString) const;
/**
* These methods test if a given string is < than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const;
//PRBool operator<(const PRUnichar* aString) const;
/**
* These methods test if a given string is > than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const;
//PRBool operator>(const PRUnichar* aString) const;
/**
* These methods test if a given string is <= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const;
//PRBool operator<=(const PRUnichar* aString) const;
/**
* These methods test if a given string is >= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const;
//PRBool operator>=(const PRUnichar* aString) const;
#endif // !defined(NEW_STRING_APIS)
void DebugDump(void) const;
@ -799,28 +487,14 @@ public:
private:
// NOT TO BE IMPLEMENTED
// these signatures help clients not accidentally call the wrong thing helped by C++ automatic integral promotion
#ifdef NEW_STRING_APIS
void operator=( PRUnichar );
#endif
void AssignWithConversion( char );
void AssignWithConversion( const char*, PRInt32=-1 );
void AppendWithConversion( char );
void InsertWithConversion( char, PRUint32 );
};
#if 0 // #ifdef NEW_STRING_APIS
inline
nsPromiseConcatenation<char>
operator+( const nsPromiseConcatenation<char>& lhs, const nsCString& rhs )
{
return nsPromiseConcatenation<char>(lhs, rhs);
}
#endif
#ifdef NEW_STRING_APIS
NS_DEF_STRING_COMPARISON_OPERATORS(nsCString, char)
// NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsCString, char);
#endif
extern NS_COM int fputs(const nsCString& aString, FILE* out);
//ostream& operator<<(ostream& aStream,const nsCString& aString);
@ -839,27 +513,20 @@ public:
virtual ~nsCAutoString();
nsCAutoString();
nsCAutoString(const nsCString& );
nsCAutoString(const nsAReadableCString& aString);
nsCAutoString(const char* aString);
explicit nsCAutoString(const nsCString& );
explicit nsCAutoString(const nsAReadableCString& aString);
explicit nsCAutoString(const char* aString);
nsCAutoString(const char* aString,PRInt32 aLength);
nsCAutoString(const CBufDescriptor& aBuffer);
#ifndef NEW_STRING_APIS
// nsCAutoString(const PRUnichar* aString,PRInt32 aLength=-1);
// nsCAutoString(const nsStr& aString);
// nsCAutoString(PRUnichar aChar);
#endif
explicit nsCAutoString(const CBufDescriptor& aBuffer);
#if defined(AIX) || defined(XP_OS2_VACPP)
nsCAutoString(const nsSubsumeCStr& aSubsumeStr); // AIX and VAC++ require a const
explicit nsCAutoString(const nsSubsumeCStr& aSubsumeStr); // AIX and VAC++ require a const
#else
nsCAutoString(nsSubsumeCStr& aSubsumeStr);
explicit nsCAutoString(nsSubsumeCStr& aSubsumeStr);
#endif // AIX || XP_OS2_VACPP
nsCAutoString& operator=( const nsCAutoString& aString ) { Assign(aString); return *this; }
#ifdef NEW_STRING_APIS
private:
void operator=( PRUnichar ); // NOT TO BE IMPLEMENTED
public:
@ -867,13 +534,6 @@ public:
nsCAutoString& operator=( const nsPromiseReadable<char>& aReadable ) { Assign(aReadable); return *this; }
nsCAutoString& operator=( const char* aPtr ) { Assign(aPtr); return *this; }
nsCAutoString& operator=( char aChar ) { Assign(aChar); return *this; }
#else
nsCAutoString& operator=(const nsCString& aString) {nsCString::Assign(aString); return *this;}
nsCAutoString& operator=(const char* aCString) {nsCString::Assign(aCString); return *this;}
// nsCAutoString& operator=(const PRUnichar* aString) {nsCString::Assign(aString); return *this;}
// nsCAutoString& operator=(PRUnichar aChar) {nsCString::Assign(aChar); return *this;}
nsCAutoString& operator=(char aChar) {nsCString::Assign(aChar); return *this;}
#endif
/**
* Retrieve the size of this string
@ -884,14 +544,6 @@ public:
char mBuffer[kDefaultStringSize];
};
#if 0//def NEW_STRING_APIS
NS_DEF_STRING_COMPARISON_OPERATORS(nsCAutoString, char)
#endif
#ifdef NEW_STRING_APIS
NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsCAutoString, char)
#endif
/**
* A helper class that converts a UCS2 string to UTF8
*/
@ -902,6 +554,7 @@ class NS_COM NS_ConvertUCS2toUTF8
*/
{
public:
explicit
NS_ConvertUCS2toUTF8( const PRUnichar* aString )
{
Append( aString, ~PRUint32(0) /* MAXINT */);
@ -912,14 +565,13 @@ class NS_COM NS_ConvertUCS2toUTF8
Append( aString, aLength );
}
explicit
NS_ConvertUCS2toUTF8( PRUnichar aChar )
{
Append( &aChar, 1 );
}
#ifdef NEW_STRING_APIS
NS_ConvertUCS2toUTF8( const nsAReadableString& aString );
#endif
explicit NS_ConvertUCS2toUTF8( const nsAReadableString& aString );
operator const char*() const
{
@ -950,19 +602,17 @@ class NS_COM NS_ConvertUCS2toUTF8
***************************************************************/
class NS_COM nsSubsumeCStr : public nsCString {
public:
nsSubsumeCStr(nsStr& aString);
explicit nsSubsumeCStr(nsStr& aString);
nsSubsumeCStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
nsSubsumeCStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
nsSubsumeCStr& operator=( const nsSubsumeCStr& aString ) { Assign(aString); return *this; }
#ifdef NEW_STRING_APIS
nsSubsumeCStr& operator=( const nsAReadableCString& aReadable ) { Assign(aReadable); return *this; }
nsSubsumeCStr& operator=( const nsPromiseReadable<char>& aReadable ) { Assign(aReadable); return *this; }
nsSubsumeCStr& operator=( const char* aPtr ) { Assign(aPtr); return *this; }
nsSubsumeCStr& operator=( char aChar ) { Assign(aChar); return *this; }
private:
void operator=( PRUnichar ); // NOT TO BE IMPLEMENTED
#endif
};

View File

@ -17,10 +17,8 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author:
* Rick Gessner <rickg@netscape.com>
*
* Contributor(s):
* Rick Gessner <rickg@netscape.com> (original author)
* Scott Collins <scc@mozilla.org>
*/
@ -69,25 +67,10 @@ nsString::nsString() {
Initialize(*this,eTwoByte);
}
#if 0
/**
* 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
*/
nsString::nsString(const char* aCString,PRInt32 aCount){
Initialize(*this,eTwoByte);
AssignWithConversion(aCString,aCount);
}
#endif
#ifdef NEW_STRING_APIS
nsString::nsString(const PRUnichar* aString) {
Initialize(*this,eTwoByte);
Assign(aString);
}
#endif
/**
* This constructor accepts a unicode string
@ -100,18 +83,6 @@ nsString::nsString(const PRUnichar* aString,PRInt32 aCount) {
Assign(aString,aCount);
}
#if 0
/**
* This constructor works for all other nsSTr derivatives
* @update gess 1/4/99
* @param reference to another nsCString
*/
nsString::nsString(const nsStr &aString) {
Initialize(*this,eTwoByte);
StrAssign(*this,aString,0,aString.mLength);
}
#endif
/**
* This is our copy constructor
* @update gess 1/4/99
@ -149,7 +120,6 @@ nsString::~nsString() {
nsStr::Destroy(*this);
}
#ifdef NEW_STRING_APIS
const PRUnichar* nsString::GetReadableFragment( nsReadableFragment<PRUnichar>& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const {
switch ( aRequest ) {
case kFirstFragment:
@ -199,7 +169,6 @@ nsString::nsString( const nsAReadableString& aReadable ) {
Initialize(*this,eTwoByte);
Assign(aReadable);
}
#endif
void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
if (aResult) {
@ -275,36 +244,6 @@ const PRUnichar* nsString::GetUnicode(void) const {
return result;
}
#ifndef NEW_STRING_APIS
/**
* Get nth character.
*/
PRUnichar nsString::operator[](PRUint32 anIndex) const {
return GetCharAt(*this,anIndex);
}
/**
* Get nth character.
*/
PRUnichar nsString::CharAt(PRUint32 anIndex) const {
return GetCharAt(*this,anIndex);
}
/**
* Get 1st character.
*/
PRUnichar nsString::First(void) const{
return GetCharAt(*this,0);
}
/**
* Get last character.
*/
PRUnichar nsString::Last(void) const{
return GetCharAt(*this,mLength-1);
}
#endif // !defined(NEW_STRING_APIS)
/**
* set a char inside this string at given index
* @param aChar is the char you want to write into this string
@ -330,81 +269,6 @@ PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
append (operator+) METHODS....
*********************************************************/
#ifndef NEW_STRING_APIS
/**
* Create a new string by appending given string to this
* @update gess 01/04/99
* @param aString -- 2nd string to be appended
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(const nsStr& aString){
nsString temp(*this); //make a temp string the same size as this...
nsStr::StrAppend(temp,aString,0,aString.mLength);
return nsSubsumeStr(temp);
}
/**
* Create a new string by appending given string to this
* @update gess 01/04/99
* @param aString -- 2nd string to be appended
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(const nsString& aString){
nsString temp(*this); //make a temp string the same size as this...
nsStr::StrAppend(temp,aString,0,aString.mLength);
return nsSubsumeStr(temp);
}
/**
* create a new string by adding this to the given buffer.
* @update gess 01/04/99
* @param aCString is a ptr to cstring to be added to this
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(const char* aCString) {
nsString temp(*this);
temp.AppendWithConversion(aCString);
return nsSubsumeStr(temp);
}
/**
* create a new string by adding this to the given char.
* @update gess 01/04/99
* @param aChar is a char to be added to this
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(char aChar) {
nsString temp(*this);
temp.Append(char(aChar));
return nsSubsumeStr(temp);
}
/**
* create a new string by adding this to the given buffer.
* @update gess 01/04/99
* @param aString is a ptr to unistring to be added to this
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(const PRUnichar* aString) {
nsString temp(*this);
temp.Append(aString);
return nsSubsumeStr(temp);
}
/**
* create a new string by adding this to the given char.
* @update gess 01/04/99
* @param aChar is a unichar to be added to this
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(PRUnichar aChar) {
nsString temp(*this);
temp.Append(char(aChar));
return nsSubsumeStr(temp);
}
#endif // !defined(NEW_STRING_APIS)
/**********************************************************************
Lexomorphic transforms...
@ -952,26 +816,6 @@ PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
*********************************************************************/
#ifndef NEW_STRING_APIS
/**
* assign given nsStr (or derivative) to this one
* @update gess 01/04/99
* @param aString: nsStr to be appended
* @return this
*/
nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
if(this!=&aString){
nsStr::Truncate(*this,0);
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
StrAssign(*this,aString,0,aCount);
}
return *this;
}
#endif
/**
* assign given char* to this string
@ -989,33 +833,13 @@ void nsString::AssignWithConversion(const char* aCString,PRInt32 aCount) {
}
}
#ifdef NEW_STRING_APIS
void nsString::AssignWithConversion(const char* aCString) {
nsStr::Truncate(*this,0);
if(aCString){
AppendWithConversion(aCString);
}
}
#endif
#ifndef NEW_STRING_APIS
/**
* assign given unichar* to this string
* @update gess 01/04/99
* @param aString: 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
*/
nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
nsStr::Truncate(*this,0);
if(aString){
Append(aString,aCount);
}
return *this;
}
#endif
/**
* assign given char to this string
@ -1028,39 +852,6 @@ void nsString::AssignWithConversion(char aChar) {
AppendWithConversion(aChar);
}
#ifndef NEW_STRING_APIS
/**
* assign given unichar to this string
* @update gess 01/04/99
* @param aChar: char to be assignd to this
* @return this
*/
nsString& nsString::Assign(PRUnichar aChar) {
nsStr::Truncate(*this,0);
return Append(aChar);
}
#endif
#ifndef NEW_STRING_APIS
/**
* WARNING! THIS IS A VERY SPECIAL METHOD.
* This method "steals" the contents of aSource and hands it to aDest.
* Ordinarily a copy is made, but not in this version.
* @update gess10/30/98
* @param
* @return
*/
#if defined(AIX) || defined(XP_OS2_VACPP)
nsString& nsString::operator=(const nsSubsumeStr& aSubsumeString) {
nsSubsumeStr temp(aSubsumeString); // a temp is needed for the AIX and VAC++ compilers
Subsume(*this,temp);
#else
nsString& nsString::operator=(nsSubsumeStr& aSubsumeString) {
Subsume(*this,aSubsumeString);
#endif // AIX || XP_OS2_VACPP
return *this;
}
#endif
/**
* append given c-string to this string
@ -1169,96 +960,6 @@ void nsString::AppendFloat(double aFloat){
}
#ifndef NEW_STRING_APIS
/**
* append given string to this string;
* @update gess 01/04/99
* @param aString : string to be appended to this
* @return this
*/
#if 0
nsString& nsString::Append(const nsStr& aString,PRInt32 aCount) {
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
StrAppend(*this,aString,0,aCount);
return *this;
}
#endif
/**
* append given string to this string
* I don't think we need this method now that we have the previous one.
* @update gess 01/04/99
* @param aString : string to be appended to this
* @return this
*/
nsString& nsString::Append(const nsString& aString,PRInt32 aCount) {
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
StrAppend(*this,aString,0,aCount);
return *this;
}
/**
* append given unicode string to this
* @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
*/
nsString& nsString::Append(const PRUnichar* aString,PRInt32 aCount) {
if(aString && aCount){ //if astring is null or count==0 there's nothing to do
nsStr temp;
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=(PRUnichar*)aString;
if(0<aCount) {
temp.mLength=aCount;
// If this assertion fires, the caller is probably lying about the length of
// the passed-in string. File a bug on the caller.
#ifdef NS_DEBUG
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
if(kNotFound<len) {
NS_WARNING(kPossibleNull);
}
#endif
}
else aCount=temp.mLength=nsCRT::strlen(aString);
if(0<aCount)
StrAppend(*this,temp,0,aCount);
}
return *this;
}
/**
* append given unichar to this string
* @update gess 01/04/99
* @param aChar: char to be appended to this
* @return this
*/
nsString& nsString::Append(PRUnichar aChar) {
PRUnichar buf[2]={0,0};
buf[0]=aChar;
nsStr temp;
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=buf;
temp.mLength=1;
StrAppend(*this,temp,0,1);
return *this;
}
#endif
/*
* Copies n characters from this left of this string to given string,
@ -1349,98 +1050,8 @@ void nsString::InsertWithConversion(const char* aCString,PRUint32 anOffset,PRInt
}
}
#ifndef NEW_STRING_APIS
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
* @update gess 4/1/98
* @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
*/
void nsString::Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) {
StrInsert(*this,anOffset,aCopy,0,aCount);
}
/**
* Insert a unicode* into this string at a specified offset.
*
* @update gess4/22/98
* @param aChar char to be inserted into this string
* @param anOffset is insert pos in str
* @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::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aCount){
if(aString && aCount){
nsStr temp;
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=(PRUnichar*)aString;
if(0<aCount) {
temp.mLength=aCount;
// If this assertion fires, the caller is probably lying about the length of
// the passed-in string. File a bug on the caller.
#ifdef NS_DEBUG
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
if(kNotFound<len) {
NS_WARNING(kPossibleNull);
}
#endif
}
else aCount=temp.mLength=nsCRT::strlen(aString);
if(0<aCount){
StrInsert(*this,anOffset,temp,0,aCount);
}
}
}
/**
* Insert a single uni-char into this string at
* a specified offset.
*
* @update gess4/22/98
* @param aChar char to be inserted into this string
* @param anOffset is insert pos in str
* @return this
*/
void nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
PRUnichar theBuffer[2]={0,0};
theBuffer[0]=aChar;
nsStr temp;
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=theBuffer;
temp.mLength=1;
StrInsert(*this,anOffset,temp,0,1);
}
#endif
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
* @update gess 01/04/99
* @param anOffset -- start pos for cut operation
* @param aCount -- number of chars to be cut
* @return *this
*/
#ifndef NEW_STRING_APIS
void nsString::Cut(PRUint32 anOffset, PRInt32 aCount) {
if(0<aCount) {
nsStr::Delete(*this,anOffset,aCount);
}
}
#endif
/**********************************************************************
Searching methods...
*********************************************************************/
@ -1823,55 +1434,7 @@ PRInt32 nsString::CompareWithConversion(const PRUnichar* aString,PRBool aIgnoreC
return 0;
}
#ifndef NEW_STRING_APIS
/**
* Compare given nsStr with this cstring.
*
* @param aString is an nsStr instance to be compared
* @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::Compare(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
return nsStr::StrCompare(*this,aString,aCount,aIgnoreCase);
}
#endif
#ifndef NEW_STRING_APIS
/**
* Here come a whole bunch of operator functions that are self-explanatory...
*/
PRBool nsString::operator==(const nsString& S) const {return Equals(S);}
//PRBool nsString::operator==(const nsStr& S) const {return Equals(S);}
//PRBool nsString::operator==(const char* s) const {return Equals(s);}
PRBool nsString::operator==(const PRUnichar* s) const {return Equals(nsAutoString(s));}
PRBool nsString::operator!=(const nsString& S) const {return PRBool(Compare(S)!=0);}
//PRBool nsString::operator!=(const nsStr& S) const {return PRBool(Compare(S)!=0);}
//PRBool nsString::operator!=(const char* s) const {return PRBool(Compare(s)!=0);}
PRBool nsString::operator!=(const PRUnichar* s) const {return PRBool(Compare(nsAutoString(s))!=0);}
PRBool nsString::operator<(const nsString& S) const {return PRBool(Compare(S)<0);}
//PRBool nsString::operator<(const nsStr& S) const {return PRBool(Compare(S)<0);}
//PRBool nsString::operator<(const char* s) const {return PRBool(Compare(s)<0);}
PRBool nsString::operator<(const PRUnichar* s) const {return PRBool(Compare(nsAutoString(s))<0);}
PRBool nsString::operator>(const nsString& S) const {return PRBool(Compare(S)>0);}
//PRBool nsString::operator>(const nsStr& S) const {return PRBool(Compare(S)>0);}
//PRBool nsString::operator>(const char* s) const {return PRBool(Compare(s)>0);}
PRBool nsString::operator>(const PRUnichar* s) const {return PRBool(Compare(nsAutoString(s))>0);}
PRBool nsString::operator<=(const nsString& S) const {return PRBool(Compare(S)<=0);}
//PRBool nsString::operator<=(const nsStr& S) const {return PRBool(Compare(S)<=0);}
//PRBool nsString::operator<=(const char* s) const {return PRBool(Compare(s)<=0);}
PRBool nsString::operator<=(const PRUnichar* s) const {return PRBool(Compare(nsAutoString(s))<=0);}
PRBool nsString::operator>=(const nsString& S) const {return PRBool(Compare(S)>=0);}
//PRBool nsString::operator>=(const nsStr& S) const {return PRBool(Compare(S)>=0);}
//PRBool nsString::operator>=(const char* s) const {return PRBool(Compare(s)>=0);}
PRBool nsString::operator>=(const PRUnichar* s) const {return PRBool(Compare(nsAutoString(s))>=0);}
#endif // !defined(NEW_STRING_APIS)
PRBool nsString::EqualsIgnoreCase(const nsString& aString) const {
return EqualsWithConversion(aString,PR_TRUE);
@ -1881,12 +1444,6 @@ PRBool nsString::EqualsIgnoreCase(const char* aString,PRInt32 aLength) const {
return EqualsWithConversion(aString,PR_TRUE,aLength);
}
#ifndef NEW_STRING_APIS
PRBool nsString::EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const {
return Equals(s1,s2,PR_TRUE);
}
#endif
/**
* Compare this to given string; note that we compare full strings here.
*
@ -1963,40 +1520,6 @@ PRBool nsString::EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const {
return EqualsAtom(aAtom,PR_TRUE);
}
#ifndef NEW_STRING_APIS
/**
* Compare this to given string; note that we compare full strings here.
*
* @update gess 01/04/99
* @param aString is the other nsString to be compared to
* @param aCount tells us how many chars to test; -1 implies full length
* @return TRUE if equal
*/
PRBool nsString::Equals(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
PRInt32 theAnswer=nsStr::StrCompare(*this,aString,aCount,aIgnoreCase);
PRBool result=PRBool(0==theAnswer);
return result;
}
/**
* Compare given strings
* @update gess 7/27/98
* @param s1 -- first unichar string to be compared
* @param s2 -- second unichar string to be compared
* @return TRUE if equal
*/
PRBool nsString::Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase) const {
NS_ASSERTION(0!=s1,kNullPointerError);
NS_ASSERTION(0!=s2,kNullPointerError);
PRBool result=PR_FALSE;
if((s1) && (s2)){
PRInt32 cmp=(aIgnoreCase) ? nsCRT::strcasecmp(s1,s2) : nsCRT::strcmp(s1,s2);
result=PRBool(0==cmp);
}
return result;
}
#endif
/**
* Determine if given char in valid alpha range
@ -2321,21 +1844,6 @@ NS_ConvertASCIItoUCS2::NS_ConvertASCIItoUCS2( char aChar )
AppendWithConversion(aChar);
}
#if 0
#ifdef NEW_STRING_APIS
NS_ConvertASCIItoUCS2::NS_ConvertASCIItoUCS2( const nsAReadableCString& )
{
// ...
}
#else
NS_ConvertASCIItoUCS2::NS_ConvertASCIItoUCS2( const nsCString& )
{
// ...
}
#endif
#endif
void
NS_ConvertUTF8toUCS2::Init( const char* aCString, PRUint32 aLength )
{

View File

@ -17,10 +17,8 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author:
* Rick Gessner <rickg@netscape.com>
*
* Contributor(s):
* Rick Gessner <rickg@netscape.com> (original author)
* Scott Collins <scc@mozilla.org>
*/
@ -39,16 +37,6 @@
4. Subsumable strings
***********************************************************************/
#ifndef NEW_STRING_APIS
#define NEW_STRING_APIS 1
#endif //NEW_STRING_APIS
// Need this to enable comparison profiling for a while
#ifdef OLD_STRING_APIS
#undef NEW_STRING_APIS
#endif
#ifndef _nsString_
#define _nsString_
@ -60,9 +48,7 @@
#include "nsStr.h"
#include "nsCRT.h"
#ifdef NEW_STRING_APIS
#include "nsAWritableString.h"
#endif
#ifdef STANDALONE_MI_STRING_TESTS
class nsAReadableString { public: virtual ~nsAReadableString() { } };
@ -78,17 +64,13 @@ class nsISizeOfHandler;
class NS_COM nsSubsumeStr;
class NS_COM nsString :
#if defined(NEW_STRING_APIS) || defined(STANDALONE_MI_STRING_TESTS)
public nsAWritableString,
#endif
public nsStr {
#ifdef NEW_STRING_APIS
protected:
virtual const void* Implementation() const { return "nsString"; }
virtual const PRUnichar* GetReadableFragment( nsReadableFragment<PRUnichar>&, nsFragmentRequest, PRUint32 ) const;
virtual PRUnichar* GetWritableFragment( nsWritableFragment<PRUnichar>&, nsFragmentRequest, PRUint32 );
#endif
public:
@ -103,30 +85,10 @@ public:
*/
nsString(const nsString& aString);
#ifdef NEW_STRING_APIS
explicit nsString(const nsAReadableString&);
nsString(const PRUnichar*);
explicit nsString(const PRUnichar*);
nsString(const PRUnichar*, PRInt32);
#else
/**
* This constructor accepts a unichar string
* @param aCString is a ptr to a 2-byte cstr
*/
nsString(const PRUnichar* aString,PRInt32 aCount=-1);
/**
* This constructor accepts an isolatin string
* @param aCString is a ptr to a 1-byte cstr
*/
//nsString(const char* aCString,PRInt32 aCount=-1);
/**
* This is a copy constructor that accepts an nsStr
* @param reference to another nsString
*/
//nsString(const nsStr&);
#endif
/**
@ -134,9 +96,9 @@ public:
* @param reference to subsumestr
*/
#if defined(AIX) || defined(XP_OS2_VACPP)
nsString(const nsSubsumeStr& aSubsumeStr); // AIX and VAC++ require a const here
explicit nsString(const nsSubsumeStr& aSubsumeStr); // AIX and VAC++ require a const here
#else
nsString(nsSubsumeStr& aSubsumeStr);
explicit nsString(nsSubsumeStr& aSubsumeStr);
#endif
/**
@ -198,17 +160,6 @@ public:
return result;
}
#ifndef NEW_STRING_APIS
/**
* Determine whether or not this string has a length of 0
*
* @return TRUE if empty.
*/
PRBool IsEmpty(void) const {
return PRBool(0==mLength);
}
#endif
/**********************************************************************
Getters/Setters...
*********************************************************************/
@ -219,63 +170,12 @@ public:
const char* GetBuffer(void) const;
const PRUnichar* GetUnicode(void) const;
#ifndef NEW_STRING_APIS
/**
* Get nth character.
*/
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
#endif // !defined(NEW_STRING_APIS)
/**
* Set nth character.
*/
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
#ifndef NEW_STRING_APIS
/**********************************************************************
String concatenation methods...
*********************************************************************/
/**
* Create a new string by appending given string to this
* @param aString -- 2nd string to be appended
* @return new subsumable string
*/
nsSubsumeStr operator+(const nsStr& aString);
nsSubsumeStr operator+(const nsString& aString);
/**
* create a new string by adding this to the given cstring
* @param aCString is a ptr to cstring to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(const char* aCString);
/**
* create a new string by adding this to the given prunichar*.
* @param aString is a ptr to UC-string to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(const PRUnichar* aString);
/**
* create a new string by adding this to the given char.
* @param aChar is a char to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(char aChar);
/**
* create a new string by adding this to the given char.
* @param aChar is a unichar to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(PRUnichar aChar);
#endif
/**********************************************************************
Lexomorphic transforms...
@ -449,47 +349,14 @@ public:
*/
nsString& operator=( const nsString& aString ) { Assign(aString); return *this; }
#ifdef NEW_STRING_APIS
nsString& operator=( const nsAReadableString& aReadable ) { Assign(aReadable); return *this; }
nsString& operator=( const nsPromiseReadable<PRUnichar>& aReadable ) { Assign(aReadable); return *this; }
nsString& operator=( const PRUnichar* aPtr ) { Assign(aPtr); return *this; }
nsString& operator=( PRUnichar aChar ) { Assign(aChar); return *this; }
#endif
void AssignWithConversion(char);
#ifdef NEW_STRING_APIS
void AssignWithConversion(const char*);
void AssignWithConversion(const char*, PRInt32);
#else
void AssignWithConversion(const char*, PRInt32=-1);
nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Assign(PRUnichar aChar);
nsString& Assign(const nsStr& aString,PRInt32 aCount=-1);
//nsString& Assign(const char* aString,PRInt32 aCount=-1) { AssignWithConversion(aString, aCount); return *this; }
//nsString& Assign(char aChar) { AssignWithConversion(aChar); return *this; }
/**
* here come a bunch of assignment operators...
* @param aString: string to be added to this
* @return this
*/
nsString& operator=(PRUnichar aChar) {Assign(aChar); return *this;}
//nsString& operator=(char aChar) {AssignWithConversion(aChar); return *this;}
//nsString& operator=(const char* aCString) {AssignWithConversion(aCString); return *this;}
//nsString& operator=(const nsStr& aString) {return Assign(aString);}
nsString& operator=(const PRUnichar* aString) {return Assign(aString);}
// Yes, I know this makes assignment from a |nsSubsumeString| not do the special thing
// |nsSubsumeString| needs to go away
#if defined(AIX) || defined(XP_OS2_VACPP)
nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX and VAC++ requires a const here
#else
nsString& operator=(nsSubsumeStr& aSubsumeString);
#endif
#endif
/*
@ -507,42 +374,6 @@ public:
virtual void do_AppendFromElement( PRUnichar );
#ifndef NEW_STRING_APIS
/*
* 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
*/
//nsString& Append(const nsStr& aString,PRInt32 aCount);
//nsString& Append(const nsStr& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsString& Append(const nsString& aString,PRInt32 aCount);
nsString& Append(const nsString& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Append(PRUnichar aChar);
//nsString& Append(const char* aString,PRInt32 aCount=-1) { AppendWithConversion(aString,aCount); return *this; }
//nsString& Append(char aChar) { AppendWithConversion(aChar); return *this; }
//nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10) { AppendInt(aInteger,aRadix); return *this; }
//nsString& Append(float aFloat) { AppendFloat(aFloat); return *this; }
/**
* Here's a bunch of methods that append varying types...
* @param various...
* @return this
*/
//nsString& operator+=(const char* aCString) {return Append(aCString);}
//nsString& operator+=(const char aChar) {return Append((PRUnichar) (unsigned char)aChar);}
nsString& operator+=(const PRUnichar aChar) {return Append(aChar);}
//nsString& operator+=(const int anInt) {return Append(anInt,10);}
//nsString& operator+=(const nsStr& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsString& operator+=(const nsString& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);}
#endif
/*
* Copies n characters from this string to given string,
@ -581,55 +412,6 @@ public:
//void InsertWithConversion(char);
void InsertWithConversion(const char*, PRUint32, PRInt32=-1);
#ifndef NEW_STRING_APIS
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
* @param aCopy -- String to be inserted into this
* @param anOffset -- insertion position within this str
* @param aCount -- number of chars to be copied from aCopy
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
*
* @return number of chars inserted into this.
*/
void Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
/**
* Insert a given string into this string at
* a specified offset.
*
* @param aString* to be inserted into this string
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
//nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1) {InsertWithConversion(aChar, anOffset, aCount); return *this;}
void Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
/**
* Insert a single char into this string at
* a specified offset.
*
* @param character to be inserted into this string
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
//nsString& Insert(char aChar,PRUint32 anOffset) {InsertWithConversion(aChar,anOffset); return *this;}
void Insert(PRUnichar aChar,PRUint32 anOffset);
#endif
#ifndef NEW_STRING_APIS
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
* @param anOffset -- start pos for cut operation
* @param aCount -- number of chars to be cut
* @return *this
*/
void Cut(PRUint32 anOffset,PRInt32 aCount);
#endif
/**********************************************************************
@ -739,110 +521,6 @@ public:
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const;
#ifndef NEW_STRING_APIS
//virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return CompareWithConversion(aString,aIgnoreCase,aCount);
//}
//virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return CompareWithConversion(aString,aIgnoreCase,aCount);
//}
//virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return CompareWithConversion(aString,aIgnoreCase,aCount);
//}
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
/**
* Compare this to given string; note that we compare full strings here.
* The optional length argument just lets us know how long the given string is.
* If you provide a length, it is compared to length of this string as an
* optimization.
*
* @param aString -- the string to compare to this
* @param aCount -- number of chars to be compared.
* @return TRUE if equal
*/
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
return EqualsWithConversion(aString,aIgnoreCase,aCount);
}
//PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return EqualsWithConversion(aString,aIgnoreCase,aCount);
//}
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
return EqualsWithConversion(aString,aIgnoreCase,aCount);
}
//PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const { return EqualsAtom(anAtom, aIgnoreCase); }
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
/**
* These methods compare a given string type to this one
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator==(const nsString &aString) const;
//PRBool operator==(const nsStr &aString) const;
//PRBool operator==(const char *aString) const;
PRBool operator==(const PRUnichar* aString) const;
/**
* These methods perform a !compare of a given string type to this
* @param aString is the string to be compared to this
* @return TRUE
*/
PRBool operator!=(const nsString &aString) const;
//PRBool operator!=(const nsStr &aString) const;
//PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const;
/**
* These methods test if a given string is < than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<(const nsString &aString) const;
//PRBool operator<(const nsStr &aString) const;
//PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const;
/**
* These methods test if a given string is > than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>(const nsString &aString) const;
//PRBool operator>(const nsStr &S) const;
//PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const;
/**
* These methods test if a given string is <= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<=(const nsString &aString) const;
//PRBool operator<=(const nsStr &S) const;
//PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const;
/**
* These methods test if a given string is >= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>=(const nsString &aString) const;
//PRBool operator>=(const nsStr &S) const;
//PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const;
#endif // !defined(NEW_STRING_APIS)
/**
* Determine if given buffer is plain ascii
@ -884,9 +562,7 @@ public:
private:
// NOT TO BE IMPLEMENTED
// these signatures help clients not accidentally call the wrong thing helped by C++ automatic integral promotion
#ifdef NEW_STRING_APIS
void operator=( char );
#endif
void AssignWithConversion( PRUnichar );
void AssignWithConversion( const PRUnichar*, PRInt32=-1 );
void AppendWithConversion( PRUnichar );
@ -894,19 +570,7 @@ private:
void InsertWithConversion( const PRUnichar*, PRUint32, PRInt32=-1 );
};
#ifdef NEW_STRING_APIS
NS_DEF_STRING_COMPARISON_OPERATORS(nsString, PRUnichar)
// NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsString, PRUnichar)
#endif
#if 0 // #ifdef NEW_STRING_APIS
inline
nsPromiseConcatenation<PRUnichar>
operator+( const nsPromiseConcatenation<PRUnichar>& lhs, const nsString& rhs )
{
return nsPromiseConcatenation<PRUnichar>(lhs, rhs);
}
#endif
extern NS_COM int fputs(const nsString& aString, FILE* out);
//ostream& operator<<(ostream& aStream,const nsString& aString);
@ -924,27 +588,21 @@ public:
virtual ~nsAutoString();
nsAutoString();
nsAutoString(const nsAutoString& aString);
nsAutoString(const nsAReadableString& aString);
nsAutoString(const nsString& aString);
nsAutoString(const PRUnichar* aString);
explicit nsAutoString(const nsAReadableString& aString);
explicit nsAutoString(const nsString& aString);
explicit nsAutoString(const PRUnichar* aString);
nsAutoString(const PRUnichar* aString,PRInt32 aLength);
nsAutoString(PRUnichar aChar);
nsAutoString(const CBufDescriptor& aBuffer);
#ifndef NEW_STRING_APIS
// nsAutoString(const char* aCString,PRInt32 aLength=-1);
// nsAutoString(const nsStr& aString);
#endif
explicit nsAutoString(PRUnichar aChar);
explicit nsAutoString(const CBufDescriptor& aBuffer);
#if defined(AIX) || defined(XP_OS2_VACPP)
nsAutoString(const nsSubsumeStr& aSubsumeStr); // AIX and VAC++ requires a const
explicit nsAutoString(const nsSubsumeStr& aSubsumeStr); // AIX and VAC++ requires a const
#else
nsAutoString(nsSubsumeStr& aSubsumeStr);
explicit nsAutoString(nsSubsumeStr& aSubsumeStr);
#endif // AIX || XP_OS2_VACPP
nsAutoString& operator=( const nsAutoString& aString ) { Assign(aString); return *this; }
#ifdef NEW_STRING_APIS
private:
void operator=( char ); // NOT TO BE IMPLEMENTED
public:
@ -952,13 +610,6 @@ public:
nsAutoString& operator=( const nsPromiseReadable<PRUnichar>& aReadable ) { Assign(aReadable); return *this; }
nsAutoString& operator=( const PRUnichar* aPtr ) { Assign(aPtr); return *this; }
nsAutoString& operator=( PRUnichar aChar ) { Assign(aChar); return *this; }
#else
nsAutoString& operator=(const nsStr& aString) {nsString::Assign(aString); return *this;}
// nsAutoString& operator=(const char* aCString) {nsString::Assign(aCString); return *this;}
// nsAutoString& operator=(char aChar) {nsString::Assign(aChar); return *this;}
nsAutoString& operator=(const PRUnichar* aBuffer) {nsString::Assign(aBuffer); return *this;}
nsAutoString& operator=(PRUnichar aChar) {nsString::Assign(aChar); return *this;}
#endif
/**
* Retrieve the size of this string
@ -969,10 +620,6 @@ public:
char mBuffer[kDefaultStringSize<<eTwoByte];
};
#ifdef NEW_STRING_APIS
NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsAutoString, PRUnichar)
#endif
class NS_COM NS_ConvertASCIItoUCS2
: public nsAutoString
/*
@ -980,19 +627,10 @@ class NS_COM NS_ConvertASCIItoUCS2
*/
{
public:
NS_ConvertASCIItoUCS2( const char* );
explicit NS_ConvertASCIItoUCS2( const char* );
NS_ConvertASCIItoUCS2( const char*, PRUint32 );
NS_ConvertASCIItoUCS2( char );
#if 0
#ifdef NEW_STRING_APIS
NS_ConvertASCIItoUCS2( const nsAReadableCString& );
#else
class nsCString;
NS_ConvertASCIItoUCS2( const nsCString& );
#endif
#endif
explicit NS_ConvertASCIItoUCS2( char );
#ifdef NEW_STRING_APIS
operator const PRUnichar*() const
{
return GetUnicode();
@ -1002,7 +640,6 @@ class NS_COM NS_ConvertASCIItoUCS2
{
return nsLiteralString(mUStr, mLength);
}
#endif
private:
// NOT TO BE IMPLEMENTED
@ -1036,6 +673,7 @@ class NS_COM NS_ConvertUTF8toUCS2
: public nsAutoString
{
public:
explicit
NS_ConvertUTF8toUCS2( const char* aCString )
{
Init( aCString, ~PRUint32(0) /* MAXINT */ );
@ -1046,6 +684,7 @@ class NS_COM NS_ConvertUTF8toUCS2
Init( aCString, aLength );
}
explicit
NS_ConvertUTF8toUCS2( char aChar )
{
Init( &aChar, 1 );
@ -1079,20 +718,18 @@ class NS_COM NS_ConvertUTF8toUCS2
class NS_COM nsSubsumeStr : public nsString {
public:
nsSubsumeStr();
nsSubsumeStr(nsStr& aString);
explicit nsSubsumeStr(nsStr& aString);
nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
int Subsume(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
nsSubsumeStr& operator=( const nsSubsumeStr& aReadable ) { Assign(aReadable); return *this; }
#ifdef NEW_STRING_APIS
nsSubsumeStr& operator=( const nsAReadableString& aReadable ) { Assign(aReadable); return *this; }
nsSubsumeStr& operator=( const nsPromiseReadable<PRUnichar>& aReadable ) { Assign(aReadable); return *this; }
nsSubsumeStr& operator=( const PRUnichar* aPtr ) { Assign(aPtr); return *this; }
nsSubsumeStr& operator=( PRUnichar aChar ) { Assign(aChar); return *this; }
private:
void operator=( char ); // NOT TO BE IMPLEMENTED
#endif
};

View File

@ -17,22 +17,11 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author:
* Rick Gessner <rickg@netscape.com>
*
* Contributor(s):
* Rick Gessner <rickg@netscape.com> (original author)
* Scott Collins <scc@mozilla.org>
*/
#ifndef NEW_STRING_APIS
#define NEW_STRING_APIS 1
#endif //NEW_STRING_APIS
// Need this to enable comparison profiling for a while
#ifdef OLD_STRING_APIS
#undef NEW_STRING_APIS
#endif
/***********************************************************************
MODULE NOTES:
@ -431,21 +420,6 @@ struct NS_COM nsStr {
*/
static PRUint32 HashCode(const nsStr& aDest);
#ifndef NEW_STRING_APIS
static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount) {
StrAppend(aDest, aSource, anOffset, aCount);
}
static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount) {
StrAssign(aDest, aSource, anOffset, aCount);
}
static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount) {
StrInsert(aDest, aDestOffset, aSource, aSrcOffset, aCount);
}
static PRInt32 Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) {
return StrCompare(aDest, aSource, aCount, aIgnoreCase);
}
#endif
#ifdef NS_STR_STATS
/**
* Prints an nsStr. If truncate is true, the string is only printed up to

View File

@ -70,12 +70,10 @@ nsCString::nsCString() {
Initialize(*this,eOneByte);
}
#ifdef NEW_STRING_APIS
nsCString::nsCString(const char* aCString) {
Initialize(*this,eOneByte);
Assign(aCString);
}
#endif
/**
* This constructor accepts an ascii string
@ -137,7 +135,6 @@ nsCString::~nsCString() {
Destroy(*this);
}
#ifdef NEW_STRING_APIS
const char* nsCString::GetReadableFragment( nsReadableFragment<char>& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const {
switch ( aRequest ) {
case kFirstFragment:
@ -172,7 +169,6 @@ nsCString::nsCString( const nsAReadableCString& aReadable ) {
Initialize(*this,eOneByte);
Assign(aReadable);
}
#endif
void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
if (aResult) {
@ -232,35 +228,6 @@ const char* nsCString::GetBuffer(void) const {
return mStr;
}
#ifndef NEW_STRING_APIS
/**
* Get nth character.
*/
PRUnichar nsCString::operator[](PRUint32 anIndex) const {
return GetCharAt(*this,anIndex);
}
/**
* Get nth character.
*/
PRUnichar nsCString::CharAt(PRUint32 anIndex) const {
return GetCharAt(*this,anIndex);
}
/**
* Get 1st character.
*/
PRUnichar nsCString::First(void) const{
return GetCharAt(*this,0);
}
/**
* Get last character.
*/
PRUnichar nsCString::Last(void) const{
return (char)GetCharAt(*this,mLength-1);
}
#endif // !defined(NEW_STRING_APIS)
/**
* set a char inside this string at given index
@ -281,57 +248,6 @@ PRBool nsCString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
/*********************************************************
append (operator+) METHODS....
*********************************************************/
#ifndef NEW_STRING_APIS
/**
* Create a new string by appending given string to this
* @update gess 01/04/99
* @param aString -- 2nd string to be appended
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeCStr nsCString::operator+(const nsCString& aString){
nsCString temp(*this); //make a temp string the same size as this...
nsStr::StrAppend(temp,aString,0,aString.mLength);
return nsSubsumeCStr(temp);
}
/**
* create a new string by adding this to the given buffer.
* @update gess 01/04/99
* @param aCString is a ptr to cstring to be added to this
* @return newly created subsumable string
*/
nsSubsumeCStr nsCString::operator+(const char* aCString) {
nsCString temp(*this);
temp.Append(aCString);
return nsSubsumeCStr(temp);
}
/**
* create a new string by adding this to the given char.
* @update gess 01/04/99
* @param aChar is a char to be added to this
* @return newly created subsumable string
*/
nsSubsumeCStr nsCString::operator+(PRUnichar aChar) {
nsCString temp(*this);
temp.Append(aChar);
return nsSubsumeCStr(temp);
}
/**
* create a new string by adding this to the given char.
* @update gess 01/04/99
* @param aChar is a char to be added to this
* @return newly created string
*/
nsSubsumeCStr nsCString::operator+(char aChar) {
nsCString temp(*this);
temp.Append(aChar);
return nsSubsumeCStr(temp);
}
#endif // !defined(NEW_STRING_APIS)
/**********************************************************************
Lexomorphic transforms...
@ -843,73 +759,6 @@ PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
String manipulation methods...
*********************************************************************/
#ifndef NEW_STRING_APIS
/**
* assign given nsStr (or derivative) to this one
* @update gess 01/04/99
* @param aString: string to be appended
* @return this
*/
nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
if(this!=&aString){
nsStr::Truncate(*this,0);
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
StrAssign(*this,aString,0,aCount);
}
return *this;
}
/**
* 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
*/
nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
nsStr::Truncate(*this,0);
if(aCString){
Append(aCString,aCount);
}
return *this;
}
/**
* assign given char to this string
* @update gess 01/04/99
* @param aChar: char to be assignd to this
* @return this
*/
nsCString& nsCString::Assign(char aChar) {
nsStr::Truncate(*this,0);
return Append(aChar);
}
/**
* WARNING! THIS IS A VERY SPECIAL METHOD.
* This method "steals" the contents of aSource and hands it to aDest.
* Ordinarily a copy is made, but not in this version.
* @update gess10/30/98
* @param
* @return
*/
#if defined(AIX) || defined(XP_OS2_VACPP)
nsCString& nsCString::operator=(const nsSubsumeCStr& aSubsumeString) {
nsSubsumeCStr temp(aSubsumeString); // a temp is needed for the AIX and VAC++ compiler
CSubsume(*this,temp);
#else
nsCString& nsCString::operator=(nsSubsumeCStr& aSubsumeString) {
CSubsume(*this,aSubsumeString);
#endif // AIX || XP_OS2_VACPP
return *this;
}
#endif
/**
* assign given unichar* to this string
@ -952,7 +801,6 @@ void nsCString::AssignWithConversion( const nsString& aString ) {
AssignWithConversion(aString.GetUnicode(), aString.Length());
}
#ifdef NEW_STRING_APIS
void nsCString::AssignWithConversion( const nsAReadableString& aString ) {
nsStr::Truncate(*this,0);
PRInt32 count = aString.Length();
@ -976,9 +824,7 @@ void nsCString::AssignWithConversion( const nsAReadableString& aString ) {
}
}
}
#endif
#ifdef NEW_STRING_APIS
void nsCString::AppendWithConversion( const nsAReadableString& aString ) {
PRInt32 count = aString.Length();
@ -1001,7 +847,6 @@ void nsCString::AppendWithConversion( const nsAReadableString& aString ) {
}
}
}
#endif
/**
* assign given unichar to this string
@ -1014,7 +859,6 @@ void nsCString::AssignWithConversion(PRUnichar aChar) {
AppendWithConversion(aChar);
}
#ifdef NEW_STRING_APIS
void nsCString::do_AppendFromReadable( const nsAReadableCString& aReadable )
{
if ( SameImplementation( NS_STATIC_CAST(const nsAReadableCString&, *this), aReadable) )
@ -1022,87 +866,7 @@ void nsCString::do_AppendFromReadable( const nsAReadableCString& aReadable )
else
nsAWritableCString::do_AppendFromReadable(aReadable);
}
#endif
#ifndef NEW_STRING_APIS
/**
* append given string to this string
* @update gess 01/04/99
* @param aString : string to be appended to this
* @return this
*/
nsCString& nsCString::Append(const nsCString& aString,PRInt32 aCount) {
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
StrAppend(*this,aString,0,aCount);
return *this;
}
#if 0
/**
* append given string to this string;
* @update gess 01/04/99
* @param aString : string to be appended to this
* @return this
*/
nsCString& nsCString::Append(const nsStr& aString,PRInt32 aCount) {
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
StrAppend(*this,aString,0,aCount);
return *this;
}
#endif
/**
* append given c-string to this string
* @update gess 01/04/99
* @param aString : string to be appended to this
* @param aCount: #of chars to be copied; -1 means to copy the whole thing
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
*
* @return this
*/
nsCString& nsCString::Append(const char* aCString,PRInt32 aCount) {
if(aCString){
nsStr temp;
nsStr::Initialize(temp,eOneByte);
temp.mStr=(char*)aCString;
if(0<aCount) {
temp.mLength=aCount;
}
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(0<aCount)
StrAppend(*this,temp,0,aCount);
}
return *this;
}
/**
* append given unichar to this string
* @update gess 01/04/99
* @param aChar: char to be appended to this
* @return this
*/
nsCString& nsCString::Append(char aChar) {
char buf[2]={0,0};
buf[0]=aChar;
nsStr temp;
nsStr::Initialize(temp,eOneByte);
temp.mStr=buf;
temp.mLength=1;
StrAppend(*this,temp,0,1);
return *this;
}
#endif
/**
* append given char to this string
@ -1272,7 +1036,6 @@ void nsCString::InsertWithConversion(PRUnichar aChar,PRUint32 anOffset){
StrInsert(*this,anOffset,temp,0,1);
}
#ifdef NEW_STRING_APIS
void nsCString::do_InsertFromReadable( const nsAReadableCString& aReadable, PRUint32 atPosition )
{
if ( SameImplementation( NS_STATIC_CAST(const nsAReadableCString&, *this), aReadable) )
@ -1280,99 +1043,10 @@ void nsCString::do_InsertFromReadable( const nsAReadableCString& aReadable, PRUi
else
nsAWritableCString::do_InsertFromReadable(aReadable, atPosition);
}
#endif
#ifndef NEW_STRING_APIS
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
* @update gess 4/1/98
* @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
*/
void nsCString::Insert(const nsCString& aString,PRUint32 anOffset,PRInt32 aCount) {
StrInsert(*this,anOffset,aString,0,aCount);
}
/**
* 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 aCounttells us how many chars to insert
* @return this
*/
void nsCString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount){
if(aCString){
nsStr temp;
nsStr::Initialize(temp,eOneByte);
temp.mStr=(char*)aCString;
if(0<aCount) {
temp.mLength=aCount;
// If this assertion fires, the caller is probably lying about the length of
// the passed-in string. File a bug on the caller.
#ifdef NS_DEBUG
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
if(kNotFound<len) {
NS_WARNING(kPossibleNull);
}
#endif
}
else aCount=temp.mLength=nsCRT::strlen(aCString);
if(temp.mLength && (0<aCount)){
StrInsert(*this,anOffset,temp,0,aCount);
}
}
}
/**
* Insert a single uni-char into this string at
* a specified offset.
*
* @update gess4/22/98
* @param aChar char to be inserted into this string
* @param anOffset is insert pos in str
* @return this
*/
void nsCString::Insert(char aChar,PRUint32 anOffset){
char theBuffer[2]={0,0};
theBuffer[0]=aChar;
nsStr temp;
nsStr::Initialize(temp,eOneByte);
temp.mStr=theBuffer;
temp.mLength=1;
StrInsert(*this,anOffset,temp,0,1);
}
#endif
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
* @update gess 01/04/99
* @param anOffset -- start pos for cut operation
* @param aCount -- number of chars to be cut
* @return *this
*/
#ifndef NEW_STRING_APIS
void nsCString::Cut(PRUint32 anOffset, PRInt32 aCount) {
if(0<aCount) {
nsStr::Delete(*this,anOffset,aCount);
}
}
#endif
/**********************************************************************
Searching methods...
*********************************************************************/
@ -1676,55 +1350,6 @@ PRInt32 nsCString::CompareWithConversion(const char *aCString,PRBool aIgnoreCase
return 0;
}
#ifndef NEW_STRING_APIS
/**
* Compare given nsStr with this cstring.
*
* @param aString is an nsStr instance to be compared
* @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 nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
return nsStr::StrCompare(*this,aString,aCount,aIgnoreCase);
}
#endif
#ifndef NEW_STRING_APIS
/**
* Here come a whole bunch of operator functions that are self-explanatory...
*/
PRBool nsCString::operator==(const nsStr& S) const {return Equals(S);}
PRBool nsCString::operator==(const char* s) const {return Equals(s);}
//PRBool nsCString::operator==(const PRUnichar* s) const {return Equals(s);}
PRBool nsCString::operator!=(const nsStr& S) const {return PRBool(Compare(S)!=0);}
PRBool nsCString::operator!=(const char* s) const {return PRBool(Compare(nsCAutoString(s))!=0);}
//PRBool nsCString::operator!=(const PRUnichar* s) const {return PRBool(Compare(s)!=0);}
PRBool nsCString::operator<(const nsStr& S) const {return PRBool(Compare(S)<0);}
PRBool nsCString::operator<(const char* s) const {return PRBool(Compare(nsCAutoString(s))<0);}
//PRBool nsCString::operator<(const PRUnichar* s) const {return PRBool(Compare(s)<0);}
PRBool nsCString::operator>(const nsStr& S) const {return PRBool(Compare(S)>0);}
PRBool nsCString::operator>(const char* s) const {return PRBool(Compare(nsCAutoString(s))>0);}
//PRBool nsCString::operator>(const PRUnichar* s) const {return PRBool(Compare(s)>0);}
PRBool nsCString::operator<=(const nsStr& S) const {return PRBool(Compare(S)<=0);}
PRBool nsCString::operator<=(const char* s) const {return PRBool(Compare(nsCAutoString(s))<=0);}
//PRBool nsCString::operator<=(const PRUnichar* s) const {return PRBool(Compare(s)<=0);}
PRBool nsCString::operator>=(const nsStr& S) const {return PRBool(Compare(S)>=0);}
PRBool nsCString::operator>=(const char* s) const {return PRBool(Compare(nsCAutoString(s))>=0);}
//PRBool nsCString::operator>=(const PRUnichar* s) const {return PRBool(Compare(s)>=0);}
#endif
#ifndef NEW_STRING_APIS
PRBool nsCString::EqualsIgnoreCase(const nsStr& aString) const {
return Equals(aString,PR_TRUE);
}
#endif
PRBool nsCString::EqualsIgnoreCase(const char* aString,PRInt32 aLength) const {
return EqualsWithConversion(aString,PR_TRUE,aLength);
}
@ -1734,22 +1359,6 @@ PRBool nsCString::EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aLength) con
}
#ifndef NEW_STRING_APIS
/**
* Compare this to given string; note that we compare full strings here.
*
* @update gess 01/04/99
* @param aString is the other nsCString to be compared to
* @param aIgnoreCase tells us how to treat case
* @param aCount tells us how many chars to test; -1 implies full length
* @return TRUE if equal
*/
PRBool nsCString::Equals(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
PRInt32 theAnswer=nsStr::StrCompare(*this,aString,aCount,aIgnoreCase);
PRBool result=PRBool(0==theAnswer);
return result;
}
#endif
/**
* Compare this to given string; note that we compare full strings here.
@ -1935,7 +1544,6 @@ void nsCString::DebugDump(void) const {
//----------------------------------------------------------------------
#ifdef NEW_STRING_APIS
NS_ConvertUCS2toUTF8::NS_ConvertUCS2toUTF8( const nsAReadableString& aString )
{
nsReadingIterator<PRUnichar> start(aString.BeginReading());
@ -1947,7 +1555,6 @@ NS_ConvertUCS2toUTF8::NS_ConvertUCS2toUTF8( const nsAReadableString& aString )
start += start.size_forward();
}
}
#endif
void
NS_ConvertUCS2toUTF8::Append( const PRUnichar* aString, PRUint32 aLength )

View File

@ -17,10 +17,8 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author:
* Rick Gessner <rickg@netscape.com>
*
* Contributor(s):
* Rick Gessner <rickg@netscape.com> (original author)
* Scott Collins <scc@mozilla.org>
*/
@ -38,15 +36,6 @@
4. Subsumable strings
***********************************************************************/
#ifndef NEW_STRING_APIS
#define NEW_STRING_APIS 1
#endif //NEW_STRING_APIS
// Need this to enable comparison profiling for a while
#ifdef OLD_STRING_APIS
#undef NEW_STRING_APIS
#endif
#ifndef _nsCString_
#define _nsCString_
@ -57,45 +46,19 @@
#include "nsStr.h"
#include "nsIAtom.h"
#ifdef NEW_STRING_APIS
#include "nsAWritableString.h"
#else
#define NS_LITERAL_STRING(s) (s)
#define NS_LITERAL_CSTRING(s) (s)
#define NS_DEF_DERIVED_STRING_OPERATOR_PLUS(_StringT, _CharT)
#define NS_DEF_2_STRING_STRING_OPERATOR_PLUS(_String1T, _String2T, _CharT)
inline
char
nsLiteralChar( char c )
{
return c;
}
inline
PRUnichar
nsLiteralPRUnichar( PRUnichar c )
{
return c;
}
#endif
class NS_COM nsSubsumeCStr;
class NS_COM nsCString :
#ifdef NEW_STRING_APIS
public nsAWritableCString,
#endif
public nsStr {
#ifdef NEW_STRING_APIS
protected:
virtual const void* Implementation() const { return "nsCString"; }
virtual const char* GetReadableFragment( nsReadableFragment<char>&, nsFragmentRequest, PRUint32 ) const;
virtual char* GetWritableFragment( nsWritableFragment<char>&, nsFragmentRequest, PRUint32 );
#endif
public:
/**
@ -109,36 +72,16 @@ public:
*/
nsCString(const nsCString& aString);
#ifdef NEW_STRING_APIS
explicit nsCString( const nsAReadableCString& );
nsCString(const char*);
explicit nsCString(const char*);
nsCString(const char*, PRInt32);
#else
/**
* This constructor accepts an isolatin string
* @param aCString is a ptr to a 1-byte cstr
*/
nsCString(const char* aCString,PRInt32 aLength=-1);
/**
* This constructor accepts a unichar string
* @param aCString is a ptr to a 2-byte cstr
*/
//nsCString(const PRUnichar* aString,PRInt32 aLength=-1);
/**
* This is a copy constructor that accepts an nsStr
* @param reference to another nsCString
*/
//nsCString(const nsStr&);
#endif
/**
* This constructor takes a subsumestr
* @param reference to subsumestr
*/
nsCString(nsSubsumeCStr& aSubsumeStr);
explicit nsCString(nsSubsumeCStr& aSubsumeStr);
/**
* Destructor
@ -186,17 +129,6 @@ public:
SetLength(anIndex);
}
#ifndef NEW_STRING_APIS
/**
* Determine whether or not this string has a length of 0
*
* @return TRUE if empty.
*/
PRBool IsEmpty(void) const {
return PRBool(0==mLength);
}
#endif
/**********************************************************************
Accessor methods...
*********************************************************************/
@ -207,49 +139,8 @@ public:
*/
const char* GetBuffer(void) const;
#ifndef NEW_STRING_APIS
/**
* Get nth character.
*/
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
#endif
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
/**********************************************************************
String creation methods...
*********************************************************************/
#ifndef NEW_STRING_APIS
/**
* Create a new string by appending given string to this
* @param aString -- 2nd string to be appended
* @return new string
*/
nsSubsumeCStr operator+(const nsCString& aString);
/**
* create a new string by adding this to the given char*.
* @param aCString is a ptr to cstring to be added to this
* @return newly created string
*/
nsSubsumeCStr operator+(const char* aCString);
/**
* create a new string by adding this to the given char.
* @param aChar is a char to be added to this
* @return newly created string
*/
nsSubsumeCStr operator+(PRUnichar aChar);
nsSubsumeCStr operator+(char aChar);
#endif
/**********************************************************************
Lexomorphic transforms...
*********************************************************************/
@ -419,50 +310,16 @@ public:
*/
nsCString& operator=( const nsCString& aString ) { Assign(aString); return *this; }
#ifdef NEW_STRING_APIS
nsCString& operator=( const nsAReadableCString& aReadable ) { Assign(aReadable); return *this; }
nsCString& operator=( const nsPromiseReadable<char>& aReadable ) { Assign(aReadable); return *this; }
nsCString& operator=( const char* aPtr ) { Assign(aPtr); return *this; }
nsCString& operator=( char aChar ) { Assign(aChar); return *this; }
#endif
void AssignWithConversion(const PRUnichar*,PRInt32=-1);
void AssignWithConversion( const nsString& aString );
#ifdef NEW_STRING_APIS
void AssignWithConversion( const nsAReadableString& aString );
#endif
void AssignWithConversion(PRUnichar);
#ifndef NEW_STRING_APIS
nsCString& Assign(const char* aString,PRInt32 aCount=-1);
nsCString& Assign(char aChar);
nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1);
//nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1) { AssignWithConversion(aString, aCount); return *this; }
//nsCString& Assign(PRUnichar aChar) { AssignWithConversion(aChar); return *this; }
/**
* here come a bunch of assignment operators...
* @param aString: string to be added to this
* @return this
*/
//nsCString& operator=(PRUnichar aChar) {AssignWithConversion(aChar); return *this;}
nsCString& operator=(char aChar) {return Assign(aChar);}
//nsCString& operator=(const PRUnichar* aString) {AssignWithConversion(aString); return *this;}
//nsCString& operator=(const nsStr& aString) {return Assign(aString);}
nsCString& operator=(const char* aCString) {return Assign(aCString);}
// Yes, I know this makes assignment from a |nsSubsumeString| not do the special thing
// |nsSubsumeString| needs to go away
#if defined(AIX) || defined(XP_OS2_VACPP)
nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX and VAC++ requires a const here
#else
nsCString& operator=(nsSubsumeCStr& aSubsumeString);
#endif
#endif
/*
* Appends n characters from given string to this,
*
@ -475,42 +332,13 @@ public:
void AppendWithConversion(const nsString&, PRInt32=-1);
void AppendWithConversion(PRUnichar aChar);
#ifdef NEW_STRING_APIS
void AppendWithConversion( const nsAReadableString& aString );
#endif
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 );
#ifdef NEW_STRING_APIS
virtual void do_AppendFromReadable( const nsAReadableCString& );
#endif
#ifndef NEW_STRING_APIS
//nsCString& Append(const nsStr& aString,PRInt32 aCount=-1);
nsCString& Append(const nsCString& aString,PRInt32 aCount);
nsCString& Append(const nsCString& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsCString& Append(const char* aString,PRInt32 aCount=-1);
nsCString& Append(char aChar);
//nsCString& Append(PRUnichar aChar) {AppendWithConversion(aChar); return *this;}
//nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10) {AppendInt(aInteger,aRadix); return *this;}
//nsCString& Append(float aFloat) {AppendFloat(aFloat); return *this;}
/**
* Here's a bunch of methods that append varying types...
* @param various...
* @return this
*/
nsCString& operator+=(const nsCString& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsCString& operator+=(const char* aCString) {return Append(aCString);}
//nsCString& operator+=(const PRUnichar aChar) {return Append(aChar);}
nsCString& operator+=(const char aChar) {return Append(aChar);}
//nsCString& operator+=(const int anInt) {return Append(anInt,10);}
#endif
/*
* Copies n characters from this string to given string,
* starting at the leftmost offset.
@ -548,57 +376,7 @@ public:
void InsertWithConversion(PRUnichar aChar,PRUint32 anOffset);
// Why no |InsertWithConversion(PRUnichar*)|?
#ifdef NEW_STRING_APIS
virtual void do_InsertFromReadable( const nsAReadableCString&, PRUint32 );
#endif
#ifndef NEW_STRING_APIS
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
* @param aCopy -- String to be inserted into this
* @param anOffset -- insertion position within this str
* @param aCount -- number of chars to be copied from aCopy
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
*
* @return number of chars inserted into this.
*/
void Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
/**
* Insert a given string into this string at
* a specified offset.
*
* @param aString* to be inserted into this string
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
void Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
/**
* Insert a single char into this string at
* a specified offset.
*
* @param character to be inserted into this string
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
//void Insert(PRUnichar aChar,PRUint32 anOffset) {InsertWithConversion(aChar,anOffset);}
void Insert(char aChar,PRUint32 anOffset);
#endif
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
* @param anOffset -- start pos for cut operation
* @param aCount -- number of chars to be cut
* @return *this
*/
#ifndef NEW_STRING_APIS
void Cut(PRUint32 anOffset,PRInt32 aCount);
#endif
/**********************************************************************
@ -699,96 +477,6 @@ public:
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const;
#ifndef NEW_STRING_APIS
//virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return CompareWithConversion(aString,aIgnoreCase,aCount);
//}
//virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return CompareWithConversion(aString,aIgnoreCase,aCount);
//}
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
/**
* Compare this to given string; note that we compare full strings here.
* The optional length argument just lets us know how long the given string is.
* If you provide a length, it is compared to length of this string as an
* optimization.
*
* @param aString -- the string to compare to this
* @param aCount -- number of chars in given string you want to compare
* @return TRUE if equal
*/
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
return EqualsWithConversion(aString,aIgnoreCase,aCount);
}
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
return EqualsWithConversion(aString,aIgnoreCase,aCount);
}
//PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return EqualsWithConversion(aString,aIgnoreCase,aCount);
//}
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const nsStr& aString) const;
/**
* These methods compare a given string type to this one
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator==(const nsStr &aString) const;
PRBool operator==(const char* aString) const;
//PRBool operator==(const PRUnichar* aString) const;
/**
* These methods perform a !compare of a given string type to this
* @param aString is the string to be compared to this
* @return TRUE
*/
PRBool operator!=(const nsStr &aString) const;
PRBool operator!=(const char* aString) const;
//PRBool operator!=(const PRUnichar* aString) const;
/**
* These methods test if a given string is < than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<(const nsStr &aString) const;
PRBool operator<(const char* aString) const;
//PRBool operator<(const PRUnichar* aString) const;
/**
* These methods test if a given string is > than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>(const nsStr &S) const;
PRBool operator>(const char* aString) const;
//PRBool operator>(const PRUnichar* aString) const;
/**
* These methods test if a given string is <= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<=(const nsStr &S) const;
PRBool operator<=(const char* aString) const;
//PRBool operator<=(const PRUnichar* aString) const;
/**
* These methods test if a given string is >= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>=(const nsStr &S) const;
PRBool operator>=(const char* aString) const;
//PRBool operator>=(const PRUnichar* aString) const;
#endif // !defined(NEW_STRING_APIS)
void DebugDump(void) const;
@ -799,28 +487,14 @@ public:
private:
// NOT TO BE IMPLEMENTED
// these signatures help clients not accidentally call the wrong thing helped by C++ automatic integral promotion
#ifdef NEW_STRING_APIS
void operator=( PRUnichar );
#endif
void AssignWithConversion( char );
void AssignWithConversion( const char*, PRInt32=-1 );
void AppendWithConversion( char );
void InsertWithConversion( char, PRUint32 );
};
#if 0 // #ifdef NEW_STRING_APIS
inline
nsPromiseConcatenation<char>
operator+( const nsPromiseConcatenation<char>& lhs, const nsCString& rhs )
{
return nsPromiseConcatenation<char>(lhs, rhs);
}
#endif
#ifdef NEW_STRING_APIS
NS_DEF_STRING_COMPARISON_OPERATORS(nsCString, char)
// NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsCString, char);
#endif
extern NS_COM int fputs(const nsCString& aString, FILE* out);
//ostream& operator<<(ostream& aStream,const nsCString& aString);
@ -839,27 +513,20 @@ public:
virtual ~nsCAutoString();
nsCAutoString();
nsCAutoString(const nsCString& );
nsCAutoString(const nsAReadableCString& aString);
nsCAutoString(const char* aString);
explicit nsCAutoString(const nsCString& );
explicit nsCAutoString(const nsAReadableCString& aString);
explicit nsCAutoString(const char* aString);
nsCAutoString(const char* aString,PRInt32 aLength);
nsCAutoString(const CBufDescriptor& aBuffer);
#ifndef NEW_STRING_APIS
// nsCAutoString(const PRUnichar* aString,PRInt32 aLength=-1);
// nsCAutoString(const nsStr& aString);
// nsCAutoString(PRUnichar aChar);
#endif
explicit nsCAutoString(const CBufDescriptor& aBuffer);
#if defined(AIX) || defined(XP_OS2_VACPP)
nsCAutoString(const nsSubsumeCStr& aSubsumeStr); // AIX and VAC++ require a const
explicit nsCAutoString(const nsSubsumeCStr& aSubsumeStr); // AIX and VAC++ require a const
#else
nsCAutoString(nsSubsumeCStr& aSubsumeStr);
explicit nsCAutoString(nsSubsumeCStr& aSubsumeStr);
#endif // AIX || XP_OS2_VACPP
nsCAutoString& operator=( const nsCAutoString& aString ) { Assign(aString); return *this; }
#ifdef NEW_STRING_APIS
private:
void operator=( PRUnichar ); // NOT TO BE IMPLEMENTED
public:
@ -867,13 +534,6 @@ public:
nsCAutoString& operator=( const nsPromiseReadable<char>& aReadable ) { Assign(aReadable); return *this; }
nsCAutoString& operator=( const char* aPtr ) { Assign(aPtr); return *this; }
nsCAutoString& operator=( char aChar ) { Assign(aChar); return *this; }
#else
nsCAutoString& operator=(const nsCString& aString) {nsCString::Assign(aString); return *this;}
nsCAutoString& operator=(const char* aCString) {nsCString::Assign(aCString); return *this;}
// nsCAutoString& operator=(const PRUnichar* aString) {nsCString::Assign(aString); return *this;}
// nsCAutoString& operator=(PRUnichar aChar) {nsCString::Assign(aChar); return *this;}
nsCAutoString& operator=(char aChar) {nsCString::Assign(aChar); return *this;}
#endif
/**
* Retrieve the size of this string
@ -884,14 +544,6 @@ public:
char mBuffer[kDefaultStringSize];
};
#if 0//def NEW_STRING_APIS
NS_DEF_STRING_COMPARISON_OPERATORS(nsCAutoString, char)
#endif
#ifdef NEW_STRING_APIS
NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsCAutoString, char)
#endif
/**
* A helper class that converts a UCS2 string to UTF8
*/
@ -902,6 +554,7 @@ class NS_COM NS_ConvertUCS2toUTF8
*/
{
public:
explicit
NS_ConvertUCS2toUTF8( const PRUnichar* aString )
{
Append( aString, ~PRUint32(0) /* MAXINT */);
@ -912,14 +565,13 @@ class NS_COM NS_ConvertUCS2toUTF8
Append( aString, aLength );
}
explicit
NS_ConvertUCS2toUTF8( PRUnichar aChar )
{
Append( &aChar, 1 );
}
#ifdef NEW_STRING_APIS
NS_ConvertUCS2toUTF8( const nsAReadableString& aString );
#endif
explicit NS_ConvertUCS2toUTF8( const nsAReadableString& aString );
operator const char*() const
{
@ -950,19 +602,17 @@ class NS_COM NS_ConvertUCS2toUTF8
***************************************************************/
class NS_COM nsSubsumeCStr : public nsCString {
public:
nsSubsumeCStr(nsStr& aString);
explicit nsSubsumeCStr(nsStr& aString);
nsSubsumeCStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
nsSubsumeCStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
nsSubsumeCStr& operator=( const nsSubsumeCStr& aString ) { Assign(aString); return *this; }
#ifdef NEW_STRING_APIS
nsSubsumeCStr& operator=( const nsAReadableCString& aReadable ) { Assign(aReadable); return *this; }
nsSubsumeCStr& operator=( const nsPromiseReadable<char>& aReadable ) { Assign(aReadable); return *this; }
nsSubsumeCStr& operator=( const char* aPtr ) { Assign(aPtr); return *this; }
nsSubsumeCStr& operator=( char aChar ) { Assign(aChar); return *this; }
private:
void operator=( PRUnichar ); // NOT TO BE IMPLEMENTED
#endif
};

View File

@ -17,10 +17,8 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author:
* Rick Gessner <rickg@netscape.com>
*
* Contributor(s):
* Rick Gessner <rickg@netscape.com> (original author)
* Scott Collins <scc@mozilla.org>
*/
@ -69,25 +67,10 @@ nsString::nsString() {
Initialize(*this,eTwoByte);
}
#if 0
/**
* 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
*/
nsString::nsString(const char* aCString,PRInt32 aCount){
Initialize(*this,eTwoByte);
AssignWithConversion(aCString,aCount);
}
#endif
#ifdef NEW_STRING_APIS
nsString::nsString(const PRUnichar* aString) {
Initialize(*this,eTwoByte);
Assign(aString);
}
#endif
/**
* This constructor accepts a unicode string
@ -100,18 +83,6 @@ nsString::nsString(const PRUnichar* aString,PRInt32 aCount) {
Assign(aString,aCount);
}
#if 0
/**
* This constructor works for all other nsSTr derivatives
* @update gess 1/4/99
* @param reference to another nsCString
*/
nsString::nsString(const nsStr &aString) {
Initialize(*this,eTwoByte);
StrAssign(*this,aString,0,aString.mLength);
}
#endif
/**
* This is our copy constructor
* @update gess 1/4/99
@ -149,7 +120,6 @@ nsString::~nsString() {
nsStr::Destroy(*this);
}
#ifdef NEW_STRING_APIS
const PRUnichar* nsString::GetReadableFragment( nsReadableFragment<PRUnichar>& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const {
switch ( aRequest ) {
case kFirstFragment:
@ -199,7 +169,6 @@ nsString::nsString( const nsAReadableString& aReadable ) {
Initialize(*this,eTwoByte);
Assign(aReadable);
}
#endif
void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
if (aResult) {
@ -275,36 +244,6 @@ const PRUnichar* nsString::GetUnicode(void) const {
return result;
}
#ifndef NEW_STRING_APIS
/**
* Get nth character.
*/
PRUnichar nsString::operator[](PRUint32 anIndex) const {
return GetCharAt(*this,anIndex);
}
/**
* Get nth character.
*/
PRUnichar nsString::CharAt(PRUint32 anIndex) const {
return GetCharAt(*this,anIndex);
}
/**
* Get 1st character.
*/
PRUnichar nsString::First(void) const{
return GetCharAt(*this,0);
}
/**
* Get last character.
*/
PRUnichar nsString::Last(void) const{
return GetCharAt(*this,mLength-1);
}
#endif // !defined(NEW_STRING_APIS)
/**
* set a char inside this string at given index
* @param aChar is the char you want to write into this string
@ -330,81 +269,6 @@ PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
append (operator+) METHODS....
*********************************************************/
#ifndef NEW_STRING_APIS
/**
* Create a new string by appending given string to this
* @update gess 01/04/99
* @param aString -- 2nd string to be appended
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(const nsStr& aString){
nsString temp(*this); //make a temp string the same size as this...
nsStr::StrAppend(temp,aString,0,aString.mLength);
return nsSubsumeStr(temp);
}
/**
* Create a new string by appending given string to this
* @update gess 01/04/99
* @param aString -- 2nd string to be appended
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(const nsString& aString){
nsString temp(*this); //make a temp string the same size as this...
nsStr::StrAppend(temp,aString,0,aString.mLength);
return nsSubsumeStr(temp);
}
/**
* create a new string by adding this to the given buffer.
* @update gess 01/04/99
* @param aCString is a ptr to cstring to be added to this
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(const char* aCString) {
nsString temp(*this);
temp.AppendWithConversion(aCString);
return nsSubsumeStr(temp);
}
/**
* create a new string by adding this to the given char.
* @update gess 01/04/99
* @param aChar is a char to be added to this
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(char aChar) {
nsString temp(*this);
temp.Append(char(aChar));
return nsSubsumeStr(temp);
}
/**
* create a new string by adding this to the given buffer.
* @update gess 01/04/99
* @param aString is a ptr to unistring to be added to this
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(const PRUnichar* aString) {
nsString temp(*this);
temp.Append(aString);
return nsSubsumeStr(temp);
}
/**
* create a new string by adding this to the given char.
* @update gess 01/04/99
* @param aChar is a unichar to be added to this
* @return new subsumeable string (this makes things faster by reducing copying)
*/
nsSubsumeStr nsString::operator+(PRUnichar aChar) {
nsString temp(*this);
temp.Append(char(aChar));
return nsSubsumeStr(temp);
}
#endif // !defined(NEW_STRING_APIS)
/**********************************************************************
Lexomorphic transforms...
@ -952,26 +816,6 @@ PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
*********************************************************************/
#ifndef NEW_STRING_APIS
/**
* assign given nsStr (or derivative) to this one
* @update gess 01/04/99
* @param aString: nsStr to be appended
* @return this
*/
nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
if(this!=&aString){
nsStr::Truncate(*this,0);
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
StrAssign(*this,aString,0,aCount);
}
return *this;
}
#endif
/**
* assign given char* to this string
@ -989,33 +833,13 @@ void nsString::AssignWithConversion(const char* aCString,PRInt32 aCount) {
}
}
#ifdef NEW_STRING_APIS
void nsString::AssignWithConversion(const char* aCString) {
nsStr::Truncate(*this,0);
if(aCString){
AppendWithConversion(aCString);
}
}
#endif
#ifndef NEW_STRING_APIS
/**
* assign given unichar* to this string
* @update gess 01/04/99
* @param aString: 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
*/
nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
nsStr::Truncate(*this,0);
if(aString){
Append(aString,aCount);
}
return *this;
}
#endif
/**
* assign given char to this string
@ -1028,39 +852,6 @@ void nsString::AssignWithConversion(char aChar) {
AppendWithConversion(aChar);
}
#ifndef NEW_STRING_APIS
/**
* assign given unichar to this string
* @update gess 01/04/99
* @param aChar: char to be assignd to this
* @return this
*/
nsString& nsString::Assign(PRUnichar aChar) {
nsStr::Truncate(*this,0);
return Append(aChar);
}
#endif
#ifndef NEW_STRING_APIS
/**
* WARNING! THIS IS A VERY SPECIAL METHOD.
* This method "steals" the contents of aSource and hands it to aDest.
* Ordinarily a copy is made, but not in this version.
* @update gess10/30/98
* @param
* @return
*/
#if defined(AIX) || defined(XP_OS2_VACPP)
nsString& nsString::operator=(const nsSubsumeStr& aSubsumeString) {
nsSubsumeStr temp(aSubsumeString); // a temp is needed for the AIX and VAC++ compilers
Subsume(*this,temp);
#else
nsString& nsString::operator=(nsSubsumeStr& aSubsumeString) {
Subsume(*this,aSubsumeString);
#endif // AIX || XP_OS2_VACPP
return *this;
}
#endif
/**
* append given c-string to this string
@ -1169,96 +960,6 @@ void nsString::AppendFloat(double aFloat){
}
#ifndef NEW_STRING_APIS
/**
* append given string to this string;
* @update gess 01/04/99
* @param aString : string to be appended to this
* @return this
*/
#if 0
nsString& nsString::Append(const nsStr& aString,PRInt32 aCount) {
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
StrAppend(*this,aString,0,aCount);
return *this;
}
#endif
/**
* append given string to this string
* I don't think we need this method now that we have the previous one.
* @update gess 01/04/99
* @param aString : string to be appended to this
* @return this
*/
nsString& nsString::Append(const nsString& aString,PRInt32 aCount) {
if(aCount<0)
aCount=aString.mLength;
else aCount=MinInt(aCount,aString.mLength);
if(0<aCount)
StrAppend(*this,aString,0,aCount);
return *this;
}
/**
* append given unicode string to this
* @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
*/
nsString& nsString::Append(const PRUnichar* aString,PRInt32 aCount) {
if(aString && aCount){ //if astring is null or count==0 there's nothing to do
nsStr temp;
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=(PRUnichar*)aString;
if(0<aCount) {
temp.mLength=aCount;
// If this assertion fires, the caller is probably lying about the length of
// the passed-in string. File a bug on the caller.
#ifdef NS_DEBUG
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
if(kNotFound<len) {
NS_WARNING(kPossibleNull);
}
#endif
}
else aCount=temp.mLength=nsCRT::strlen(aString);
if(0<aCount)
StrAppend(*this,temp,0,aCount);
}
return *this;
}
/**
* append given unichar to this string
* @update gess 01/04/99
* @param aChar: char to be appended to this
* @return this
*/
nsString& nsString::Append(PRUnichar aChar) {
PRUnichar buf[2]={0,0};
buf[0]=aChar;
nsStr temp;
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=buf;
temp.mLength=1;
StrAppend(*this,temp,0,1);
return *this;
}
#endif
/*
* Copies n characters from this left of this string to given string,
@ -1349,98 +1050,8 @@ void nsString::InsertWithConversion(const char* aCString,PRUint32 anOffset,PRInt
}
}
#ifndef NEW_STRING_APIS
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
* @update gess 4/1/98
* @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
*/
void nsString::Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) {
StrInsert(*this,anOffset,aCopy,0,aCount);
}
/**
* Insert a unicode* into this string at a specified offset.
*
* @update gess4/22/98
* @param aChar char to be inserted into this string
* @param anOffset is insert pos in str
* @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::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aCount){
if(aString && aCount){
nsStr temp;
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=(PRUnichar*)aString;
if(0<aCount) {
temp.mLength=aCount;
// If this assertion fires, the caller is probably lying about the length of
// the passed-in string. File a bug on the caller.
#ifdef NS_DEBUG
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
if(kNotFound<len) {
NS_WARNING(kPossibleNull);
}
#endif
}
else aCount=temp.mLength=nsCRT::strlen(aString);
if(0<aCount){
StrInsert(*this,anOffset,temp,0,aCount);
}
}
}
/**
* Insert a single uni-char into this string at
* a specified offset.
*
* @update gess4/22/98
* @param aChar char to be inserted into this string
* @param anOffset is insert pos in str
* @return this
*/
void nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
PRUnichar theBuffer[2]={0,0};
theBuffer[0]=aChar;
nsStr temp;
nsStr::Initialize(temp,eTwoByte);
temp.mUStr=theBuffer;
temp.mLength=1;
StrInsert(*this,anOffset,temp,0,1);
}
#endif
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
* @update gess 01/04/99
* @param anOffset -- start pos for cut operation
* @param aCount -- number of chars to be cut
* @return *this
*/
#ifndef NEW_STRING_APIS
void nsString::Cut(PRUint32 anOffset, PRInt32 aCount) {
if(0<aCount) {
nsStr::Delete(*this,anOffset,aCount);
}
}
#endif
/**********************************************************************
Searching methods...
*********************************************************************/
@ -1823,55 +1434,7 @@ PRInt32 nsString::CompareWithConversion(const PRUnichar* aString,PRBool aIgnoreC
return 0;
}
#ifndef NEW_STRING_APIS
/**
* Compare given nsStr with this cstring.
*
* @param aString is an nsStr instance to be compared
* @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::Compare(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
return nsStr::StrCompare(*this,aString,aCount,aIgnoreCase);
}
#endif
#ifndef NEW_STRING_APIS
/**
* Here come a whole bunch of operator functions that are self-explanatory...
*/
PRBool nsString::operator==(const nsString& S) const {return Equals(S);}
//PRBool nsString::operator==(const nsStr& S) const {return Equals(S);}
//PRBool nsString::operator==(const char* s) const {return Equals(s);}
PRBool nsString::operator==(const PRUnichar* s) const {return Equals(nsAutoString(s));}
PRBool nsString::operator!=(const nsString& S) const {return PRBool(Compare(S)!=0);}
//PRBool nsString::operator!=(const nsStr& S) const {return PRBool(Compare(S)!=0);}
//PRBool nsString::operator!=(const char* s) const {return PRBool(Compare(s)!=0);}
PRBool nsString::operator!=(const PRUnichar* s) const {return PRBool(Compare(nsAutoString(s))!=0);}
PRBool nsString::operator<(const nsString& S) const {return PRBool(Compare(S)<0);}
//PRBool nsString::operator<(const nsStr& S) const {return PRBool(Compare(S)<0);}
//PRBool nsString::operator<(const char* s) const {return PRBool(Compare(s)<0);}
PRBool nsString::operator<(const PRUnichar* s) const {return PRBool(Compare(nsAutoString(s))<0);}
PRBool nsString::operator>(const nsString& S) const {return PRBool(Compare(S)>0);}
//PRBool nsString::operator>(const nsStr& S) const {return PRBool(Compare(S)>0);}
//PRBool nsString::operator>(const char* s) const {return PRBool(Compare(s)>0);}
PRBool nsString::operator>(const PRUnichar* s) const {return PRBool(Compare(nsAutoString(s))>0);}
PRBool nsString::operator<=(const nsString& S) const {return PRBool(Compare(S)<=0);}
//PRBool nsString::operator<=(const nsStr& S) const {return PRBool(Compare(S)<=0);}
//PRBool nsString::operator<=(const char* s) const {return PRBool(Compare(s)<=0);}
PRBool nsString::operator<=(const PRUnichar* s) const {return PRBool(Compare(nsAutoString(s))<=0);}
PRBool nsString::operator>=(const nsString& S) const {return PRBool(Compare(S)>=0);}
//PRBool nsString::operator>=(const nsStr& S) const {return PRBool(Compare(S)>=0);}
//PRBool nsString::operator>=(const char* s) const {return PRBool(Compare(s)>=0);}
PRBool nsString::operator>=(const PRUnichar* s) const {return PRBool(Compare(nsAutoString(s))>=0);}
#endif // !defined(NEW_STRING_APIS)
PRBool nsString::EqualsIgnoreCase(const nsString& aString) const {
return EqualsWithConversion(aString,PR_TRUE);
@ -1881,12 +1444,6 @@ PRBool nsString::EqualsIgnoreCase(const char* aString,PRInt32 aLength) const {
return EqualsWithConversion(aString,PR_TRUE,aLength);
}
#ifndef NEW_STRING_APIS
PRBool nsString::EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const {
return Equals(s1,s2,PR_TRUE);
}
#endif
/**
* Compare this to given string; note that we compare full strings here.
*
@ -1963,40 +1520,6 @@ PRBool nsString::EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const {
return EqualsAtom(aAtom,PR_TRUE);
}
#ifndef NEW_STRING_APIS
/**
* Compare this to given string; note that we compare full strings here.
*
* @update gess 01/04/99
* @param aString is the other nsString to be compared to
* @param aCount tells us how many chars to test; -1 implies full length
* @return TRUE if equal
*/
PRBool nsString::Equals(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
PRInt32 theAnswer=nsStr::StrCompare(*this,aString,aCount,aIgnoreCase);
PRBool result=PRBool(0==theAnswer);
return result;
}
/**
* Compare given strings
* @update gess 7/27/98
* @param s1 -- first unichar string to be compared
* @param s2 -- second unichar string to be compared
* @return TRUE if equal
*/
PRBool nsString::Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase) const {
NS_ASSERTION(0!=s1,kNullPointerError);
NS_ASSERTION(0!=s2,kNullPointerError);
PRBool result=PR_FALSE;
if((s1) && (s2)){
PRInt32 cmp=(aIgnoreCase) ? nsCRT::strcasecmp(s1,s2) : nsCRT::strcmp(s1,s2);
result=PRBool(0==cmp);
}
return result;
}
#endif
/**
* Determine if given char in valid alpha range
@ -2321,21 +1844,6 @@ NS_ConvertASCIItoUCS2::NS_ConvertASCIItoUCS2( char aChar )
AppendWithConversion(aChar);
}
#if 0
#ifdef NEW_STRING_APIS
NS_ConvertASCIItoUCS2::NS_ConvertASCIItoUCS2( const nsAReadableCString& )
{
// ...
}
#else
NS_ConvertASCIItoUCS2::NS_ConvertASCIItoUCS2( const nsCString& )
{
// ...
}
#endif
#endif
void
NS_ConvertUTF8toUCS2::Init( const char* aCString, PRUint32 aLength )
{

View File

@ -17,10 +17,8 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author:
* Rick Gessner <rickg@netscape.com>
*
* Contributor(s):
* Rick Gessner <rickg@netscape.com> (original author)
* Scott Collins <scc@mozilla.org>
*/
@ -39,16 +37,6 @@
4. Subsumable strings
***********************************************************************/
#ifndef NEW_STRING_APIS
#define NEW_STRING_APIS 1
#endif //NEW_STRING_APIS
// Need this to enable comparison profiling for a while
#ifdef OLD_STRING_APIS
#undef NEW_STRING_APIS
#endif
#ifndef _nsString_
#define _nsString_
@ -60,9 +48,7 @@
#include "nsStr.h"
#include "nsCRT.h"
#ifdef NEW_STRING_APIS
#include "nsAWritableString.h"
#endif
#ifdef STANDALONE_MI_STRING_TESTS
class nsAReadableString { public: virtual ~nsAReadableString() { } };
@ -78,17 +64,13 @@ class nsISizeOfHandler;
class NS_COM nsSubsumeStr;
class NS_COM nsString :
#if defined(NEW_STRING_APIS) || defined(STANDALONE_MI_STRING_TESTS)
public nsAWritableString,
#endif
public nsStr {
#ifdef NEW_STRING_APIS
protected:
virtual const void* Implementation() const { return "nsString"; }
virtual const PRUnichar* GetReadableFragment( nsReadableFragment<PRUnichar>&, nsFragmentRequest, PRUint32 ) const;
virtual PRUnichar* GetWritableFragment( nsWritableFragment<PRUnichar>&, nsFragmentRequest, PRUint32 );
#endif
public:
@ -103,30 +85,10 @@ public:
*/
nsString(const nsString& aString);
#ifdef NEW_STRING_APIS
explicit nsString(const nsAReadableString&);
nsString(const PRUnichar*);
explicit nsString(const PRUnichar*);
nsString(const PRUnichar*, PRInt32);
#else
/**
* This constructor accepts a unichar string
* @param aCString is a ptr to a 2-byte cstr
*/
nsString(const PRUnichar* aString,PRInt32 aCount=-1);
/**
* This constructor accepts an isolatin string
* @param aCString is a ptr to a 1-byte cstr
*/
//nsString(const char* aCString,PRInt32 aCount=-1);
/**
* This is a copy constructor that accepts an nsStr
* @param reference to another nsString
*/
//nsString(const nsStr&);
#endif
/**
@ -134,9 +96,9 @@ public:
* @param reference to subsumestr
*/
#if defined(AIX) || defined(XP_OS2_VACPP)
nsString(const nsSubsumeStr& aSubsumeStr); // AIX and VAC++ require a const here
explicit nsString(const nsSubsumeStr& aSubsumeStr); // AIX and VAC++ require a const here
#else
nsString(nsSubsumeStr& aSubsumeStr);
explicit nsString(nsSubsumeStr& aSubsumeStr);
#endif
/**
@ -198,17 +160,6 @@ public:
return result;
}
#ifndef NEW_STRING_APIS
/**
* Determine whether or not this string has a length of 0
*
* @return TRUE if empty.
*/
PRBool IsEmpty(void) const {
return PRBool(0==mLength);
}
#endif
/**********************************************************************
Getters/Setters...
*********************************************************************/
@ -219,63 +170,12 @@ public:
const char* GetBuffer(void) const;
const PRUnichar* GetUnicode(void) const;
#ifndef NEW_STRING_APIS
/**
* Get nth character.
*/
PRUnichar operator[](PRUint32 anIndex) const;
PRUnichar CharAt(PRUint32 anIndex) const;
PRUnichar First(void) const;
PRUnichar Last(void) const;
#endif // !defined(NEW_STRING_APIS)
/**
* Set nth character.
*/
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
#ifndef NEW_STRING_APIS
/**********************************************************************
String concatenation methods...
*********************************************************************/
/**
* Create a new string by appending given string to this
* @param aString -- 2nd string to be appended
* @return new subsumable string
*/
nsSubsumeStr operator+(const nsStr& aString);
nsSubsumeStr operator+(const nsString& aString);
/**
* create a new string by adding this to the given cstring
* @param aCString is a ptr to cstring to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(const char* aCString);
/**
* create a new string by adding this to the given prunichar*.
* @param aString is a ptr to UC-string to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(const PRUnichar* aString);
/**
* create a new string by adding this to the given char.
* @param aChar is a char to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(char aChar);
/**
* create a new string by adding this to the given char.
* @param aChar is a unichar to be added to this
* @return newly created string
*/
nsSubsumeStr operator+(PRUnichar aChar);
#endif
/**********************************************************************
Lexomorphic transforms...
@ -449,47 +349,14 @@ public:
*/
nsString& operator=( const nsString& aString ) { Assign(aString); return *this; }
#ifdef NEW_STRING_APIS
nsString& operator=( const nsAReadableString& aReadable ) { Assign(aReadable); return *this; }
nsString& operator=( const nsPromiseReadable<PRUnichar>& aReadable ) { Assign(aReadable); return *this; }
nsString& operator=( const PRUnichar* aPtr ) { Assign(aPtr); return *this; }
nsString& operator=( PRUnichar aChar ) { Assign(aChar); return *this; }
#endif
void AssignWithConversion(char);
#ifdef NEW_STRING_APIS
void AssignWithConversion(const char*);
void AssignWithConversion(const char*, PRInt32);
#else
void AssignWithConversion(const char*, PRInt32=-1);
nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Assign(PRUnichar aChar);
nsString& Assign(const nsStr& aString,PRInt32 aCount=-1);
//nsString& Assign(const char* aString,PRInt32 aCount=-1) { AssignWithConversion(aString, aCount); return *this; }
//nsString& Assign(char aChar) { AssignWithConversion(aChar); return *this; }
/**
* here come a bunch of assignment operators...
* @param aString: string to be added to this
* @return this
*/
nsString& operator=(PRUnichar aChar) {Assign(aChar); return *this;}
//nsString& operator=(char aChar) {AssignWithConversion(aChar); return *this;}
//nsString& operator=(const char* aCString) {AssignWithConversion(aCString); return *this;}
//nsString& operator=(const nsStr& aString) {return Assign(aString);}
nsString& operator=(const PRUnichar* aString) {return Assign(aString);}
// Yes, I know this makes assignment from a |nsSubsumeString| not do the special thing
// |nsSubsumeString| needs to go away
#if defined(AIX) || defined(XP_OS2_VACPP)
nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX and VAC++ requires a const here
#else
nsString& operator=(nsSubsumeStr& aSubsumeString);
#endif
#endif
/*
@ -507,42 +374,6 @@ public:
virtual void do_AppendFromElement( PRUnichar );
#ifndef NEW_STRING_APIS
/*
* 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
*/
//nsString& Append(const nsStr& aString,PRInt32 aCount);
//nsString& Append(const nsStr& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsString& Append(const nsString& aString,PRInt32 aCount);
nsString& Append(const nsString& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1);
nsString& Append(PRUnichar aChar);
//nsString& Append(const char* aString,PRInt32 aCount=-1) { AppendWithConversion(aString,aCount); return *this; }
//nsString& Append(char aChar) { AppendWithConversion(aChar); return *this; }
//nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10) { AppendInt(aInteger,aRadix); return *this; }
//nsString& Append(float aFloat) { AppendFloat(aFloat); return *this; }
/**
* Here's a bunch of methods that append varying types...
* @param various...
* @return this
*/
//nsString& operator+=(const char* aCString) {return Append(aCString);}
//nsString& operator+=(const char aChar) {return Append((PRUnichar) (unsigned char)aChar);}
nsString& operator+=(const PRUnichar aChar) {return Append(aChar);}
//nsString& operator+=(const int anInt) {return Append(anInt,10);}
//nsString& operator+=(const nsStr& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsString& operator+=(const nsString& aString) {return Append(aString,(PRInt32)aString.mLength);}
nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);}
#endif
/*
* Copies n characters from this string to given string,
@ -581,55 +412,6 @@ public:
//void InsertWithConversion(char);
void InsertWithConversion(const char*, PRUint32, PRInt32=-1);
#ifndef NEW_STRING_APIS
/*
* This method inserts n chars from given string into this
* string at str[anOffset].
*
* @param aCopy -- String to be inserted into this
* @param anOffset -- insertion position within this str
* @param aCount -- number of chars to be copied from aCopy
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
*
* @return number of chars inserted into this.
*/
void Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
/**
* Insert a given string into this string at
* a specified offset.
*
* @param aString* to be inserted into this string
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
//nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1) {InsertWithConversion(aChar, anOffset, aCount); return *this;}
void Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
/**
* Insert a single char into this string at
* a specified offset.
*
* @param character to be inserted into this string
* @param anOffset is insert pos in str
* @return the number of chars inserted into this string
*/
//nsString& Insert(char aChar,PRUint32 anOffset) {InsertWithConversion(aChar,anOffset); return *this;}
void Insert(PRUnichar aChar,PRUint32 anOffset);
#endif
#ifndef NEW_STRING_APIS
/*
* This method is used to cut characters in this string
* starting at anOffset, continuing for aCount chars.
*
* @param anOffset -- start pos for cut operation
* @param aCount -- number of chars to be cut
* @return *this
*/
void Cut(PRUint32 anOffset,PRInt32 aCount);
#endif
/**********************************************************************
@ -739,110 +521,6 @@ public:
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const;
#ifndef NEW_STRING_APIS
//virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return CompareWithConversion(aString,aIgnoreCase,aCount);
//}
//virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return CompareWithConversion(aString,aIgnoreCase,aCount);
//}
//virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return CompareWithConversion(aString,aIgnoreCase,aCount);
//}
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
/**
* Compare this to given string; note that we compare full strings here.
* The optional length argument just lets us know how long the given string is.
* If you provide a length, it is compared to length of this string as an
* optimization.
*
* @param aString -- the string to compare to this
* @param aCount -- number of chars to be compared.
* @return TRUE if equal
*/
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
return EqualsWithConversion(aString,aIgnoreCase,aCount);
}
//PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
// return EqualsWithConversion(aString,aIgnoreCase,aCount);
//}
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
return EqualsWithConversion(aString,aIgnoreCase,aCount);
}
//PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const { return EqualsAtom(anAtom, aIgnoreCase); }
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const;
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
/**
* These methods compare a given string type to this one
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator==(const nsString &aString) const;
//PRBool operator==(const nsStr &aString) const;
//PRBool operator==(const char *aString) const;
PRBool operator==(const PRUnichar* aString) const;
/**
* These methods perform a !compare of a given string type to this
* @param aString is the string to be compared to this
* @return TRUE
*/
PRBool operator!=(const nsString &aString) const;
//PRBool operator!=(const nsStr &aString) const;
//PRBool operator!=(const char* aString) const;
PRBool operator!=(const PRUnichar* aString) const;
/**
* These methods test if a given string is < than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<(const nsString &aString) const;
//PRBool operator<(const nsStr &aString) const;
//PRBool operator<(const char* aString) const;
PRBool operator<(const PRUnichar* aString) const;
/**
* These methods test if a given string is > than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>(const nsString &aString) const;
//PRBool operator>(const nsStr &S) const;
//PRBool operator>(const char* aString) const;
PRBool operator>(const PRUnichar* aString) const;
/**
* These methods test if a given string is <= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator<=(const nsString &aString) const;
//PRBool operator<=(const nsStr &S) const;
//PRBool operator<=(const char* aString) const;
PRBool operator<=(const PRUnichar* aString) const;
/**
* These methods test if a given string is >= than this
* @param aString is the string to be compared to this
* @return TRUE or FALSE
*/
PRBool operator>=(const nsString &aString) const;
//PRBool operator>=(const nsStr &S) const;
//PRBool operator>=(const char* aString) const;
PRBool operator>=(const PRUnichar* aString) const;
#endif // !defined(NEW_STRING_APIS)
/**
* Determine if given buffer is plain ascii
@ -884,9 +562,7 @@ public:
private:
// NOT TO BE IMPLEMENTED
// these signatures help clients not accidentally call the wrong thing helped by C++ automatic integral promotion
#ifdef NEW_STRING_APIS
void operator=( char );
#endif
void AssignWithConversion( PRUnichar );
void AssignWithConversion( const PRUnichar*, PRInt32=-1 );
void AppendWithConversion( PRUnichar );
@ -894,19 +570,7 @@ private:
void InsertWithConversion( const PRUnichar*, PRUint32, PRInt32=-1 );
};
#ifdef NEW_STRING_APIS
NS_DEF_STRING_COMPARISON_OPERATORS(nsString, PRUnichar)
// NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsString, PRUnichar)
#endif
#if 0 // #ifdef NEW_STRING_APIS
inline
nsPromiseConcatenation<PRUnichar>
operator+( const nsPromiseConcatenation<PRUnichar>& lhs, const nsString& rhs )
{
return nsPromiseConcatenation<PRUnichar>(lhs, rhs);
}
#endif
extern NS_COM int fputs(const nsString& aString, FILE* out);
//ostream& operator<<(ostream& aStream,const nsString& aString);
@ -924,27 +588,21 @@ public:
virtual ~nsAutoString();
nsAutoString();
nsAutoString(const nsAutoString& aString);
nsAutoString(const nsAReadableString& aString);
nsAutoString(const nsString& aString);
nsAutoString(const PRUnichar* aString);
explicit nsAutoString(const nsAReadableString& aString);
explicit nsAutoString(const nsString& aString);
explicit nsAutoString(const PRUnichar* aString);
nsAutoString(const PRUnichar* aString,PRInt32 aLength);
nsAutoString(PRUnichar aChar);
nsAutoString(const CBufDescriptor& aBuffer);
#ifndef NEW_STRING_APIS
// nsAutoString(const char* aCString,PRInt32 aLength=-1);
// nsAutoString(const nsStr& aString);
#endif
explicit nsAutoString(PRUnichar aChar);
explicit nsAutoString(const CBufDescriptor& aBuffer);
#if defined(AIX) || defined(XP_OS2_VACPP)
nsAutoString(const nsSubsumeStr& aSubsumeStr); // AIX and VAC++ requires a const
explicit nsAutoString(const nsSubsumeStr& aSubsumeStr); // AIX and VAC++ requires a const
#else
nsAutoString(nsSubsumeStr& aSubsumeStr);
explicit nsAutoString(nsSubsumeStr& aSubsumeStr);
#endif // AIX || XP_OS2_VACPP
nsAutoString& operator=( const nsAutoString& aString ) { Assign(aString); return *this; }
#ifdef NEW_STRING_APIS
private:
void operator=( char ); // NOT TO BE IMPLEMENTED
public:
@ -952,13 +610,6 @@ public:
nsAutoString& operator=( const nsPromiseReadable<PRUnichar>& aReadable ) { Assign(aReadable); return *this; }
nsAutoString& operator=( const PRUnichar* aPtr ) { Assign(aPtr); return *this; }
nsAutoString& operator=( PRUnichar aChar ) { Assign(aChar); return *this; }
#else
nsAutoString& operator=(const nsStr& aString) {nsString::Assign(aString); return *this;}
// nsAutoString& operator=(const char* aCString) {nsString::Assign(aCString); return *this;}
// nsAutoString& operator=(char aChar) {nsString::Assign(aChar); return *this;}
nsAutoString& operator=(const PRUnichar* aBuffer) {nsString::Assign(aBuffer); return *this;}
nsAutoString& operator=(PRUnichar aChar) {nsString::Assign(aChar); return *this;}
#endif
/**
* Retrieve the size of this string
@ -969,10 +620,6 @@ public:
char mBuffer[kDefaultStringSize<<eTwoByte];
};
#ifdef NEW_STRING_APIS
NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsAutoString, PRUnichar)
#endif
class NS_COM NS_ConvertASCIItoUCS2
: public nsAutoString
/*
@ -980,19 +627,10 @@ class NS_COM NS_ConvertASCIItoUCS2
*/
{
public:
NS_ConvertASCIItoUCS2( const char* );
explicit NS_ConvertASCIItoUCS2( const char* );
NS_ConvertASCIItoUCS2( const char*, PRUint32 );
NS_ConvertASCIItoUCS2( char );
#if 0
#ifdef NEW_STRING_APIS
NS_ConvertASCIItoUCS2( const nsAReadableCString& );
#else
class nsCString;
NS_ConvertASCIItoUCS2( const nsCString& );
#endif
#endif
explicit NS_ConvertASCIItoUCS2( char );
#ifdef NEW_STRING_APIS
operator const PRUnichar*() const
{
return GetUnicode();
@ -1002,7 +640,6 @@ class NS_COM NS_ConvertASCIItoUCS2
{
return nsLiteralString(mUStr, mLength);
}
#endif
private:
// NOT TO BE IMPLEMENTED
@ -1036,6 +673,7 @@ class NS_COM NS_ConvertUTF8toUCS2
: public nsAutoString
{
public:
explicit
NS_ConvertUTF8toUCS2( const char* aCString )
{
Init( aCString, ~PRUint32(0) /* MAXINT */ );
@ -1046,6 +684,7 @@ class NS_COM NS_ConvertUTF8toUCS2
Init( aCString, aLength );
}
explicit
NS_ConvertUTF8toUCS2( char aChar )
{
Init( &aChar, 1 );
@ -1079,20 +718,18 @@ class NS_COM NS_ConvertUTF8toUCS2
class NS_COM nsSubsumeStr : public nsString {
public:
nsSubsumeStr();
nsSubsumeStr(nsStr& aString);
explicit nsSubsumeStr(nsStr& aString);
nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
int Subsume(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
nsSubsumeStr& operator=( const nsSubsumeStr& aReadable ) { Assign(aReadable); return *this; }
#ifdef NEW_STRING_APIS
nsSubsumeStr& operator=( const nsAReadableString& aReadable ) { Assign(aReadable); return *this; }
nsSubsumeStr& operator=( const nsPromiseReadable<PRUnichar>& aReadable ) { Assign(aReadable); return *this; }
nsSubsumeStr& operator=( const PRUnichar* aPtr ) { Assign(aPtr); return *this; }
nsSubsumeStr& operator=( PRUnichar aChar ) { Assign(aChar); return *this; }
private:
void operator=( char ); // NOT TO BE IMPLEMENTED
#endif
};