Conditionally enable the new string APIs. Don't worry, they're not turned on yet. All changes r=waterson. Changes that effect |nsString| unconditionally, r=rickg.
git-svn-id: svn://10.0.0.236/trunk@63813 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -285,7 +285,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount){
|
||||
* @param aDestOffset is where in aDest truncation is to occur
|
||||
*/
|
||||
void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
if(aDestOffset<aDest.mCapacity){
|
||||
aDest.mLength=aDestOffset;
|
||||
AddNullTerminator(aDest);
|
||||
NSSTR_SEEN(aDest);
|
||||
|
||||
@@ -40,7 +40,6 @@ static const char* kNullPointerError = "Error: unexpected null ptr";
|
||||
static const char* kWhitespace="\b\t\r\n ";
|
||||
|
||||
|
||||
|
||||
static void CSubsume(nsStr& aDest,nsStr& aSource){
|
||||
if(aSource.mStr && aSource.mLength) {
|
||||
if(aSource.mOwnsBuffer){
|
||||
@@ -126,6 +125,47 @@ nsCString::~nsCString() {
|
||||
nsStr::Destroy(*this);
|
||||
}
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
const char* nsCString::GetConstFragment( ConstFragment& aFragment, FragmentRequest aRequest, PRUint32 aOffset ) const {
|
||||
switch ( aRequest ) {
|
||||
case kFirstFragment:
|
||||
case kLastFragment:
|
||||
case kFragmentAt:
|
||||
aFragment.mEnd = (aFragment.mStart = mStr) + mLength;
|
||||
return aFragment.mStart + aOffset;
|
||||
|
||||
case kPrevFragment:
|
||||
case kNextFragment:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
char* nsCString::GetFragment( Fragment& aFragment, FragmentRequest aRequest, PRUint32 aOffset ) {
|
||||
switch ( aRequest ) {
|
||||
case kFirstFragment:
|
||||
case kLastFragment:
|
||||
case kFragmentAt:
|
||||
aFragment.mEnd = (aFragment.mStart = mStr) + mLength;
|
||||
return aFragment.mStart + aOffset;
|
||||
|
||||
case kPrevFragment:
|
||||
case kNextFragment:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
nsCString::nsCString( const nsAReadableCString& aReadable ) {
|
||||
nsStr::Initialize(*this,eOneByte);
|
||||
Assign(aReadable);
|
||||
}
|
||||
#endif
|
||||
|
||||
void nsCString::AppendChar( char aChar ) {
|
||||
Append(aChar);
|
||||
}
|
||||
|
||||
void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||
if (aResult) {
|
||||
*aResult = sizeof(*this) + mCapacity * mCharSize;
|
||||
@@ -139,7 +179,9 @@ void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||
* @param anIndex -- new length of string
|
||||
* @return nada
|
||||
*/
|
||||
void nsCString::Truncate(PRUint32 anIndex) {
|
||||
void nsCString::SetLength(PRUint32 anIndex) {
|
||||
if ( anIndex > mCapacity )
|
||||
SetCapacity(anIndex);
|
||||
nsStr::Truncate(*this,anIndex);
|
||||
}
|
||||
|
||||
@@ -160,7 +202,7 @@ void nsCString::SetCapacity(PRUint32 aLength) {
|
||||
Accessor methods...
|
||||
*********************************************************************/
|
||||
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* Retrieves internal (1-byte) buffer ptr;
|
||||
* @update gess1/4/99
|
||||
@@ -197,6 +239,7 @@ PRUnichar nsCString::First(void) const{
|
||||
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
|
||||
@@ -217,7 +260,7 @@ 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
|
||||
@@ -267,7 +310,7 @@ nsSubsumeCStr nsCString::operator+(char aChar) {
|
||||
temp.Append(aChar);
|
||||
return nsSubsumeCStr(temp);
|
||||
}
|
||||
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
@@ -1173,12 +1216,14 @@ nsCString& nsCString::Insert(char aChar,PRUint32 anOffset){
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
#ifndef NEW_STRING_APIS
|
||||
nsCString& nsCString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
||||
if(0<aCount) {
|
||||
nsStr::Delete(*this,anOffset,aCount);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**********************************************************************
|
||||
Searching methods...
|
||||
@@ -1495,7 +1540,7 @@ PRInt32 nsCString::Compare(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCoun
|
||||
return nsStr::Compare(*this,aString,aCount,aIgnoreCase);
|
||||
}
|
||||
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* Here come a whole bunch of operator functions that are self-explanatory...
|
||||
*/
|
||||
@@ -1522,7 +1567,7 @@ PRBool nsCString::operator<=(const PRUnichar* s) const {return PRBool(Compare(s)
|
||||
PRBool nsCString::operator>=(const nsStr& S) const {return PRBool(Compare(S)>=0);}
|
||||
PRBool nsCString::operator>=(const char* s) const {return PRBool(Compare(s)>=0);}
|
||||
PRBool nsCString::operator>=(const PRUnichar* s) const {return PRBool(Compare(s)>=0);}
|
||||
|
||||
#endif
|
||||
|
||||
PRBool nsCString::EqualsIgnoreCase(const nsStr& aString) const {
|
||||
return Equals(aString,PR_TRUE);
|
||||
|
||||
@@ -45,10 +45,52 @@
|
||||
#include "nsStr.h"
|
||||
#include "nsIAtom.h"
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
#include "nsAWritableString.h"
|
||||
#endif
|
||||
|
||||
|
||||
class NS_COM nsSubsumeCStr;
|
||||
|
||||
class NS_COM nsCString : public nsStr {
|
||||
class NS_COM nsCString :
|
||||
#ifdef NEW_STRING_APIS
|
||||
public nsAWritableCString,
|
||||
#endif
|
||||
public nsStr {
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
protected:
|
||||
typedef nsAReadableCString::FragmentRequest FragmentRequest;
|
||||
typedef nsAReadableCString::ConstFragment ConstFragment;
|
||||
typedef nsAWritableCString::Fragment Fragment;
|
||||
|
||||
virtual const char* GetConstFragment( ConstFragment&, FragmentRequest, PRUint32 ) const;
|
||||
virtual char* GetFragment( Fragment&, FragmentRequest, PRUint32 );
|
||||
|
||||
public:
|
||||
nsCString( const nsAReadableCString& );
|
||||
|
||||
#ifdef HAVE_CPP_USING
|
||||
using nsAWritableCString::Assign;
|
||||
using nsAWritableCString::Append;
|
||||
using nsAWritableCString::Insert;
|
||||
#else
|
||||
virtual void Assign( const nsAReadableCString& aReadable ) {
|
||||
nsAWritableCString::Assign(aReadable);
|
||||
}
|
||||
|
||||
virtual void Append( const nsAReadableCString& aReadable ) {
|
||||
nsAWritableCString::Append(aReadable);
|
||||
}
|
||||
|
||||
virtual void Insert( const nsAReadableCString& aReadable, PRUint32 atPosition ) {
|
||||
nsAWritableCString::Insert(aReadable, atPosition);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
public:
|
||||
void AppendChar( char );
|
||||
|
||||
public:
|
||||
|
||||
@@ -97,7 +139,7 @@ public:
|
||||
* Retrieve the length of this string
|
||||
* @return string length
|
||||
*/
|
||||
inline PRInt32 Length() const { return (PRInt32)mLength; }
|
||||
virtual PRUint32 Length() const { return mLength; }
|
||||
|
||||
/**
|
||||
* Retrieve the size of this string
|
||||
@@ -112,9 +154,7 @@ public:
|
||||
* @param aLength -- contains new length for mStr
|
||||
* @return
|
||||
*/
|
||||
void SetLength(PRUint32 aLength) {
|
||||
Truncate(aLength);
|
||||
}
|
||||
void SetLength(PRUint32 aLength);
|
||||
|
||||
/**
|
||||
* Sets the new length of the string.
|
||||
@@ -122,14 +162,20 @@ public:
|
||||
* @return nada
|
||||
*/
|
||||
void SetCapacity(PRUint32 aLength);
|
||||
|
||||
/**
|
||||
* This method truncates this string to given length.
|
||||
*
|
||||
* @param anIndex -- new length of string
|
||||
* @return nada
|
||||
*/
|
||||
void Truncate(PRUint32 anIndex=0);
|
||||
void Truncate(PRUint32 anIndex=0) {
|
||||
NS_ASSERTION(anIndex<=mLength, "Can't use |Truncate()| to make a string longer.");
|
||||
if ( anIndex < mLength )
|
||||
SetLength(anIndex);
|
||||
}
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* Determine whether or not this string has a length of 0
|
||||
*
|
||||
@@ -157,14 +203,15 @@ public:
|
||||
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
|
||||
@@ -187,7 +234,7 @@ public:
|
||||
*/
|
||||
nsSubsumeCStr operator+(PRUnichar aChar);
|
||||
nsSubsumeCStr operator+(char aChar);
|
||||
|
||||
#endif
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
@@ -499,7 +546,9 @@ public:
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
#ifndef NEW_STRING_APIS
|
||||
nsCString& Cut(PRUint32 anOffset,PRInt32 aCount);
|
||||
#endif
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
@@ -594,6 +643,7 @@ public:
|
||||
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* These methods compare a given string type to this one
|
||||
* @param aString is the string to be compared to this
|
||||
@@ -647,6 +697,7 @@ public:
|
||||
PRBool operator>=(const nsStr &S) const;
|
||||
PRBool operator>=(const char* aString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
|
||||
/**
|
||||
* Compare this to given string; note that we compare full strings here.
|
||||
@@ -675,6 +726,14 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#if 0
|
||||
#ifdef NEW_STRING_APIS
|
||||
NS_DEF_NON_TEMPLATE_STRING_COMPARISON_OPERATORS(const nsCString&, const nsCString&);
|
||||
NS_DEF_NON_TEMPLATE_STRING_COMPARISON_OPERATORS(const nsCString&, const char*)
|
||||
NS_DEF_NON_TEMPLATE_STRING_COMPARISON_OPERATORS(const char*, const nsCString&)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern NS_COM int fputs(const nsCString& aString, FILE* out);
|
||||
//ostream& operator<<(ostream& aStream,const nsCString& aString);
|
||||
//virtual void DebugDump(ostream& aStream) const;
|
||||
|
||||
@@ -136,6 +136,47 @@ nsString::~nsString() {
|
||||
nsStr::Destroy(*this);
|
||||
}
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
const PRUnichar* nsString::GetConstFragment( ConstFragment& aFragment, FragmentRequest aRequest, PRUint32 aOffset ) const {
|
||||
switch ( aRequest ) {
|
||||
case kFirstFragment:
|
||||
case kLastFragment:
|
||||
case kFragmentAt:
|
||||
aFragment.mEnd = (aFragment.mStart = mUStr) + mLength;
|
||||
return aFragment.mStart + aOffset;
|
||||
|
||||
case kPrevFragment:
|
||||
case kNextFragment:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
PRUnichar* nsString::GetFragment( Fragment& aFragment, FragmentRequest aRequest, PRUint32 aOffset ) {
|
||||
switch ( aRequest ) {
|
||||
case kFirstFragment:
|
||||
case kLastFragment:
|
||||
case kFragmentAt:
|
||||
aFragment.mEnd = (aFragment.mStart = mUStr) + mLength;
|
||||
return aFragment.mStart + aOffset;
|
||||
|
||||
case kPrevFragment:
|
||||
case kNextFragment:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
nsString::nsString( const nsAReadableString& aReadable ) {
|
||||
nsStr::Initialize(*this,eTwoByte);
|
||||
Assign(aReadable);
|
||||
}
|
||||
#endif
|
||||
|
||||
void nsString::AppendChar( PRUnichar aChar ) {
|
||||
Append(aChar);
|
||||
}
|
||||
|
||||
void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||
if (aResult) {
|
||||
*aResult = sizeof(*this) + mCapacity * mCharSize;
|
||||
@@ -149,7 +190,9 @@ void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||
* @param anIndex -- new length of string
|
||||
* @return nada
|
||||
*/
|
||||
void nsString::Truncate(PRUint32 anIndex) {
|
||||
void nsString::SetLength(PRUint32 anIndex) {
|
||||
if ( anIndex > mCapacity )
|
||||
SetCapacity(anIndex);
|
||||
nsStr::Truncate(*this,anIndex);
|
||||
}
|
||||
|
||||
@@ -173,7 +216,7 @@ void nsString::SetCapacity(PRUint32 aLength) {
|
||||
|
||||
|
||||
//static char gChar=0;
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
*
|
||||
* @update gess1/4/99
|
||||
@@ -225,6 +268,7 @@ PRUnichar nsString::First(void) const{
|
||||
PRUnichar nsString::Last(void) const{
|
||||
return GetCharAt(*this,mLength-1);
|
||||
}
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
|
||||
/**
|
||||
* set a char inside this string at given index
|
||||
@@ -251,7 +295,7 @@ 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
|
||||
@@ -325,6 +369,7 @@ nsSubsumeStr nsString::operator+(PRUnichar aChar) {
|
||||
temp.Append(char(aChar));
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
@@ -1375,12 +1420,14 @@ nsString& nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
#ifndef NEW_STRING_APIS
|
||||
nsString& nsString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
||||
if(0<aCount) {
|
||||
nsStr::Delete(*this,anOffset,aCount);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**********************************************************************
|
||||
Searching methods...
|
||||
@@ -1776,6 +1823,8 @@ PRInt32 nsString::Compare(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount
|
||||
return nsStr::Compare(*this,aString,aCount,aIgnoreCase);
|
||||
}
|
||||
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* Here come a whole bunch of operator functions that are self-explanatory...
|
||||
*/
|
||||
@@ -1809,7 +1858,7 @@ PRBool nsString::operator>=(const nsString& S) const {return PRBool(Compare(S)>=
|
||||
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(s)>=0);}
|
||||
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
|
||||
PRBool nsString::EqualsIgnoreCase(const nsString& aString) const {
|
||||
return Equals(aString,PR_TRUE);
|
||||
|
||||
@@ -47,6 +47,10 @@
|
||||
#include "nsStr.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
#include "nsAWritableString.h"
|
||||
#endif
|
||||
|
||||
class nsISizeOfHandler;
|
||||
|
||||
|
||||
@@ -55,7 +59,45 @@ class nsISizeOfHandler;
|
||||
|
||||
|
||||
class NS_COM nsSubsumeStr;
|
||||
class NS_COM nsString : public nsStr {
|
||||
class NS_COM nsString :
|
||||
#ifdef NEW_STRING_APIS
|
||||
public nsAWritableString,
|
||||
#endif
|
||||
public nsStr {
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
protected:
|
||||
typedef nsAReadableString::FragmentRequest FragmentRequest;
|
||||
typedef nsAReadableString::ConstFragment ConstFragment;
|
||||
typedef nsAWritableString::Fragment Fragment;
|
||||
|
||||
virtual const PRUnichar* GetConstFragment( ConstFragment&, FragmentRequest, PRUint32 ) const;
|
||||
virtual PRUnichar* GetFragment( Fragment&, FragmentRequest, PRUint32 );
|
||||
|
||||
public:
|
||||
nsString( const nsAReadableString& );
|
||||
|
||||
#ifdef HAVE_CPP_USING
|
||||
using nsAWritableString::Assign;
|
||||
using nsAWritableString::Append;
|
||||
using nsAWritableString::Insert;
|
||||
#else
|
||||
virtual void Assign( const nsAReadableString& aReadable ) {
|
||||
nsAWritableString::Assign(aReadable);
|
||||
}
|
||||
|
||||
virtual void Append( const nsAReadableString& aReadable ) {
|
||||
nsAWritableString::Append(aReadable);
|
||||
}
|
||||
|
||||
virtual void Insert( const nsAReadableString& aReadable, PRUint32 atPosition ) {
|
||||
nsAWritableString::Insert(aReadable, atPosition);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
public:
|
||||
void AppendChar( PRUnichar );
|
||||
|
||||
public:
|
||||
|
||||
@@ -109,7 +151,7 @@ public:
|
||||
* Retrieve the length of this string
|
||||
* @return string length
|
||||
*/
|
||||
inline PRInt32 Length() const { return (PRInt32)mLength; }
|
||||
virtual PRUint32 Length() const { return mLength; }
|
||||
|
||||
/**
|
||||
* Retrieve the size of this string
|
||||
@@ -124,9 +166,7 @@ public:
|
||||
* @param aLength -- contains new length for mStr
|
||||
* @return
|
||||
*/
|
||||
void SetLength(PRUint32 aLength) {
|
||||
Truncate(aLength);
|
||||
}
|
||||
void SetLength(PRUint32 aLength);
|
||||
|
||||
/**
|
||||
* Sets the new length of the string.
|
||||
@@ -135,15 +175,21 @@ public:
|
||||
*/
|
||||
void SetCapacity(PRUint32 aLength);
|
||||
|
||||
|
||||
/**
|
||||
* This method truncates this string to given length.
|
||||
*
|
||||
* @param anIndex -- new length of string
|
||||
* @return nada
|
||||
*/
|
||||
void Truncate(PRUint32 anIndex=0);
|
||||
void Truncate(PRUint32 anIndex=0) {
|
||||
NS_ASSERTION(anIndex<=mLength, "Can't use |Truncate()| to make a string longer.");
|
||||
if ( anIndex < mLength )
|
||||
SetLength(anIndex);
|
||||
}
|
||||
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* Determine whether or not the characters in this
|
||||
* string are in store as 1 or 2 byte (unicode) strings.
|
||||
@@ -182,7 +228,7 @@ public:
|
||||
PRUnichar CharAt(PRUint32 anIndex) const;
|
||||
PRUnichar First(void) const;
|
||||
PRUnichar Last(void) const;
|
||||
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
/**
|
||||
* Set nth character.
|
||||
*/
|
||||
@@ -551,7 +597,9 @@ public:
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
#ifndef NEW_STRING_APIS
|
||||
nsString& Cut(PRUint32 anOffset,PRInt32 aCount);
|
||||
#endif
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
@@ -652,6 +700,7 @@ public:
|
||||
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* These methods compare a given string type to this one
|
||||
* @param aString is the string to be compared to this
|
||||
@@ -711,7 +760,7 @@ public:
|
||||
PRBool operator>=(const nsStr &S) const;
|
||||
PRBool operator>=(const char* aString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
/**
|
||||
* 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.
|
||||
@@ -773,6 +822,11 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
NS_DEF_NON_TEMPLATE_STRING_COMPARISON_OPERATORS(const nsString&, const PRUnichar*)
|
||||
NS_DEF_NON_TEMPLATE_STRING_COMPARISON_OPERATORS(const PRUnichar*, const nsString&)
|
||||
#endif
|
||||
|
||||
extern NS_COM int fputs(const nsString& aString, FILE* out);
|
||||
//ostream& operator<<(ostream& aStream,const nsString& aString);
|
||||
//virtual void DebugDump(ostream& aStream) const;
|
||||
|
||||
@@ -126,11 +126,17 @@ static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
|
||||
|
||||
extern nsICaseConversion * gCaseConv;
|
||||
|
||||
#ifdef SCC_TESTS
|
||||
static nsICaseConversion* gCaseConv;
|
||||
#endif
|
||||
|
||||
static void CheckCaseConversion()
|
||||
{
|
||||
#ifndef SCC_TESTS
|
||||
if (NULL == gCaseConv)
|
||||
(void) nsServiceManager::GetService(kUnicharUtilCID, NS_GET_IID(nsICaseConversion),
|
||||
(nsISupports**) &gCaseConv);
|
||||
#endif
|
||||
|
||||
NS_ASSERTION( gCaseConv != NULL , "cannot obtain UnicharUtil");
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount){
|
||||
* @param aDestOffset is where in aDest truncation is to occur
|
||||
*/
|
||||
void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
if(aDestOffset<aDest.mCapacity){
|
||||
aDest.mLength=aDestOffset;
|
||||
AddNullTerminator(aDest);
|
||||
NSSTR_SEEN(aDest);
|
||||
|
||||
@@ -40,7 +40,6 @@ static const char* kNullPointerError = "Error: unexpected null ptr";
|
||||
static const char* kWhitespace="\b\t\r\n ";
|
||||
|
||||
|
||||
|
||||
static void CSubsume(nsStr& aDest,nsStr& aSource){
|
||||
if(aSource.mStr && aSource.mLength) {
|
||||
if(aSource.mOwnsBuffer){
|
||||
@@ -126,6 +125,47 @@ nsCString::~nsCString() {
|
||||
nsStr::Destroy(*this);
|
||||
}
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
const char* nsCString::GetConstFragment( ConstFragment& aFragment, FragmentRequest aRequest, PRUint32 aOffset ) const {
|
||||
switch ( aRequest ) {
|
||||
case kFirstFragment:
|
||||
case kLastFragment:
|
||||
case kFragmentAt:
|
||||
aFragment.mEnd = (aFragment.mStart = mStr) + mLength;
|
||||
return aFragment.mStart + aOffset;
|
||||
|
||||
case kPrevFragment:
|
||||
case kNextFragment:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
char* nsCString::GetFragment( Fragment& aFragment, FragmentRequest aRequest, PRUint32 aOffset ) {
|
||||
switch ( aRequest ) {
|
||||
case kFirstFragment:
|
||||
case kLastFragment:
|
||||
case kFragmentAt:
|
||||
aFragment.mEnd = (aFragment.mStart = mStr) + mLength;
|
||||
return aFragment.mStart + aOffset;
|
||||
|
||||
case kPrevFragment:
|
||||
case kNextFragment:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
nsCString::nsCString( const nsAReadableCString& aReadable ) {
|
||||
nsStr::Initialize(*this,eOneByte);
|
||||
Assign(aReadable);
|
||||
}
|
||||
#endif
|
||||
|
||||
void nsCString::AppendChar( char aChar ) {
|
||||
Append(aChar);
|
||||
}
|
||||
|
||||
void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||
if (aResult) {
|
||||
*aResult = sizeof(*this) + mCapacity * mCharSize;
|
||||
@@ -139,7 +179,9 @@ void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||
* @param anIndex -- new length of string
|
||||
* @return nada
|
||||
*/
|
||||
void nsCString::Truncate(PRUint32 anIndex) {
|
||||
void nsCString::SetLength(PRUint32 anIndex) {
|
||||
if ( anIndex > mCapacity )
|
||||
SetCapacity(anIndex);
|
||||
nsStr::Truncate(*this,anIndex);
|
||||
}
|
||||
|
||||
@@ -160,7 +202,7 @@ void nsCString::SetCapacity(PRUint32 aLength) {
|
||||
Accessor methods...
|
||||
*********************************************************************/
|
||||
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* Retrieves internal (1-byte) buffer ptr;
|
||||
* @update gess1/4/99
|
||||
@@ -197,6 +239,7 @@ PRUnichar nsCString::First(void) const{
|
||||
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
|
||||
@@ -217,7 +260,7 @@ 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
|
||||
@@ -267,7 +310,7 @@ nsSubsumeCStr nsCString::operator+(char aChar) {
|
||||
temp.Append(aChar);
|
||||
return nsSubsumeCStr(temp);
|
||||
}
|
||||
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
@@ -1173,12 +1216,14 @@ nsCString& nsCString::Insert(char aChar,PRUint32 anOffset){
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
#ifndef NEW_STRING_APIS
|
||||
nsCString& nsCString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
||||
if(0<aCount) {
|
||||
nsStr::Delete(*this,anOffset,aCount);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**********************************************************************
|
||||
Searching methods...
|
||||
@@ -1495,7 +1540,7 @@ PRInt32 nsCString::Compare(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCoun
|
||||
return nsStr::Compare(*this,aString,aCount,aIgnoreCase);
|
||||
}
|
||||
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* Here come a whole bunch of operator functions that are self-explanatory...
|
||||
*/
|
||||
@@ -1522,7 +1567,7 @@ PRBool nsCString::operator<=(const PRUnichar* s) const {return PRBool(Compare(s)
|
||||
PRBool nsCString::operator>=(const nsStr& S) const {return PRBool(Compare(S)>=0);}
|
||||
PRBool nsCString::operator>=(const char* s) const {return PRBool(Compare(s)>=0);}
|
||||
PRBool nsCString::operator>=(const PRUnichar* s) const {return PRBool(Compare(s)>=0);}
|
||||
|
||||
#endif
|
||||
|
||||
PRBool nsCString::EqualsIgnoreCase(const nsStr& aString) const {
|
||||
return Equals(aString,PR_TRUE);
|
||||
|
||||
@@ -45,10 +45,52 @@
|
||||
#include "nsStr.h"
|
||||
#include "nsIAtom.h"
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
#include "nsAWritableString.h"
|
||||
#endif
|
||||
|
||||
|
||||
class NS_COM nsSubsumeCStr;
|
||||
|
||||
class NS_COM nsCString : public nsStr {
|
||||
class NS_COM nsCString :
|
||||
#ifdef NEW_STRING_APIS
|
||||
public nsAWritableCString,
|
||||
#endif
|
||||
public nsStr {
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
protected:
|
||||
typedef nsAReadableCString::FragmentRequest FragmentRequest;
|
||||
typedef nsAReadableCString::ConstFragment ConstFragment;
|
||||
typedef nsAWritableCString::Fragment Fragment;
|
||||
|
||||
virtual const char* GetConstFragment( ConstFragment&, FragmentRequest, PRUint32 ) const;
|
||||
virtual char* GetFragment( Fragment&, FragmentRequest, PRUint32 );
|
||||
|
||||
public:
|
||||
nsCString( const nsAReadableCString& );
|
||||
|
||||
#ifdef HAVE_CPP_USING
|
||||
using nsAWritableCString::Assign;
|
||||
using nsAWritableCString::Append;
|
||||
using nsAWritableCString::Insert;
|
||||
#else
|
||||
virtual void Assign( const nsAReadableCString& aReadable ) {
|
||||
nsAWritableCString::Assign(aReadable);
|
||||
}
|
||||
|
||||
virtual void Append( const nsAReadableCString& aReadable ) {
|
||||
nsAWritableCString::Append(aReadable);
|
||||
}
|
||||
|
||||
virtual void Insert( const nsAReadableCString& aReadable, PRUint32 atPosition ) {
|
||||
nsAWritableCString::Insert(aReadable, atPosition);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
public:
|
||||
void AppendChar( char );
|
||||
|
||||
public:
|
||||
|
||||
@@ -97,7 +139,7 @@ public:
|
||||
* Retrieve the length of this string
|
||||
* @return string length
|
||||
*/
|
||||
inline PRInt32 Length() const { return (PRInt32)mLength; }
|
||||
virtual PRUint32 Length() const { return mLength; }
|
||||
|
||||
/**
|
||||
* Retrieve the size of this string
|
||||
@@ -112,9 +154,7 @@ public:
|
||||
* @param aLength -- contains new length for mStr
|
||||
* @return
|
||||
*/
|
||||
void SetLength(PRUint32 aLength) {
|
||||
Truncate(aLength);
|
||||
}
|
||||
void SetLength(PRUint32 aLength);
|
||||
|
||||
/**
|
||||
* Sets the new length of the string.
|
||||
@@ -122,14 +162,20 @@ public:
|
||||
* @return nada
|
||||
*/
|
||||
void SetCapacity(PRUint32 aLength);
|
||||
|
||||
/**
|
||||
* This method truncates this string to given length.
|
||||
*
|
||||
* @param anIndex -- new length of string
|
||||
* @return nada
|
||||
*/
|
||||
void Truncate(PRUint32 anIndex=0);
|
||||
void Truncate(PRUint32 anIndex=0) {
|
||||
NS_ASSERTION(anIndex<=mLength, "Can't use |Truncate()| to make a string longer.");
|
||||
if ( anIndex < mLength )
|
||||
SetLength(anIndex);
|
||||
}
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* Determine whether or not this string has a length of 0
|
||||
*
|
||||
@@ -157,14 +203,15 @@ public:
|
||||
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
|
||||
@@ -187,7 +234,7 @@ public:
|
||||
*/
|
||||
nsSubsumeCStr operator+(PRUnichar aChar);
|
||||
nsSubsumeCStr operator+(char aChar);
|
||||
|
||||
#endif
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
@@ -499,7 +546,9 @@ public:
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
#ifndef NEW_STRING_APIS
|
||||
nsCString& Cut(PRUint32 anOffset,PRInt32 aCount);
|
||||
#endif
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
@@ -594,6 +643,7 @@ public:
|
||||
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* These methods compare a given string type to this one
|
||||
* @param aString is the string to be compared to this
|
||||
@@ -647,6 +697,7 @@ public:
|
||||
PRBool operator>=(const nsStr &S) const;
|
||||
PRBool operator>=(const char* aString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
|
||||
/**
|
||||
* Compare this to given string; note that we compare full strings here.
|
||||
@@ -675,6 +726,14 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#if 0
|
||||
#ifdef NEW_STRING_APIS
|
||||
NS_DEF_NON_TEMPLATE_STRING_COMPARISON_OPERATORS(const nsCString&, const nsCString&);
|
||||
NS_DEF_NON_TEMPLATE_STRING_COMPARISON_OPERATORS(const nsCString&, const char*)
|
||||
NS_DEF_NON_TEMPLATE_STRING_COMPARISON_OPERATORS(const char*, const nsCString&)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern NS_COM int fputs(const nsCString& aString, FILE* out);
|
||||
//ostream& operator<<(ostream& aStream,const nsCString& aString);
|
||||
//virtual void DebugDump(ostream& aStream) const;
|
||||
|
||||
@@ -136,6 +136,47 @@ nsString::~nsString() {
|
||||
nsStr::Destroy(*this);
|
||||
}
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
const PRUnichar* nsString::GetConstFragment( ConstFragment& aFragment, FragmentRequest aRequest, PRUint32 aOffset ) const {
|
||||
switch ( aRequest ) {
|
||||
case kFirstFragment:
|
||||
case kLastFragment:
|
||||
case kFragmentAt:
|
||||
aFragment.mEnd = (aFragment.mStart = mUStr) + mLength;
|
||||
return aFragment.mStart + aOffset;
|
||||
|
||||
case kPrevFragment:
|
||||
case kNextFragment:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
PRUnichar* nsString::GetFragment( Fragment& aFragment, FragmentRequest aRequest, PRUint32 aOffset ) {
|
||||
switch ( aRequest ) {
|
||||
case kFirstFragment:
|
||||
case kLastFragment:
|
||||
case kFragmentAt:
|
||||
aFragment.mEnd = (aFragment.mStart = mUStr) + mLength;
|
||||
return aFragment.mStart + aOffset;
|
||||
|
||||
case kPrevFragment:
|
||||
case kNextFragment:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
nsString::nsString( const nsAReadableString& aReadable ) {
|
||||
nsStr::Initialize(*this,eTwoByte);
|
||||
Assign(aReadable);
|
||||
}
|
||||
#endif
|
||||
|
||||
void nsString::AppendChar( PRUnichar aChar ) {
|
||||
Append(aChar);
|
||||
}
|
||||
|
||||
void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||
if (aResult) {
|
||||
*aResult = sizeof(*this) + mCapacity * mCharSize;
|
||||
@@ -149,7 +190,9 @@ void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||
* @param anIndex -- new length of string
|
||||
* @return nada
|
||||
*/
|
||||
void nsString::Truncate(PRUint32 anIndex) {
|
||||
void nsString::SetLength(PRUint32 anIndex) {
|
||||
if ( anIndex > mCapacity )
|
||||
SetCapacity(anIndex);
|
||||
nsStr::Truncate(*this,anIndex);
|
||||
}
|
||||
|
||||
@@ -173,7 +216,7 @@ void nsString::SetCapacity(PRUint32 aLength) {
|
||||
|
||||
|
||||
//static char gChar=0;
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
*
|
||||
* @update gess1/4/99
|
||||
@@ -225,6 +268,7 @@ PRUnichar nsString::First(void) const{
|
||||
PRUnichar nsString::Last(void) const{
|
||||
return GetCharAt(*this,mLength-1);
|
||||
}
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
|
||||
/**
|
||||
* set a char inside this string at given index
|
||||
@@ -251,7 +295,7 @@ 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
|
||||
@@ -325,6 +369,7 @@ nsSubsumeStr nsString::operator+(PRUnichar aChar) {
|
||||
temp.Append(char(aChar));
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
@@ -1375,12 +1420,14 @@ nsString& nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
#ifndef NEW_STRING_APIS
|
||||
nsString& nsString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
||||
if(0<aCount) {
|
||||
nsStr::Delete(*this,anOffset,aCount);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**********************************************************************
|
||||
Searching methods...
|
||||
@@ -1776,6 +1823,8 @@ PRInt32 nsString::Compare(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount
|
||||
return nsStr::Compare(*this,aString,aCount,aIgnoreCase);
|
||||
}
|
||||
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* Here come a whole bunch of operator functions that are self-explanatory...
|
||||
*/
|
||||
@@ -1809,7 +1858,7 @@ PRBool nsString::operator>=(const nsString& S) const {return PRBool(Compare(S)>=
|
||||
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(s)>=0);}
|
||||
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
|
||||
PRBool nsString::EqualsIgnoreCase(const nsString& aString) const {
|
||||
return Equals(aString,PR_TRUE);
|
||||
|
||||
@@ -47,6 +47,10 @@
|
||||
#include "nsStr.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
#include "nsAWritableString.h"
|
||||
#endif
|
||||
|
||||
class nsISizeOfHandler;
|
||||
|
||||
|
||||
@@ -55,7 +59,45 @@ class nsISizeOfHandler;
|
||||
|
||||
|
||||
class NS_COM nsSubsumeStr;
|
||||
class NS_COM nsString : public nsStr {
|
||||
class NS_COM nsString :
|
||||
#ifdef NEW_STRING_APIS
|
||||
public nsAWritableString,
|
||||
#endif
|
||||
public nsStr {
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
protected:
|
||||
typedef nsAReadableString::FragmentRequest FragmentRequest;
|
||||
typedef nsAReadableString::ConstFragment ConstFragment;
|
||||
typedef nsAWritableString::Fragment Fragment;
|
||||
|
||||
virtual const PRUnichar* GetConstFragment( ConstFragment&, FragmentRequest, PRUint32 ) const;
|
||||
virtual PRUnichar* GetFragment( Fragment&, FragmentRequest, PRUint32 );
|
||||
|
||||
public:
|
||||
nsString( const nsAReadableString& );
|
||||
|
||||
#ifdef HAVE_CPP_USING
|
||||
using nsAWritableString::Assign;
|
||||
using nsAWritableString::Append;
|
||||
using nsAWritableString::Insert;
|
||||
#else
|
||||
virtual void Assign( const nsAReadableString& aReadable ) {
|
||||
nsAWritableString::Assign(aReadable);
|
||||
}
|
||||
|
||||
virtual void Append( const nsAReadableString& aReadable ) {
|
||||
nsAWritableString::Append(aReadable);
|
||||
}
|
||||
|
||||
virtual void Insert( const nsAReadableString& aReadable, PRUint32 atPosition ) {
|
||||
nsAWritableString::Insert(aReadable, atPosition);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
public:
|
||||
void AppendChar( PRUnichar );
|
||||
|
||||
public:
|
||||
|
||||
@@ -109,7 +151,7 @@ public:
|
||||
* Retrieve the length of this string
|
||||
* @return string length
|
||||
*/
|
||||
inline PRInt32 Length() const { return (PRInt32)mLength; }
|
||||
virtual PRUint32 Length() const { return mLength; }
|
||||
|
||||
/**
|
||||
* Retrieve the size of this string
|
||||
@@ -124,9 +166,7 @@ public:
|
||||
* @param aLength -- contains new length for mStr
|
||||
* @return
|
||||
*/
|
||||
void SetLength(PRUint32 aLength) {
|
||||
Truncate(aLength);
|
||||
}
|
||||
void SetLength(PRUint32 aLength);
|
||||
|
||||
/**
|
||||
* Sets the new length of the string.
|
||||
@@ -135,15 +175,21 @@ public:
|
||||
*/
|
||||
void SetCapacity(PRUint32 aLength);
|
||||
|
||||
|
||||
/**
|
||||
* This method truncates this string to given length.
|
||||
*
|
||||
* @param anIndex -- new length of string
|
||||
* @return nada
|
||||
*/
|
||||
void Truncate(PRUint32 anIndex=0);
|
||||
void Truncate(PRUint32 anIndex=0) {
|
||||
NS_ASSERTION(anIndex<=mLength, "Can't use |Truncate()| to make a string longer.");
|
||||
if ( anIndex < mLength )
|
||||
SetLength(anIndex);
|
||||
}
|
||||
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* Determine whether or not the characters in this
|
||||
* string are in store as 1 or 2 byte (unicode) strings.
|
||||
@@ -182,7 +228,7 @@ public:
|
||||
PRUnichar CharAt(PRUint32 anIndex) const;
|
||||
PRUnichar First(void) const;
|
||||
PRUnichar Last(void) const;
|
||||
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
/**
|
||||
* Set nth character.
|
||||
*/
|
||||
@@ -551,7 +597,9 @@ public:
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
#ifndef NEW_STRING_APIS
|
||||
nsString& Cut(PRUint32 anOffset,PRInt32 aCount);
|
||||
#endif
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
@@ -652,6 +700,7 @@ public:
|
||||
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* These methods compare a given string type to this one
|
||||
* @param aString is the string to be compared to this
|
||||
@@ -711,7 +760,7 @@ public:
|
||||
PRBool operator>=(const nsStr &S) const;
|
||||
PRBool operator>=(const char* aString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
/**
|
||||
* 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.
|
||||
@@ -773,6 +822,11 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
NS_DEF_NON_TEMPLATE_STRING_COMPARISON_OPERATORS(const nsString&, const PRUnichar*)
|
||||
NS_DEF_NON_TEMPLATE_STRING_COMPARISON_OPERATORS(const PRUnichar*, const nsString&)
|
||||
#endif
|
||||
|
||||
extern NS_COM int fputs(const nsString& aString, FILE* out);
|
||||
//ostream& operator<<(ostream& aStream,const nsString& aString);
|
||||
//virtual void DebugDump(ostream& aStream) const;
|
||||
|
||||
@@ -285,7 +285,7 @@ void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount){
|
||||
* @param aDestOffset is where in aDest truncation is to occur
|
||||
*/
|
||||
void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
if(aDestOffset<aDest.mCapacity){
|
||||
aDest.mLength=aDestOffset;
|
||||
AddNullTerminator(aDest);
|
||||
NSSTR_SEEN(aDest);
|
||||
|
||||
@@ -40,7 +40,6 @@ static const char* kNullPointerError = "Error: unexpected null ptr";
|
||||
static const char* kWhitespace="\b\t\r\n ";
|
||||
|
||||
|
||||
|
||||
static void CSubsume(nsStr& aDest,nsStr& aSource){
|
||||
if(aSource.mStr && aSource.mLength) {
|
||||
if(aSource.mOwnsBuffer){
|
||||
@@ -126,6 +125,47 @@ nsCString::~nsCString() {
|
||||
nsStr::Destroy(*this);
|
||||
}
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
const char* nsCString::GetConstFragment( ConstFragment& aFragment, FragmentRequest aRequest, PRUint32 aOffset ) const {
|
||||
switch ( aRequest ) {
|
||||
case kFirstFragment:
|
||||
case kLastFragment:
|
||||
case kFragmentAt:
|
||||
aFragment.mEnd = (aFragment.mStart = mStr) + mLength;
|
||||
return aFragment.mStart + aOffset;
|
||||
|
||||
case kPrevFragment:
|
||||
case kNextFragment:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
char* nsCString::GetFragment( Fragment& aFragment, FragmentRequest aRequest, PRUint32 aOffset ) {
|
||||
switch ( aRequest ) {
|
||||
case kFirstFragment:
|
||||
case kLastFragment:
|
||||
case kFragmentAt:
|
||||
aFragment.mEnd = (aFragment.mStart = mStr) + mLength;
|
||||
return aFragment.mStart + aOffset;
|
||||
|
||||
case kPrevFragment:
|
||||
case kNextFragment:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
nsCString::nsCString( const nsAReadableCString& aReadable ) {
|
||||
nsStr::Initialize(*this,eOneByte);
|
||||
Assign(aReadable);
|
||||
}
|
||||
#endif
|
||||
|
||||
void nsCString::AppendChar( char aChar ) {
|
||||
Append(aChar);
|
||||
}
|
||||
|
||||
void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||
if (aResult) {
|
||||
*aResult = sizeof(*this) + mCapacity * mCharSize;
|
||||
@@ -139,7 +179,9 @@ void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||
* @param anIndex -- new length of string
|
||||
* @return nada
|
||||
*/
|
||||
void nsCString::Truncate(PRUint32 anIndex) {
|
||||
void nsCString::SetLength(PRUint32 anIndex) {
|
||||
if ( anIndex > mCapacity )
|
||||
SetCapacity(anIndex);
|
||||
nsStr::Truncate(*this,anIndex);
|
||||
}
|
||||
|
||||
@@ -160,7 +202,7 @@ void nsCString::SetCapacity(PRUint32 aLength) {
|
||||
Accessor methods...
|
||||
*********************************************************************/
|
||||
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* Retrieves internal (1-byte) buffer ptr;
|
||||
* @update gess1/4/99
|
||||
@@ -197,6 +239,7 @@ PRUnichar nsCString::First(void) const{
|
||||
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
|
||||
@@ -217,7 +260,7 @@ 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
|
||||
@@ -267,7 +310,7 @@ nsSubsumeCStr nsCString::operator+(char aChar) {
|
||||
temp.Append(aChar);
|
||||
return nsSubsumeCStr(temp);
|
||||
}
|
||||
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
@@ -1173,12 +1216,14 @@ nsCString& nsCString::Insert(char aChar,PRUint32 anOffset){
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
#ifndef NEW_STRING_APIS
|
||||
nsCString& nsCString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
||||
if(0<aCount) {
|
||||
nsStr::Delete(*this,anOffset,aCount);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**********************************************************************
|
||||
Searching methods...
|
||||
@@ -1495,7 +1540,7 @@ PRInt32 nsCString::Compare(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCoun
|
||||
return nsStr::Compare(*this,aString,aCount,aIgnoreCase);
|
||||
}
|
||||
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* Here come a whole bunch of operator functions that are self-explanatory...
|
||||
*/
|
||||
@@ -1522,7 +1567,7 @@ PRBool nsCString::operator<=(const PRUnichar* s) const {return PRBool(Compare(s)
|
||||
PRBool nsCString::operator>=(const nsStr& S) const {return PRBool(Compare(S)>=0);}
|
||||
PRBool nsCString::operator>=(const char* s) const {return PRBool(Compare(s)>=0);}
|
||||
PRBool nsCString::operator>=(const PRUnichar* s) const {return PRBool(Compare(s)>=0);}
|
||||
|
||||
#endif
|
||||
|
||||
PRBool nsCString::EqualsIgnoreCase(const nsStr& aString) const {
|
||||
return Equals(aString,PR_TRUE);
|
||||
|
||||
@@ -45,10 +45,52 @@
|
||||
#include "nsStr.h"
|
||||
#include "nsIAtom.h"
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
#include "nsAWritableString.h"
|
||||
#endif
|
||||
|
||||
|
||||
class NS_COM nsSubsumeCStr;
|
||||
|
||||
class NS_COM nsCString : public nsStr {
|
||||
class NS_COM nsCString :
|
||||
#ifdef NEW_STRING_APIS
|
||||
public nsAWritableCString,
|
||||
#endif
|
||||
public nsStr {
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
protected:
|
||||
typedef nsAReadableCString::FragmentRequest FragmentRequest;
|
||||
typedef nsAReadableCString::ConstFragment ConstFragment;
|
||||
typedef nsAWritableCString::Fragment Fragment;
|
||||
|
||||
virtual const char* GetConstFragment( ConstFragment&, FragmentRequest, PRUint32 ) const;
|
||||
virtual char* GetFragment( Fragment&, FragmentRequest, PRUint32 );
|
||||
|
||||
public:
|
||||
nsCString( const nsAReadableCString& );
|
||||
|
||||
#ifdef HAVE_CPP_USING
|
||||
using nsAWritableCString::Assign;
|
||||
using nsAWritableCString::Append;
|
||||
using nsAWritableCString::Insert;
|
||||
#else
|
||||
virtual void Assign( const nsAReadableCString& aReadable ) {
|
||||
nsAWritableCString::Assign(aReadable);
|
||||
}
|
||||
|
||||
virtual void Append( const nsAReadableCString& aReadable ) {
|
||||
nsAWritableCString::Append(aReadable);
|
||||
}
|
||||
|
||||
virtual void Insert( const nsAReadableCString& aReadable, PRUint32 atPosition ) {
|
||||
nsAWritableCString::Insert(aReadable, atPosition);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
public:
|
||||
void AppendChar( char );
|
||||
|
||||
public:
|
||||
|
||||
@@ -97,7 +139,7 @@ public:
|
||||
* Retrieve the length of this string
|
||||
* @return string length
|
||||
*/
|
||||
inline PRInt32 Length() const { return (PRInt32)mLength; }
|
||||
virtual PRUint32 Length() const { return mLength; }
|
||||
|
||||
/**
|
||||
* Retrieve the size of this string
|
||||
@@ -112,9 +154,7 @@ public:
|
||||
* @param aLength -- contains new length for mStr
|
||||
* @return
|
||||
*/
|
||||
void SetLength(PRUint32 aLength) {
|
||||
Truncate(aLength);
|
||||
}
|
||||
void SetLength(PRUint32 aLength);
|
||||
|
||||
/**
|
||||
* Sets the new length of the string.
|
||||
@@ -122,14 +162,20 @@ public:
|
||||
* @return nada
|
||||
*/
|
||||
void SetCapacity(PRUint32 aLength);
|
||||
|
||||
/**
|
||||
* This method truncates this string to given length.
|
||||
*
|
||||
* @param anIndex -- new length of string
|
||||
* @return nada
|
||||
*/
|
||||
void Truncate(PRUint32 anIndex=0);
|
||||
void Truncate(PRUint32 anIndex=0) {
|
||||
NS_ASSERTION(anIndex<=mLength, "Can't use |Truncate()| to make a string longer.");
|
||||
if ( anIndex < mLength )
|
||||
SetLength(anIndex);
|
||||
}
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* Determine whether or not this string has a length of 0
|
||||
*
|
||||
@@ -157,14 +203,15 @@ public:
|
||||
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
|
||||
@@ -187,7 +234,7 @@ public:
|
||||
*/
|
||||
nsSubsumeCStr operator+(PRUnichar aChar);
|
||||
nsSubsumeCStr operator+(char aChar);
|
||||
|
||||
#endif
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
@@ -499,7 +546,9 @@ public:
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
#ifndef NEW_STRING_APIS
|
||||
nsCString& Cut(PRUint32 anOffset,PRInt32 aCount);
|
||||
#endif
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
@@ -594,6 +643,7 @@ public:
|
||||
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* These methods compare a given string type to this one
|
||||
* @param aString is the string to be compared to this
|
||||
@@ -647,6 +697,7 @@ public:
|
||||
PRBool operator>=(const nsStr &S) const;
|
||||
PRBool operator>=(const char* aString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
|
||||
/**
|
||||
* Compare this to given string; note that we compare full strings here.
|
||||
@@ -675,6 +726,14 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#if 0
|
||||
#ifdef NEW_STRING_APIS
|
||||
NS_DEF_NON_TEMPLATE_STRING_COMPARISON_OPERATORS(const nsCString&, const nsCString&);
|
||||
NS_DEF_NON_TEMPLATE_STRING_COMPARISON_OPERATORS(const nsCString&, const char*)
|
||||
NS_DEF_NON_TEMPLATE_STRING_COMPARISON_OPERATORS(const char*, const nsCString&)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern NS_COM int fputs(const nsCString& aString, FILE* out);
|
||||
//ostream& operator<<(ostream& aStream,const nsCString& aString);
|
||||
//virtual void DebugDump(ostream& aStream) const;
|
||||
|
||||
@@ -136,6 +136,47 @@ nsString::~nsString() {
|
||||
nsStr::Destroy(*this);
|
||||
}
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
const PRUnichar* nsString::GetConstFragment( ConstFragment& aFragment, FragmentRequest aRequest, PRUint32 aOffset ) const {
|
||||
switch ( aRequest ) {
|
||||
case kFirstFragment:
|
||||
case kLastFragment:
|
||||
case kFragmentAt:
|
||||
aFragment.mEnd = (aFragment.mStart = mUStr) + mLength;
|
||||
return aFragment.mStart + aOffset;
|
||||
|
||||
case kPrevFragment:
|
||||
case kNextFragment:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
PRUnichar* nsString::GetFragment( Fragment& aFragment, FragmentRequest aRequest, PRUint32 aOffset ) {
|
||||
switch ( aRequest ) {
|
||||
case kFirstFragment:
|
||||
case kLastFragment:
|
||||
case kFragmentAt:
|
||||
aFragment.mEnd = (aFragment.mStart = mUStr) + mLength;
|
||||
return aFragment.mStart + aOffset;
|
||||
|
||||
case kPrevFragment:
|
||||
case kNextFragment:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
nsString::nsString( const nsAReadableString& aReadable ) {
|
||||
nsStr::Initialize(*this,eTwoByte);
|
||||
Assign(aReadable);
|
||||
}
|
||||
#endif
|
||||
|
||||
void nsString::AppendChar( PRUnichar aChar ) {
|
||||
Append(aChar);
|
||||
}
|
||||
|
||||
void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||
if (aResult) {
|
||||
*aResult = sizeof(*this) + mCapacity * mCharSize;
|
||||
@@ -149,7 +190,9 @@ void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||
* @param anIndex -- new length of string
|
||||
* @return nada
|
||||
*/
|
||||
void nsString::Truncate(PRUint32 anIndex) {
|
||||
void nsString::SetLength(PRUint32 anIndex) {
|
||||
if ( anIndex > mCapacity )
|
||||
SetCapacity(anIndex);
|
||||
nsStr::Truncate(*this,anIndex);
|
||||
}
|
||||
|
||||
@@ -173,7 +216,7 @@ void nsString::SetCapacity(PRUint32 aLength) {
|
||||
|
||||
|
||||
//static char gChar=0;
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
*
|
||||
* @update gess1/4/99
|
||||
@@ -225,6 +268,7 @@ PRUnichar nsString::First(void) const{
|
||||
PRUnichar nsString::Last(void) const{
|
||||
return GetCharAt(*this,mLength-1);
|
||||
}
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
|
||||
/**
|
||||
* set a char inside this string at given index
|
||||
@@ -251,7 +295,7 @@ 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
|
||||
@@ -325,6 +369,7 @@ nsSubsumeStr nsString::operator+(PRUnichar aChar) {
|
||||
temp.Append(char(aChar));
|
||||
return nsSubsumeStr(temp);
|
||||
}
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
@@ -1375,12 +1420,14 @@ nsString& nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
#ifndef NEW_STRING_APIS
|
||||
nsString& nsString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
||||
if(0<aCount) {
|
||||
nsStr::Delete(*this,anOffset,aCount);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**********************************************************************
|
||||
Searching methods...
|
||||
@@ -1776,6 +1823,8 @@ PRInt32 nsString::Compare(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount
|
||||
return nsStr::Compare(*this,aString,aCount,aIgnoreCase);
|
||||
}
|
||||
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* Here come a whole bunch of operator functions that are self-explanatory...
|
||||
*/
|
||||
@@ -1809,7 +1858,7 @@ PRBool nsString::operator>=(const nsString& S) const {return PRBool(Compare(S)>=
|
||||
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(s)>=0);}
|
||||
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
|
||||
PRBool nsString::EqualsIgnoreCase(const nsString& aString) const {
|
||||
return Equals(aString,PR_TRUE);
|
||||
|
||||
@@ -47,6 +47,10 @@
|
||||
#include "nsStr.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
#include "nsAWritableString.h"
|
||||
#endif
|
||||
|
||||
class nsISizeOfHandler;
|
||||
|
||||
|
||||
@@ -55,7 +59,45 @@ class nsISizeOfHandler;
|
||||
|
||||
|
||||
class NS_COM nsSubsumeStr;
|
||||
class NS_COM nsString : public nsStr {
|
||||
class NS_COM nsString :
|
||||
#ifdef NEW_STRING_APIS
|
||||
public nsAWritableString,
|
||||
#endif
|
||||
public nsStr {
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
protected:
|
||||
typedef nsAReadableString::FragmentRequest FragmentRequest;
|
||||
typedef nsAReadableString::ConstFragment ConstFragment;
|
||||
typedef nsAWritableString::Fragment Fragment;
|
||||
|
||||
virtual const PRUnichar* GetConstFragment( ConstFragment&, FragmentRequest, PRUint32 ) const;
|
||||
virtual PRUnichar* GetFragment( Fragment&, FragmentRequest, PRUint32 );
|
||||
|
||||
public:
|
||||
nsString( const nsAReadableString& );
|
||||
|
||||
#ifdef HAVE_CPP_USING
|
||||
using nsAWritableString::Assign;
|
||||
using nsAWritableString::Append;
|
||||
using nsAWritableString::Insert;
|
||||
#else
|
||||
virtual void Assign( const nsAReadableString& aReadable ) {
|
||||
nsAWritableString::Assign(aReadable);
|
||||
}
|
||||
|
||||
virtual void Append( const nsAReadableString& aReadable ) {
|
||||
nsAWritableString::Append(aReadable);
|
||||
}
|
||||
|
||||
virtual void Insert( const nsAReadableString& aReadable, PRUint32 atPosition ) {
|
||||
nsAWritableString::Insert(aReadable, atPosition);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
public:
|
||||
void AppendChar( PRUnichar );
|
||||
|
||||
public:
|
||||
|
||||
@@ -109,7 +151,7 @@ public:
|
||||
* Retrieve the length of this string
|
||||
* @return string length
|
||||
*/
|
||||
inline PRInt32 Length() const { return (PRInt32)mLength; }
|
||||
virtual PRUint32 Length() const { return mLength; }
|
||||
|
||||
/**
|
||||
* Retrieve the size of this string
|
||||
@@ -124,9 +166,7 @@ public:
|
||||
* @param aLength -- contains new length for mStr
|
||||
* @return
|
||||
*/
|
||||
void SetLength(PRUint32 aLength) {
|
||||
Truncate(aLength);
|
||||
}
|
||||
void SetLength(PRUint32 aLength);
|
||||
|
||||
/**
|
||||
* Sets the new length of the string.
|
||||
@@ -135,15 +175,21 @@ public:
|
||||
*/
|
||||
void SetCapacity(PRUint32 aLength);
|
||||
|
||||
|
||||
/**
|
||||
* This method truncates this string to given length.
|
||||
*
|
||||
* @param anIndex -- new length of string
|
||||
* @return nada
|
||||
*/
|
||||
void Truncate(PRUint32 anIndex=0);
|
||||
void Truncate(PRUint32 anIndex=0) {
|
||||
NS_ASSERTION(anIndex<=mLength, "Can't use |Truncate()| to make a string longer.");
|
||||
if ( anIndex < mLength )
|
||||
SetLength(anIndex);
|
||||
}
|
||||
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* Determine whether or not the characters in this
|
||||
* string are in store as 1 or 2 byte (unicode) strings.
|
||||
@@ -182,7 +228,7 @@ public:
|
||||
PRUnichar CharAt(PRUint32 anIndex) const;
|
||||
PRUnichar First(void) const;
|
||||
PRUnichar Last(void) const;
|
||||
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
/**
|
||||
* Set nth character.
|
||||
*/
|
||||
@@ -551,7 +597,9 @@ public:
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
#ifndef NEW_STRING_APIS
|
||||
nsString& Cut(PRUint32 anOffset,PRInt32 aCount);
|
||||
#endif
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
@@ -652,6 +700,7 @@ public:
|
||||
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
#ifndef NEW_STRING_APIS
|
||||
/**
|
||||
* These methods compare a given string type to this one
|
||||
* @param aString is the string to be compared to this
|
||||
@@ -711,7 +760,7 @@ public:
|
||||
PRBool operator>=(const nsStr &S) const;
|
||||
PRBool operator>=(const char* aString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
|
||||
#endif // !defined(NEW_STRING_APIS)
|
||||
/**
|
||||
* 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.
|
||||
@@ -773,6 +822,11 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#ifdef NEW_STRING_APIS
|
||||
NS_DEF_NON_TEMPLATE_STRING_COMPARISON_OPERATORS(const nsString&, const PRUnichar*)
|
||||
NS_DEF_NON_TEMPLATE_STRING_COMPARISON_OPERATORS(const PRUnichar*, const nsString&)
|
||||
#endif
|
||||
|
||||
extern NS_COM int fputs(const nsString& aString, FILE* out);
|
||||
//ostream& operator<<(ostream& aStream,const nsString& aString);
|
||||
//virtual void DebugDump(ostream& aStream) const;
|
||||
|
||||
Reference in New Issue
Block a user