wip for nsString classes; not part of build
git-svn-id: svn://10.0.0.236/trunk@64738 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,13 @@
|
||||
|
||||
#include "nsString2x.h"
|
||||
#include "nsStringx.h"
|
||||
#include "nsString2.h"
|
||||
#include "nsString.h"
|
||||
#include "nsBufferManager.h"
|
||||
#include <stdio.h>
|
||||
#include "nsAutoStringImpl.h"
|
||||
#include <stdlib.h>
|
||||
#include "nsIAllocator.h"
|
||||
|
||||
static const char* kNullPointerError = "Unexpected null pointer";
|
||||
static const char* kWhitespace="\b\t\r\n ";
|
||||
|
||||
//******************************************
|
||||
// Ctor's
|
||||
@@ -22,6 +26,16 @@ nsString::nsString(const nsCString &aString,PRInt32 aLength) : mStringValue() {
|
||||
Assign(aString,aLength);
|
||||
}
|
||||
|
||||
//call this version for a single char of type char...
|
||||
nsString::nsString(const nsSubsumeStr &aSubsumeString) : mStringValue(aSubsumeString.mLHS) {
|
||||
SVAppend(mStringValue,aSubsumeString.mRHS,aSubsumeString.mRHS.mLength,0);
|
||||
}
|
||||
|
||||
//call this version for a single char of type char...
|
||||
nsString::nsString(nsSubsumeStr &aSubsumeString) : mStringValue(aSubsumeString.mLHS) {
|
||||
SVAppend(mStringValue,aSubsumeString.mRHS,aSubsumeString.mRHS.mLength,0);
|
||||
}
|
||||
|
||||
//call this version for char*'s....
|
||||
nsString::nsString(const PRUnichar* aString,PRInt32 aLength) : mStringValue() {
|
||||
Assign(aString,aLength,0);
|
||||
@@ -35,7 +49,7 @@ nsString::nsString(const char aChar) : mStringValue() {
|
||||
|
||||
//call this version for PRUnichar*'s....
|
||||
nsString::nsString(const char* aString,PRInt32 aLength) : mStringValue() {
|
||||
nsStringValueImpl<char> theString(const_cast<char*>(aString),aLength);
|
||||
nsStringValueImpl<char> theString(CONST_CAST(char*,aString),aLength);
|
||||
SVAssign(mStringValue,theString,theString.mLength,0);
|
||||
}
|
||||
|
||||
@@ -45,11 +59,17 @@ nsString::nsString(const nsAReadableString &aString) : mStringValue() {
|
||||
}
|
||||
|
||||
//call this version for stack-based string buffers...
|
||||
nsString::nsString(const nsStackBuffer<PRUnichar> &aBuffer) : mStringValue(aBuffer) {
|
||||
nsString::nsString(const nsUStackBuffer &aBuffer) : mStringValue(aBuffer) {
|
||||
}
|
||||
|
||||
nsString::~nsString() { }
|
||||
|
||||
void nsString::Reinitialize(PRUnichar* aBuffer,PRUint32 aCapacity,PRInt32 aLength) {
|
||||
mStringValue.mBuffer=aBuffer;
|
||||
mStringValue.mCapacity=aCapacity;
|
||||
mStringValue.mLength=aLength;
|
||||
mStringValue.mRefCount=1;
|
||||
}
|
||||
|
||||
//******************************************
|
||||
// Assigment operators
|
||||
@@ -67,16 +87,22 @@ nsString& nsString::operator=(const nsCString &aString) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsString& nsString::operator=(const nsSubsumeStr &aSubsumeString) {
|
||||
//XXX NOT IMPLEMENTED
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
nsString& nsString::operator=(const PRUnichar *aString) {
|
||||
if(mStringValue.mBuffer!=aString) {
|
||||
nsStringValueImpl<PRUnichar> theStringValue(const_cast<PRUnichar*>(aString));
|
||||
nsStringValueImpl<PRUnichar> theStringValue(CONST_CAST(PRUnichar*,aString));
|
||||
Assign(aString);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsString& nsString::operator=(const char *aString) {
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString));
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString));
|
||||
SVAssign(mStringValue,theStringValue,theStringValue.mLength,0);
|
||||
return *this;
|
||||
}
|
||||
@@ -98,19 +124,11 @@ nsString& nsString::operator=(const PRUnichar aChar) {
|
||||
|
||||
nsresult nsString::SetCapacity(PRUint32 aCapacity) {
|
||||
if(aCapacity>mStringValue.mCapacity) {
|
||||
SVGrowCapacity<PRUnichar>(mStringValue,aCapacity);
|
||||
SVAddNullTerminator<PRUnichar>(mStringValue);
|
||||
SVRealloc(mStringValue,aCapacity);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRUnichar& nsString::operator[](PRUint32 aOffset) {
|
||||
static PRUnichar gSharedChar=0;
|
||||
return (mStringValue.mBuffer) ? mStringValue.mBuffer[aOffset] : gSharedChar;
|
||||
}
|
||||
|
||||
// operator const char* const() {return mStringValue.mBuffer;}
|
||||
|
||||
|
||||
PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex) {
|
||||
PRBool result=PR_FALSE;
|
||||
@@ -121,10 +139,6 @@ PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//these aren't the real deal, but serve as a placeholder for us to implement iterators.
|
||||
nsAReadableStringIterator* nsString::First() {return new nsAReadableStringIterator(); }
|
||||
nsAReadableStringIterator* nsString::Last() {return new nsAReadableStringIterator(); }
|
||||
|
||||
|
||||
//******************************************
|
||||
// Here are the Assignment methods,
|
||||
@@ -132,7 +146,7 @@ nsAReadableStringIterator* nsString::Last() {return new nsAReadableStringIterato
|
||||
//******************************************
|
||||
|
||||
nsresult nsString::Truncate(PRUint32 anOffset) {
|
||||
SVTruncate<PRUnichar>(mStringValue,anOffset);
|
||||
SVTruncate(mStringValue,anOffset);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -182,7 +196,7 @@ nsresult nsString::Assign(const nsCString& aString,PRInt32 aLength,PRUint32 aSrc
|
||||
//assign from an nsAReadableString (the ABT)
|
||||
nsresult nsString::Assign(const nsAReadableString &aString,PRInt32 aLength,PRUint32 aSrcOffset) {
|
||||
Truncate();
|
||||
return SVAppendReadable<PRUnichar>(mStringValue,aString,aLength,aSrcOffset);
|
||||
return SVAppendReadable(mStringValue,aString,aLength,aSrcOffset);
|
||||
}
|
||||
|
||||
//assign from a char
|
||||
@@ -211,55 +225,73 @@ nsresult nsString::Assign(PRUnichar aChar) {
|
||||
* @return this
|
||||
*/
|
||||
nsresult nsString::Append(const nsString &aString,PRInt32 aLength,PRUint32 aSrcOffset) {
|
||||
aLength = (aLength<0) ? aString.mStringValue.mLength : MinInt(aLength,aString.mStringValue.mLength);
|
||||
return SVAppend< PRUnichar, PRUnichar > (mStringValue,aString.mStringValue,aLength,aSrcOffset);
|
||||
aLength = (aLength<0) ? aString.mStringValue.mLength : (aLength<(PRInt32)aString.mStringValue.mLength) ? aLength: aString.mStringValue.mLength;
|
||||
return SVAppend (mStringValue,aString.mStringValue,aLength,aSrcOffset);
|
||||
}
|
||||
|
||||
//append from a type compatible string pointer
|
||||
nsresult nsString::Append(const char* aString,PRInt32 aLength,PRUint32 aSrcOffset) {
|
||||
nsresult result=NS_OK;
|
||||
if(aString) {
|
||||
if(aLength<0) aLength=nsCRT::strlen(aString);
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString),aLength);
|
||||
result=SVAppend< PRUnichar, char > (mStringValue,theStringValue,aLength,aSrcOffset);
|
||||
if(aLength<0) aLength=stringlen(aString);
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString),aLength);
|
||||
result=SVAppend(mStringValue,theStringValue,aLength,aSrcOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//append from alternative type string pointer
|
||||
nsresult nsString::Append(const char aChar) {
|
||||
char theBuffer[]={aChar,0};
|
||||
nsStringValueImpl<char> theStringValue(theBuffer,1);
|
||||
return SVAppend< PRUnichar, char > (mStringValue,theStringValue,1,0);
|
||||
|
||||
if(mStringValue.mLength==mStringValue.mCapacity) {
|
||||
SVRealloc(mStringValue,mStringValue.mCapacity+5);
|
||||
}
|
||||
|
||||
if(mStringValue.mLength<mStringValue.mCapacity) {
|
||||
//an optimized code path when our buffer can easily contain the given char...
|
||||
mStringValue.mBuffer[mStringValue.mLength++]=aChar;
|
||||
mStringValue.mBuffer[mStringValue.mLength]=0;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//append from alternative type string pointer
|
||||
nsresult nsString::Append(const PRUnichar aChar) {
|
||||
PRUnichar theBuffer[]={aChar,0};
|
||||
nsStringValueImpl<PRUnichar> theStringValue(theBuffer,1);
|
||||
return SVAppend< PRUnichar,PRUnichar> (mStringValue,theStringValue,1,0);
|
||||
|
||||
if(mStringValue.mLength==mStringValue.mCapacity) {
|
||||
SVRealloc(mStringValue,mStringValue.mCapacity+5);
|
||||
}
|
||||
|
||||
if(mStringValue.mLength<mStringValue.mCapacity) {
|
||||
//an optimized code path when our buffer can easily contain the given char...
|
||||
mStringValue.mBuffer[mStringValue.mLength++]=aChar;
|
||||
mStringValue.mBuffer[mStringValue.mLength]=0;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//append from alternative type string pointer
|
||||
nsresult nsString::Append(const PRUnichar* aString,PRInt32 aLength,PRUint32 aSrcOffset) {
|
||||
nsresult result=NS_OK;
|
||||
if(aString) {
|
||||
nsStringValueImpl<PRUnichar> theStringValue(const_cast<PRUnichar*>(aString),aLength);
|
||||
result=SVAppend< PRUnichar,PRUnichar> (mStringValue,theStringValue,aLength,aSrcOffset);
|
||||
nsStringValueImpl<PRUnichar> theStringValue(CONST_CAST(PRUnichar*,aString),aLength);
|
||||
result=SVAppend (mStringValue,theStringValue,aLength,aSrcOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//append from an nsCString
|
||||
nsresult nsString::Append(const nsCString &aString,PRInt32 aLength,PRUint32 aSrcOffset) {
|
||||
aLength = (aLength<0) ? aString.mStringValue.mLength : MinInt(aLength,aString.mStringValue.mLength);
|
||||
return SVAppend< PRUnichar, char > (mStringValue,aString.mStringValue,aLength,aSrcOffset);
|
||||
aLength = (aLength<0) ? aString.mStringValue.mLength : (aLength<(PRInt32)aString.mStringValue.mLength) ? aLength: aString.mStringValue.mLength;
|
||||
return SVAppend (mStringValue,aString.mStringValue,aLength,aSrcOffset);
|
||||
}
|
||||
|
||||
//append from an nsAReadableString (the ABT)
|
||||
nsresult nsString::Append(const nsAReadableString &aString,PRInt32 aLength,PRUint32 aSrcOffset) {
|
||||
aLength = (aLength<0) ? aString.Length() : MinInt(aLength,aString.Length());
|
||||
return SVAppendReadable<PRUnichar> (mStringValue,aString,aLength,aSrcOffset);
|
||||
return SVAppendReadable(mStringValue,aString,aLength,aSrcOffset);
|
||||
}
|
||||
|
||||
//append an integer
|
||||
@@ -315,11 +347,11 @@ nsresult nsString::Append(float aFloat) {
|
||||
//***************************************
|
||||
|
||||
nsresult nsString::Cut(PRUint32 anOffset,PRInt32 aCount) {
|
||||
return SVDelete<PRUnichar>(mStringValue,anOffset,aCount);
|
||||
return (0<aCount) ? SVDelete(mStringValue,anOffset,aCount) : NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsString::Trim(const char* aTrimSet,PRBool aEliminateLeading,PRBool aEliminateTrailing,PRBool aIgnoreQuotes) {
|
||||
return SVTrim<PRUnichar>(mStringValue,aTrimSet,aEliminateLeading,aEliminateTrailing);
|
||||
return SVTrim(mStringValue,aTrimSet,aEliminateLeading,aEliminateTrailing);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -333,8 +365,7 @@ nsresult nsString::Trim(const char* aTrimSet,PRBool aEliminateLeading,PRBool aEl
|
||||
* @return this
|
||||
*/
|
||||
nsresult nsString::CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
nsStringValueImpl<char> theSet(const_cast<char*>(aSet));
|
||||
return SVCompressSet<PRUnichar>(mStringValue,theSet,aChar,aEliminateLeading,aEliminateTrailing);
|
||||
return SVCompressSet(mStringValue,aSet,aChar,aEliminateLeading,aEliminateTrailing);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -367,7 +398,7 @@ nsresult nsString::CompressWhitespace( PRBool aEliminateLeading,PRBool aEliminat
|
||||
* @return this
|
||||
*/
|
||||
nsresult nsString::Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
||||
return SVInsert<PRUnichar>(mStringValue,anOffset,aCopy.mStringValue,aCount,anOffset);
|
||||
return SVInsert(mStringValue,anOffset,aCopy.mStringValue,aCount,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -385,10 +416,10 @@ nsresult nsString::Insert(const char* aString,PRUint32 anOffset,PRInt32 aLength)
|
||||
nsresult result=NS_OK;
|
||||
if(aString){
|
||||
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString),aLength);
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString),aLength);
|
||||
|
||||
if(0<theStringValue.mLength){
|
||||
result=SVInsert<PRUnichar>(mStringValue,anOffset,theStringValue,theStringValue.mLength,0);
|
||||
result=SVInsert(mStringValue,anOffset,theStringValue,theStringValue.mLength,0);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -409,10 +440,10 @@ nsresult nsString::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aLe
|
||||
nsresult result=NS_OK;
|
||||
if(aString){
|
||||
|
||||
nsStringValueImpl<PRUnichar> theStringValue(const_cast<PRUnichar*>(aString),aLength);
|
||||
nsStringValueImpl<PRUnichar> theStringValue(CONST_CAST(PRUnichar*,aString),aLength);
|
||||
|
||||
if(0<theStringValue.mLength){
|
||||
result=SVInsert<PRUnichar>(mStringValue,anOffset,theStringValue,theStringValue.mLength,0);
|
||||
result=SVInsert(mStringValue,anOffset,theStringValue,theStringValue.mLength,0);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -431,7 +462,7 @@ nsresult nsString::Insert(char aChar,PRUint32 anOffset){
|
||||
char theBuffer[]={aChar,0};
|
||||
nsStringValueImpl<char> theStringValue(theBuffer,1);
|
||||
|
||||
return SVInsert<PRUnichar>(mStringValue,anOffset,theStringValue,1,0);
|
||||
return SVInsert(mStringValue,anOffset,theStringValue,1,0);
|
||||
}
|
||||
|
||||
|
||||
@@ -445,26 +476,34 @@ nsresult nsString::Insert(char aChar,PRUint32 anOffset){
|
||||
* @return this
|
||||
*/
|
||||
nsresult nsString::ReplaceChar(char anOldChar,char aNewChar){
|
||||
return SVReplaceChar<PRUnichar>(mStringValue,anOldChar,aNewChar,mStringValue.mLength,0);
|
||||
PRUnichar *root_cp=mStringValue.mBuffer;
|
||||
PRUnichar *null_cp=root_cp+mStringValue.mLength;
|
||||
|
||||
while(root_cp<null_cp) {
|
||||
if(*root_cp==anOldChar) {
|
||||
*root_cp=aNewChar;
|
||||
}
|
||||
root_cp++;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsString::ReplaceChar(const char* aSet,char aNewChar){
|
||||
nsStringValueImpl<char> theSet(const_cast<char*>(aSet));
|
||||
return SVReplaceCharsInSet<PRUnichar>(mStringValue,theSet,aNewChar,mStringValue.mLength,0);
|
||||
return SVReplaceCharsInSet(mStringValue,aSet,aNewChar,mStringValue.mLength,0);
|
||||
}
|
||||
|
||||
nsresult nsString::ReplaceSubstring( const nsString& aTarget,const nsString& aNewValue){
|
||||
return SVReplace<PRUnichar>(mStringValue,aTarget.mStringValue,aNewValue.mStringValue,mStringValue.mLength,0);
|
||||
return SVReplace(mStringValue,aTarget.mStringValue,aNewValue.mStringValue,mStringValue.mLength,0);
|
||||
}
|
||||
|
||||
|
||||
nsresult nsString::ReplaceSubstring(const char* aTarget,const char* aNewValue) {
|
||||
nsresult result=NS_OK;
|
||||
|
||||
const nsStringValueImpl<char> theTarget(const_cast<char*>(aTarget));
|
||||
const nsStringValueImpl<char> theNewValue(const_cast<char*>(aNewValue));
|
||||
const nsStringValueImpl<char> theTarget(CONST_CAST(char*,aTarget));
|
||||
const nsStringValueImpl<char> theNewValue(CONST_CAST(char*,aNewValue));
|
||||
|
||||
return SVReplace<PRUnichar>(mStringValue,theTarget,theNewValue,mStringValue.mLength,0);
|
||||
return SVReplace(mStringValue,theTarget,theNewValue,mStringValue.mLength,0);
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
@@ -480,8 +519,8 @@ nsresult nsString::ReplaceSubstring(const char* aTarget,const char* aNewValue) {
|
||||
* @param anOffset -- where in this string to start stripping chars
|
||||
* @return *this
|
||||
*/
|
||||
nsresult nsString::StripChar(char aChar,PRUint32 anOffset){
|
||||
return SVStripChar<PRUnichar>(mStringValue,aChar,mStringValue.mLength,anOffset);
|
||||
nsresult nsString::StripChar(PRUnichar aChar,PRUint32 anOffset){
|
||||
return SVStripChar(mStringValue,aChar,mStringValue.mLength,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -494,7 +533,7 @@ nsresult nsString::StripChar(char aChar,PRUint32 anOffset){
|
||||
* @return *this
|
||||
*/
|
||||
nsresult nsString::StripChar(PRInt32 anInt,PRUint32 anOffset){
|
||||
return SVStripChar<PRUnichar>(mStringValue,(PRUnichar)anInt,mStringValue.mLength,anOffset);
|
||||
return SVStripChar(mStringValue,(PRUnichar)anInt,mStringValue.mLength,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -505,9 +544,9 @@ nsresult nsString::StripChar(PRInt32 anInt,PRUint32 anOffset){
|
||||
* @param aSet -- characters to be cut from this
|
||||
* @return *this
|
||||
*/
|
||||
nsresult nsString::StripChars(const char* aSet){
|
||||
nsStringValueImpl<char> theSet(const_cast<char*>(aSet));
|
||||
return SVStripCharsInSet<PRUnichar>(mStringValue,aSet,mStringValue.mLength,0);
|
||||
nsresult nsString::StripChars(const char* aSet,PRInt32 aLength){
|
||||
nsStringValueImpl<char> theSet(CONST_CAST(char*,aSet),aLength);
|
||||
return SVStripCharsInSet(mStringValue,aSet,mStringValue.mLength,0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -526,21 +565,44 @@ nsresult nsString::StripWhitespace() {
|
||||
//**************************************************
|
||||
|
||||
nsresult nsString::Left(nsString& aCopy,PRInt32 aCount) const {
|
||||
aCount = (aCount<0) ? mStringValue.mLength : MinInt(aCount,mStringValue.mLength);
|
||||
aCount = (aCount<0) ? mStringValue.mLength : (aCount<(PRInt32)mStringValue.mLength) ? aCount : mStringValue.mLength;
|
||||
return aCopy.Assign(*this,aCount,0);
|
||||
}
|
||||
|
||||
nsresult nsString::Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const {
|
||||
aCount = (aCount<0) ? mStringValue.mLength : MinInt(aCount,mStringValue.mLength);
|
||||
aCount = (aCount<0) ? mStringValue.mLength : (aCount<(PRInt32)mStringValue.mLength) ? aCount : mStringValue.mLength;
|
||||
return aCopy.Assign(*this,aCount,anOffset);
|
||||
}
|
||||
|
||||
nsresult nsString::Right(nsString& aCopy,PRInt32 aCount) const {
|
||||
PRInt32 offset=MaxInt(mStringValue.mLength-aCount,0);
|
||||
PRUint32 theLen=mStringValue.mLength-aCount;
|
||||
PRInt32 offset=(theLen<0) ? 0 : theLen;
|
||||
return Mid(aCopy,offset,aCount);
|
||||
}
|
||||
|
||||
//******************************************
|
||||
// Concatenation operators
|
||||
//******************************************
|
||||
|
||||
nsSubsumeStr nsString::operator+(const nsString &aString) {
|
||||
nsSubsumeStr result(mStringValue,aString.mStringValue);
|
||||
return result;
|
||||
}
|
||||
|
||||
nsSubsumeStr nsString::operator+(const PRUnichar* aString) {
|
||||
nsSubsumeStr result; //NOT IMPLEMENTED
|
||||
return result;
|
||||
}
|
||||
|
||||
nsSubsumeStr nsString::operator+(const char* aCString) {
|
||||
nsSubsumeStr result; //NOT IMPLEMENTED
|
||||
return result;
|
||||
}
|
||||
|
||||
nsSubsumeStr nsString::operator+(PRUnichar aChar) {
|
||||
nsSubsumeStr result; //NOT IMPLEMENTED
|
||||
return result;
|
||||
}
|
||||
//*******************************************
|
||||
// Here come the operator+=() methods...
|
||||
//*******************************************
|
||||
@@ -578,7 +640,7 @@ nsString& nsString::operator+=(const int anInt){
|
||||
}
|
||||
|
||||
void nsString::ToLowerCase() {
|
||||
SVToLowerCase<PRUnichar>(mStringValue);
|
||||
SVToLowerCase(mStringValue);
|
||||
}
|
||||
|
||||
void nsString::ToLowerCase(nsString &aString) const {
|
||||
@@ -587,7 +649,7 @@ void nsString::ToLowerCase(nsString &aString) const {
|
||||
}
|
||||
|
||||
void nsString::ToUpperCase() {
|
||||
SVToUpperCase<PRUnichar>(mStringValue);
|
||||
SVToUpperCase(mStringValue);
|
||||
}
|
||||
|
||||
void nsString::ToUpperCase(nsString &aString) const {
|
||||
@@ -597,52 +659,78 @@ void nsString::ToUpperCase(nsString &aString) const {
|
||||
|
||||
|
||||
PRInt32 nsString::Compare(const nsString &aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
||||
return SVCompare<PRUnichar,PRUnichar>(mStringValue,aString.mStringValue,aIgnoreCase,aCount);
|
||||
return SVCompareChars(mStringValue,aString.mStringValue,aIgnoreCase,aCount);
|
||||
}
|
||||
|
||||
PRInt32 nsString::Compare(const nsCString &aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
||||
return SVCompare<PRUnichar,char>(mStringValue,aString.mStringValue,aIgnoreCase,aCount);
|
||||
return SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount);
|
||||
}
|
||||
|
||||
PRInt32 nsString::Compare(const char* aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString),aCount);
|
||||
return SVCompare<PRUnichar,char>(mStringValue,theStringValue,aIgnoreCase,aCount);
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString),aCount);
|
||||
return SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount);
|
||||
}
|
||||
|
||||
PRInt32 nsString::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
||||
nsStringValueImpl<PRUnichar> theStringValue(const_cast<PRUnichar*>(aString),aCount);
|
||||
return SVCompare<PRUnichar,PRUnichar>(mStringValue,theStringValue,aIgnoreCase,aCount);
|
||||
nsStringValueImpl<PRUnichar> theStringValue(CONST_CAST(PRUnichar*,aString),aCount);
|
||||
return SVCompareChars(mStringValue,theStringValue,aIgnoreCase,aCount);
|
||||
}
|
||||
|
||||
PRBool nsString::Equals(const nsString &aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
||||
PRInt32 result=SVCompare<PRUnichar,PRUnichar>(mStringValue,aString.mStringValue,aIgnoreCase,aCount);
|
||||
return PRBool(0==result);
|
||||
return PRBool(0==SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount));
|
||||
}
|
||||
|
||||
PRBool nsString::Equals(const nsCString &aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
||||
PRInt32 result=SVCompare<PRUnichar,char>(mStringValue,aString.mStringValue,aIgnoreCase,aCount);
|
||||
return PRBool(0==result);
|
||||
return PRBool(0==SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount));
|
||||
}
|
||||
|
||||
PRBool nsString::Equals(const char* aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString),aCount);
|
||||
PRInt32 result=SVCompare<PRUnichar,char>(mStringValue,theStringValue,aIgnoreCase,aCount);
|
||||
return PRBool(0==result);
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString),aCount);
|
||||
return PRBool(0==SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount));
|
||||
}
|
||||
|
||||
|
||||
PRBool nsString::Equals(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
||||
nsStringValueImpl<PRUnichar> theStringValue(const_cast<PRUnichar*>(aString),aCount);
|
||||
PRInt32 result=SVCompare<PRUnichar,PRUnichar>(mStringValue,theStringValue,aIgnoreCase,aCount);
|
||||
return PRBool(0==result);
|
||||
nsStringValueImpl<PRUnichar> theStringValue(CONST_CAST(PRUnichar*,aString),aCount);
|
||||
return PRBool(0==SVCompareChars(mStringValue,theStringValue,aIgnoreCase,aCount));
|
||||
}
|
||||
|
||||
PRBool nsString::EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const {
|
||||
PRBool result=PR_FALSE;
|
||||
PRBool nsString::Equals(const PRUnichar* aLHS,const PRUnichar* aRHS,PRBool aIgnoreCase) const {
|
||||
NS_ASSERTION(0!=aLHS,kNullPointerError);
|
||||
NS_ASSERTION(0!=aRHS,kNullPointerError);
|
||||
PRBool result=PR_FALSE;
|
||||
if((aLHS) && (aRHS)){
|
||||
|
||||
|
||||
// PRInt32 cmp=(aIgnoreCase) ? nsCRT::strcasecmp(aLHS,aRHS) : nsCRT::strcmp(aLHS,aRHS);
|
||||
// result=PRBool(0==cmp);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
|
||||
PRBool nsString::Equals(/*FIX: const */nsIAtom* aAtom,PRBool aIgnoreCase) const{
|
||||
NS_ASSERTION(0!=aAtom,kNullPointerError);
|
||||
PRBool result=PR_FALSE;
|
||||
|
||||
#if 0
|
||||
|
||||
if(aAtom){
|
||||
PRInt32 cmp=0;
|
||||
const PRUnichar* unicode;
|
||||
if (aAtom->GetUnicode(&unicode) != NS_OK || unicode == nsnull)
|
||||
return PR_FALSE;
|
||||
if (aIgnoreCase)
|
||||
cmp=nsCRT::strcasecmp(mUStr,unicode);
|
||||
else
|
||||
cmp=nsCRT::strcmp(mUStr,unicode);
|
||||
result=PRBool(0==cmp);
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/***************************************
|
||||
@@ -660,7 +748,7 @@ PRBool nsString::EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) cons
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 nsString::Find(const nsString& aTarget,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const {
|
||||
return SVFind<PRUnichar,PRUnichar>(mStringValue,aTarget.mStringValue,aIgnoreCase,aRepCount,anOffset);
|
||||
return SVFind(mStringValue,aTarget.mStringValue,aIgnoreCase,aRepCount,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -674,7 +762,7 @@ PRInt32 nsString::Find(const nsString& aTarget,PRBool aIgnoreCase,PRUint32 anOff
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 nsString::Find(const nsCString &aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const {
|
||||
return SVFind<PRUnichar,char>(mStringValue,aString.mStringValue,aIgnoreCase,aRepCount,anOffset);
|
||||
return SVFind(mStringValue,aString.mStringValue,aIgnoreCase,aRepCount,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -688,8 +776,8 @@ PRInt32 nsString::Find(const nsCString &aString,PRBool aIgnoreCase,PRUint32 anOf
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 nsString::Find(const char* aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const {
|
||||
nsStringValueImpl<char> theString(const_cast<char*>(aString));
|
||||
return SVFind<PRUnichar,char>(mStringValue,theString,aIgnoreCase,aRepCount,anOffset);
|
||||
nsStringValueImpl<char> theString(CONST_CAST(char*,aString));
|
||||
return SVFind(mStringValue,theString,aIgnoreCase,aRepCount,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -704,8 +792,8 @@ PRInt32 nsString::Find(const char* aString,PRBool aIgnoreCase,PRUint32 anOffset,
|
||||
*/
|
||||
PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const {
|
||||
|
||||
nsStringValueImpl<PRUnichar> theString(const_cast<PRUnichar*>(aString));
|
||||
return SVFind<PRUnichar,PRUnichar>(mStringValue,theString,aIgnoreCase,aRepCount,anOffset);
|
||||
nsStringValueImpl<PRUnichar> theString(CONST_CAST(PRUnichar*,aString));
|
||||
return SVFind(mStringValue,theString,aIgnoreCase,aRepCount,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -718,7 +806,7 @@ PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRUint32 anOf
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsString::FindCharInSet(const nsString& aString,PRUint32 anOffset) const{
|
||||
return SVFindCharInSet<PRUnichar,PRUnichar>(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
return SVFindCharInSet(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
}
|
||||
|
||||
|
||||
@@ -733,8 +821,8 @@ PRInt32 nsString::FindCharInSet(const nsString& aString,PRUint32 anOffset) const
|
||||
*/
|
||||
PRInt32 nsString::FindCharInSet(const char *aString,PRUint32 anOffset) const{
|
||||
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString));
|
||||
return SVFindCharInSet<PRUnichar,char>(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString));
|
||||
return SVFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -748,8 +836,8 @@ PRInt32 nsString::FindCharInSet(const char *aString,PRUint32 anOffset) const{
|
||||
*/
|
||||
PRInt32 nsString::FindCharInSet(const PRUnichar *aString,PRUint32 anOffset) const{
|
||||
|
||||
nsStringValueImpl<PRUnichar> theStringValue(const_cast<PRUnichar*>(aString));
|
||||
return SVFindCharInSet<PRUnichar,PRUnichar>(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
nsStringValueImpl<PRUnichar> theStringValue(CONST_CAST(PRUnichar*,aString));
|
||||
return SVFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -763,7 +851,7 @@ PRInt32 nsString::FindCharInSet(const PRUnichar *aString,PRUint32 anOffset) cons
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 nsString::FindChar(char aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const {
|
||||
return SVFindChar<PRUnichar>(mStringValue,aChar,aIgnoreCase,aCount,anOffset);
|
||||
return SVFindChar(mStringValue,aChar,aIgnoreCase,aCount,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -777,7 +865,7 @@ PRInt32 nsString::FindChar(char aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt3
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 nsString::RFindChar(char aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aRepCount) const{
|
||||
return SVRFindChar<PRUnichar>(mStringValue,aChar,aIgnoreCase,aRepCount,anOffset);
|
||||
return SVRFindChar(mStringValue,aChar,aIgnoreCase,aRepCount,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -795,20 +883,20 @@ PRInt32 nsString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOff
|
||||
PRInt32 result=kNotFound;
|
||||
|
||||
if(0<=theMaxPos) {
|
||||
result=SVRFind<PRUnichar,PRUnichar>(mStringValue,aString.mStringValue,aIgnoreCase,aRepCount,anOffset);
|
||||
result=SVRFind(mStringValue,aString.mStringValue,aIgnoreCase,aRepCount,anOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aRepCount) const{
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString));
|
||||
return SVRFind<PRUnichar,char>(mStringValue,theStringValue,aIgnoreCase,aRepCount,anOffset);
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString));
|
||||
return SVRFind(mStringValue,theStringValue,aIgnoreCase,aRepCount,anOffset);
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsString::RFind(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aRepCount) const{
|
||||
nsStringValueImpl<PRUnichar> theStringValue(const_cast<PRUnichar*>(aString));
|
||||
return SVRFind<PRUnichar,PRUnichar>(mStringValue,theStringValue,aIgnoreCase,aRepCount,anOffset);
|
||||
nsStringValueImpl<PRUnichar> theStringValue(CONST_CAST(PRUnichar*,aString));
|
||||
return SVRFind(mStringValue,theStringValue,aIgnoreCase,aRepCount,anOffset);
|
||||
}
|
||||
/**
|
||||
* This method finds (in reverse) the offset of the first char in this string that is
|
||||
@@ -820,7 +908,7 @@ PRInt32 nsString::RFind(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOf
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsString::RFindCharInSet(const nsString& aString,PRInt32 anOffset) const {
|
||||
return SVRFindCharInSet<PRUnichar,PRUnichar>(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
return SVRFindCharInSet(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -833,8 +921,8 @@ PRInt32 nsString::RFindCharInSet(const nsString& aString,PRInt32 anOffset) const
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsString::RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset) const{
|
||||
nsStringValueImpl<PRUnichar> theStringValue(const_cast<PRUnichar*>(aString));
|
||||
return SVRFindCharInSet<PRUnichar,PRUnichar>(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
nsStringValueImpl<PRUnichar> theStringValue(CONST_CAST(PRUnichar*,aString));
|
||||
return SVRFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -847,8 +935,8 @@ PRInt32 nsString::RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset) cons
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsString::RFindCharInSet(const char* aString,PRInt32 anOffset) const{
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString));
|
||||
return SVRFindCharInSet<PRUnichar,char>(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString));
|
||||
return SVRFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
}
|
||||
|
||||
/***************************************
|
||||
@@ -894,7 +982,7 @@ char* nsString::ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset) cons
|
||||
|
||||
|
||||
PRInt32 nsString::CountChar(PRUnichar aChar) {
|
||||
return SVCountChar<PRUnichar>(mStringValue,aChar);
|
||||
return SVCountChar(mStringValue,aChar);
|
||||
}
|
||||
|
||||
//******************************************
|
||||
@@ -904,7 +992,7 @@ PRInt32 nsString::CountChar(PRUnichar aChar) {
|
||||
|
||||
//This will not work correctly for any unicode set other than ascii
|
||||
void nsString::DebugDump(void) const {
|
||||
SVDebugDump<PRUnichar>(mStringValue);
|
||||
SVDebugDump(mStringValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -919,7 +1007,7 @@ float nsString::ToFloat(PRInt32* aErrorCode) const {
|
||||
return 0.0f;
|
||||
}
|
||||
char* cp = ToCString(buf, sizeof(buf));
|
||||
float f = (float) PR_strtod(cp, &cp);
|
||||
float f = (float) strtod(cp, &cp);
|
||||
if (*cp != 0) {
|
||||
*aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
@@ -938,7 +1026,264 @@ PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const{
|
||||
}
|
||||
|
||||
nsresult nsString::Append(const nsStringValueImpl<char> &aString,PRInt32 aLength,PRUint32 aSrcOffset) {
|
||||
aLength = (aLength<0) ? aString.mLength : MinInt(aLength,aString.mLength);
|
||||
return SVAppend< PRUnichar, char> (mStringValue,aString,aLength,aSrcOffset);
|
||||
aLength = (aLength<0) ? aString.mLength : (aLength<(PRInt32)aString.mLength) ? aLength: aString.mLength;
|
||||
return SVAppend(mStringValue,aString,aLength,aSrcOffset);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
Now we declare the nsCSubsumeString class
|
||||
*****************************************************************/
|
||||
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr() {
|
||||
}
|
||||
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(const nsString& aString) : mLHS(aString.mStringValue), mRHS() {
|
||||
}
|
||||
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(const nsSubsumeStr& aSubsumeString) :
|
||||
mLHS(aSubsumeString.mLHS),
|
||||
mRHS(aSubsumeString.mRHS) {
|
||||
}
|
||||
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(const nsStringValueImpl<PRUnichar> &aLHS,const nsSubsumeStr& aSubsumeString) :
|
||||
mLHS(aLHS),
|
||||
mRHS(aSubsumeString.mLHS) {
|
||||
}
|
||||
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(const nsStringValueImpl<PRUnichar> &aLHS,const nsStringValueImpl<PRUnichar> &aRHS) :
|
||||
mLHS(aLHS),
|
||||
mRHS(aRHS) {
|
||||
}
|
||||
|
||||
nsSubsumeStr::nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength) {
|
||||
}
|
||||
|
||||
nsSubsumeStr nsSubsumeStr::operator+(const nsSubsumeStr &aSubsumeString) {
|
||||
nsSubsumeStr result(*this);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
nsSubsumeStr nsSubsumeStr::operator+(const nsString &aString) {
|
||||
SVAppend(mLHS,mRHS,mRHS.mLength,0);
|
||||
memcpy(&mRHS,&aString.mStringValue,sizeof(mRHS));
|
||||
return *this;
|
||||
}
|
||||
|
||||
int nsSubsumeStr::Subsume(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength) {
|
||||
//XXX NOT IMPLEMENTED
|
||||
int result=0;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_COM int fputs(const nsString& aString, FILE* out)
|
||||
{
|
||||
char buf[100];
|
||||
char* cp = buf;
|
||||
PRInt32 len = aString.Length();
|
||||
if (len >= PRInt32(sizeof(buf))) {
|
||||
cp = aString.ToNewCString();
|
||||
} else {
|
||||
aString.ToCString(cp, len + 1);
|
||||
}
|
||||
if(len>0)
|
||||
::fwrite(cp, 1, len, out);
|
||||
if (cp != buf) {
|
||||
delete[] cp;
|
||||
}
|
||||
return (int) len;
|
||||
}
|
||||
|
||||
PRUint32 HashCode(const nsString& aDest) {
|
||||
PRUint32 h = 0;
|
||||
PRUint32 n = aDest.Length();
|
||||
PRUint32 m;
|
||||
const PRUnichar* c=aDest.GetUnicode();
|
||||
|
||||
if (n < 16) { /* Hash every char in a short string. */
|
||||
for(; n; c++, n--)
|
||||
h = (h >> 28) ^ (h << 4) ^ *c;
|
||||
}
|
||||
else { /* Sample a la java.lang.String.hash(). */
|
||||
for(m = n / 8; n >= m; c += m, n -= m)
|
||||
h = (h >> 28) ^ (h << 4) ^ *c;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
void Recycle( PRUnichar* aBuffer) {
|
||||
nsAllocator::Free(aBuffer);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
Now we declare the nsAutoString class
|
||||
*****************************************************************/
|
||||
|
||||
|
||||
nsAutoString::nsAutoString() : nsString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
mStringValue.mRefCount++; //so we don't try to delete our internal buffer
|
||||
}
|
||||
|
||||
//call this version nsAutoString derivatives...
|
||||
nsAutoString::nsAutoString(const nsAutoString& aString,PRInt32 aLength) : nsString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
mStringValue.mRefCount++; //so we don't try to delete our internal buffer
|
||||
Assign(aString,aLength);
|
||||
}
|
||||
|
||||
//call this version for nsString and the autostrings
|
||||
nsAutoString::nsAutoString(const nsString& aString,PRInt32 aLength) : nsString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
mStringValue.mRefCount++; //so we don't try to delete our internal buffer
|
||||
Assign(aString,aLength);
|
||||
}
|
||||
|
||||
//call this version with nsCString
|
||||
nsAutoString::nsAutoString(const nsCString& aString) : nsString(aString) {
|
||||
mStringValue.mRefCount++; //so we don't try to delete our internal buffer
|
||||
}
|
||||
|
||||
//call this version for char*'s....
|
||||
nsAutoString::nsAutoString(const char* aString,PRInt32 aLength) : nsString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
|
||||
nsStringValueImpl<char> theString(CONST_CAST(char*,aString),aLength);
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
mStringValue.mRefCount++; //so we don't try to delete our internal buffer
|
||||
SVAssign(mStringValue,theString,aLength,0);
|
||||
}
|
||||
|
||||
//call this version for a single char of type char...
|
||||
nsAutoString::nsAutoString(char aChar) : nsString() {
|
||||
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
mStringValue.mRefCount++; //so we don't try to delete our internal buffer
|
||||
|
||||
PRUnichar theBuffer[]={aChar,0};
|
||||
|
||||
Assign(theBuffer,1,0);
|
||||
}
|
||||
|
||||
//call this version for a single char of type char...
|
||||
nsAutoString::nsAutoString(PRUnichar aChar) : nsString() {
|
||||
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
mStringValue.mRefCount++; //so we don't try to delete our internal buffer
|
||||
|
||||
PRUnichar theBuffer[]={aChar,0};
|
||||
|
||||
Assign(theBuffer,1,0);
|
||||
}
|
||||
|
||||
|
||||
//call this version for PRUnichar*'s....
|
||||
nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
nsStringValueImpl<PRUnichar> theString(CONST_CAST(PRUnichar*,aString),aLength);
|
||||
mStringValue.mRefCount++; //so we don't try to delete our internal buffer
|
||||
SVAssign(mStringValue,theString,theString.mLength,0);
|
||||
}
|
||||
|
||||
|
||||
//call this version for all other ABT versions of readable strings
|
||||
nsAutoString::nsAutoString(const nsAReadableString &aString) : nsString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
mStringValue.mRefCount++; //so we don't try to delete our internal buffer
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
nsAutoString::nsAutoString(const nsUStackBuffer &aBuffer) : nsString() {
|
||||
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
|
||||
mStringValue.mLength=aBuffer.mLength;
|
||||
mStringValue.mCapacity=aBuffer.mCapacity;
|
||||
mStringValue.mBuffer=aBuffer.mBuffer;
|
||||
mStringValue.mRefCount++; //so we don't try to delete our internal buffer
|
||||
|
||||
}
|
||||
|
||||
nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
|
||||
mStringValue.mBuffer=(PRUnichar*)aBuffer.mBuffer;
|
||||
mStringValue.mCapacity=aBuffer.mCapacity;
|
||||
mStringValue.mLength=aBuffer.mLength;
|
||||
mStringValue.mRefCount=(aBuffer.mStackBased) ? 2 : 1;
|
||||
}
|
||||
|
||||
nsAutoString::nsAutoString(const nsSubsumeStr& aSubsumeStringX) : nsString() {
|
||||
}
|
||||
|
||||
|
||||
nsAutoString::~nsAutoString() { }
|
||||
|
||||
|
||||
nsAutoString& nsAutoString::operator=(const nsAutoString& aCopy) {
|
||||
if(aCopy.mStringValue.mBuffer!=mStringValue.mBuffer) {
|
||||
Assign(aCopy);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsAutoString& nsAutoString::operator=(const nsString& aString) {
|
||||
Assign(aString);
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsAutoString& nsAutoString::operator=(const nsCString& aString) {
|
||||
Assign(aString);
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsAutoString& nsAutoString::operator=(const PRUnichar* aString) {
|
||||
if(mStringValue.mBuffer!=aString) {
|
||||
nsStringValueImpl<PRUnichar> theStringValue(CONST_CAST(PRUnichar*,aString));
|
||||
Assign(aString);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsAutoString& nsAutoString::operator=(const char* aString) {
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString));
|
||||
SVAssign(mStringValue,theStringValue,theStringValue.mLength,0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsAutoString& nsAutoString::operator=(const PRUnichar aChar) {
|
||||
Assign(aChar);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
nsAutoString& nsAutoString::operator=(const nsSubsumeStr &aSubsumeString) {
|
||||
nsString::operator=(aSubsumeString);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,12 +21,15 @@
|
||||
#define _NS_STRING_
|
||||
|
||||
#include "nsStringValue.h"
|
||||
#include "nsBufferManager.h"
|
||||
|
||||
typedef nsStackBuffer<PRUnichar> nsUStackBuffer;
|
||||
|
||||
|
||||
class nsCString;
|
||||
class NS_COM nsCString;
|
||||
class NS_COM nsSubsumeStr;
|
||||
|
||||
class nsString: public nsAReadableString {
|
||||
|
||||
class NS_COM nsString {
|
||||
public:
|
||||
|
||||
//******************************************
|
||||
@@ -50,6 +53,12 @@ public:
|
||||
//call this version for a single char of type prunichar...
|
||||
nsString(const PRUnichar aChar);
|
||||
|
||||
//call this version for stack-based string buffers...
|
||||
nsString(const nsSubsumeStr &aSubsumeString);
|
||||
|
||||
//call this version for stack-based string buffers...
|
||||
nsString(nsSubsumeStr &aSubsumeString);
|
||||
|
||||
//call this version for char's....
|
||||
nsString(const char* aString,PRInt32 aLength=-1) ;
|
||||
|
||||
@@ -57,10 +66,21 @@ public:
|
||||
nsString(const nsAReadableString &aString) ;
|
||||
|
||||
//call this version for stack-based string buffers...
|
||||
nsString(const nsStackBuffer<PRUnichar> &aBuffer);
|
||||
nsString(const nsUStackBuffer &aBuffer);
|
||||
|
||||
virtual ~nsString();
|
||||
|
||||
void Reinitialize(PRUnichar* aBuffer,PRUint32 aCapacity,PRInt32 aLength=-1);
|
||||
|
||||
//******************************************
|
||||
// Concat operators
|
||||
//******************************************
|
||||
|
||||
nsSubsumeStr operator+(const nsString &aString);
|
||||
nsSubsumeStr operator+(const PRUnichar* aString);
|
||||
nsSubsumeStr operator+(const char* aString);
|
||||
nsSubsumeStr operator+(PRUnichar aChar);
|
||||
|
||||
|
||||
//******************************************
|
||||
// Assigment operators
|
||||
@@ -68,36 +88,36 @@ public:
|
||||
|
||||
|
||||
nsString& operator=(const nsString& aString);
|
||||
|
||||
nsString& operator=(const nsCString& aString);
|
||||
|
||||
nsString& operator=(const nsSubsumeStr &aSubsumeString);
|
||||
nsString& operator=(const PRUnichar* aString);
|
||||
|
||||
nsString& operator=(const char* aString);
|
||||
|
||||
nsString& operator=(const char aChar);
|
||||
|
||||
nsString& operator=(const PRUnichar aChar);
|
||||
|
||||
|
||||
//******************************************
|
||||
// Here are the accessor methods...
|
||||
// Here are the simple accessor methods...
|
||||
//******************************************
|
||||
|
||||
virtual nsresult SetLength(PRUint32 aLength) {
|
||||
if(aLength>mStringValue.mLength)
|
||||
SetCapacity(aLength);
|
||||
Truncate(aLength);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
virtual nsresult SetCapacity(PRUint32 aCapacity);
|
||||
|
||||
PRUnichar* GetUnicode() { return mStringValue.mBuffer;}
|
||||
PRUnichar* GetUnicode() const { return mStringValue.mBuffer;}
|
||||
|
||||
PRUnichar& operator[](PRUint32 aOffset);
|
||||
PRUnichar operator[](PRUint32 aOffset) const {return CharAt(aOffset);}
|
||||
|
||||
// operator const char* const() {return mStringValue.mBuffer;}
|
||||
|
||||
PRUint32 Length() const {return mStringValue.mLength;}
|
||||
|
||||
PRUint32 Capacity() const {return mStringValue.mCapacity;}
|
||||
|
||||
size_t GetCharSize() const {return sizeof(char);}
|
||||
PRBool IsUnicode() const {return PRBool(sizeof(PRUnichar)==sizeof(char));}
|
||||
@@ -118,11 +138,11 @@ public:
|
||||
return CharAt(mStringValue.mLength-1);
|
||||
}
|
||||
|
||||
|
||||
//these aren't the real deal, but serve as a placeholder for us to implement iterators.
|
||||
virtual nsAReadableStringIterator* First();
|
||||
virtual nsAReadableStringIterator* Last();
|
||||
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||
if (aResult) {
|
||||
*aResult = sizeof(*this) + Capacity();
|
||||
}
|
||||
}
|
||||
|
||||
//******************************************
|
||||
// Here are the Assignment methods,
|
||||
@@ -157,13 +177,9 @@ public:
|
||||
|
||||
virtual nsresult Assign(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* Functionally equivalent to assign or operator=, and deprecated!
|
||||
*
|
||||
*/
|
||||
nsresult SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
|
||||
nsresult SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
|
||||
nsresult SetString(const nsString &aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
|
||||
nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {Assign(aString, aLength); return *this;}
|
||||
nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {Assign(aString, aLength); return *this;}
|
||||
|
||||
|
||||
//***************************************
|
||||
// Here come the append methods...
|
||||
@@ -283,11 +299,11 @@ public:
|
||||
* @param anOffset -- where in this string to start stripping chars
|
||||
* @return *this
|
||||
*/
|
||||
nsresult StripChar(char aChar,PRUint32 anOffset=0);
|
||||
nsresult StripChar(PRUnichar aChar,PRUint32 anOffset=0);
|
||||
|
||||
nsresult StripChar(PRInt32 anInt,PRUint32 anOffset=0);
|
||||
|
||||
nsresult StripChars(const char* aSet);
|
||||
nsresult StripChars(const char* aSet,PRInt32 aLength=-1);
|
||||
|
||||
nsresult StripWhitespace();
|
||||
|
||||
@@ -307,16 +323,15 @@ public:
|
||||
//*******************************************
|
||||
|
||||
nsString& operator+=(const nsString& aString);
|
||||
|
||||
nsString& operator+=(const char* aString);
|
||||
|
||||
nsString& operator+=(const PRUnichar* aString);
|
||||
|
||||
nsString& operator+=(const char aChar);
|
||||
|
||||
nsString& operator+=(const PRUnichar aChar);
|
||||
|
||||
nsString& operator+=(const int anInt);
|
||||
nsString& operator+=(const nsSubsumeStr &aSubsumeString) {
|
||||
//XXX NOT IMPLEMENTED
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/***********************************
|
||||
@@ -326,7 +341,9 @@ public:
|
||||
PRBool operator==(const nsString& aString) const {return Equals(aString);}
|
||||
PRBool operator==(const nsCString& aString) const {return Equals(aString);}
|
||||
PRBool operator==(const char* aString) const {return Equals(aString);}
|
||||
PRBool operator==(char* aString) const {return Equals(aString);}
|
||||
PRBool operator==(const PRUnichar* aString) const {return Equals(aString);}
|
||||
PRBool operator==(PRUnichar* aString) const {return Equals(aString);}
|
||||
|
||||
PRBool operator!=(const nsString& aString) const {return PRBool(Compare(aString)!=0);}
|
||||
PRBool operator!=(const nsCString& aString) const {return PRBool(Compare(aString)!=0);}
|
||||
@@ -355,27 +372,23 @@ public:
|
||||
|
||||
|
||||
PRInt32 Compare(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
PRInt32 Compare(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const ;
|
||||
|
||||
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
PRBool Equals(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
|
||||
PRBool Equals(const PRUnichar* aLHS,const PRUnichar* aRHS,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
PRBool EqualsIgnoreCase(const nsString &aString) const {return Equals(aString,PR_TRUE);}
|
||||
PRBool EqualsIgnoreCase(const nsCString &aString) const {return Equals(aString,PR_TRUE);}
|
||||
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const {return Equals(aString,PR_TRUE);}
|
||||
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
|
||||
|
||||
// PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
|
||||
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const {return Equals(aString,PR_TRUE,aCount);}
|
||||
PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const {return Equals(aString,PR_TRUE,aCount);}
|
||||
PRBool EqualsIgnoreCase(const PRUnichar* aLHS, const PRUnichar* aRHS) const {return Equals(aLHS,aRHS,PR_TRUE);}
|
||||
PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const {return Equals(aAtom,PR_TRUE);}
|
||||
|
||||
|
||||
/***************************************
|
||||
@@ -396,7 +409,7 @@ public:
|
||||
PRInt32 Find(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const;
|
||||
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const;
|
||||
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const;
|
||||
PRInt32 FindChar(char aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const ;
|
||||
PRInt32 FindChar(char aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aRepCount=-1) const ;
|
||||
|
||||
PRInt32 FindCharInSet(const nsString& aString,PRUint32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(const char *aString,PRUint32 anOffset=0) const;
|
||||
@@ -430,6 +443,7 @@ public:
|
||||
|
||||
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
|
||||
|
||||
|
||||
//******************************************
|
||||
// Utility methods
|
||||
//******************************************
|
||||
@@ -470,134 +484,104 @@ protected:
|
||||
nsStringValueImpl<PRUnichar> mStringValue;
|
||||
|
||||
friend class nsCString;
|
||||
friend class nsSubsumeStr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
Now we declare the nsSubsumeStr class
|
||||
*****************************************************************/
|
||||
|
||||
class NS_COM nsSubsumeStr {
|
||||
public:
|
||||
|
||||
nsSubsumeStr();
|
||||
|
||||
nsSubsumeStr(const nsString& aString);
|
||||
|
||||
nsSubsumeStr(const nsSubsumeStr& aSubsumeString);
|
||||
|
||||
nsSubsumeStr(const nsStringValueImpl<PRUnichar> &aLHS,const nsSubsumeStr& aSubsumeString);
|
||||
|
||||
nsSubsumeStr(const nsStringValueImpl<PRUnichar> &aLHS,const nsStringValueImpl<PRUnichar> &aSubsumeString);
|
||||
|
||||
nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
|
||||
|
||||
nsSubsumeStr operator+(const nsSubsumeStr &aSubsumeString);
|
||||
|
||||
nsSubsumeStr operator+(const nsString &aString);
|
||||
|
||||
operator const PRUnichar*() {return 0;}
|
||||
|
||||
int Subsume(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
|
||||
|
||||
nsStringValueImpl<PRUnichar> mLHS;
|
||||
nsStringValueImpl<PRUnichar> mRHS;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
Now we declare the nsAutoString class
|
||||
*****************************************************************/
|
||||
|
||||
|
||||
class nsAutoString : public nsString {
|
||||
class NS_COM nsAutoString : public nsString {
|
||||
public:
|
||||
|
||||
nsAutoString() : nsString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
}
|
||||
nsAutoString();
|
||||
|
||||
//call this version nsAutoString derivatives...
|
||||
nsAutoString(const nsAutoString& aString,PRInt32 aLength=-1) : nsString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
Assign(aString,aLength);
|
||||
}
|
||||
nsAutoString(const nsAutoString& aString,PRInt32 aLength=-1);
|
||||
|
||||
//call this version for nsString,nsCString and the autostrings
|
||||
nsAutoString(const nsString& aString,PRInt32 aLength=-1) : nsString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
Assign(aString,aLength);
|
||||
}
|
||||
//call this version for nsString and the autostrings
|
||||
nsAutoString(const nsString& aString,PRInt32 aLength=-1);
|
||||
|
||||
//call this version with nsStringValueImpls (start of COW)
|
||||
nsAutoString(const nsCString& aString) : nsString(aString) {
|
||||
}
|
||||
//call this version with nsCString (start of COW)
|
||||
nsAutoString(const nsCString& aString);
|
||||
|
||||
//call this version for char*'s....
|
||||
nsAutoString(const char* aString,PRInt32 aLength=-1) : nsString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
|
||||
nsStringValueImpl<char> theString(const_cast<char*>(aString),aLength);
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
SVAssign<PRUnichar,char>(mStringValue,theString,aLength,0);
|
||||
}
|
||||
nsAutoString(const char* aString,PRInt32 aLength=-1);
|
||||
|
||||
//call this version for a single char of type char...
|
||||
nsAutoString(const char aChar) : nsString() {
|
||||
char theBuffer[]={aChar,0};
|
||||
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
|
||||
nsStringValueImpl<char> theString(theBuffer,1);
|
||||
Assign(theString,1,0);
|
||||
}
|
||||
|
||||
nsAutoString(PRUnichar aChar);
|
||||
nsAutoString(char aChar);
|
||||
|
||||
//call this version for PRUnichar*'s....
|
||||
nsAutoString(const PRUnichar* aString,PRInt32 aLength=-1) : nsString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
nsStringValueImpl<PRUnichar> theString(const_cast<PRUnichar*>(aString),aLength);
|
||||
SVAssign<PRUnichar,PRUnichar>(mStringValue,theString,theString.mLength,0);
|
||||
}
|
||||
|
||||
nsAutoString(const PRUnichar* aString,PRInt32 aLength=-1);
|
||||
|
||||
//call this version for all other ABT versions of readable strings
|
||||
nsAutoString(const nsAReadableString &aString) : nsString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
Assign(aString);
|
||||
}
|
||||
nsAutoString(const nsAReadableString &aString);
|
||||
|
||||
nsAutoString(const nsStackBuffer<PRUnichar> &aBuffer) : nsString() {
|
||||
nsAutoString(const nsUStackBuffer &aBuffer) ;
|
||||
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
nsAutoString(const CBufDescriptor& aBuffer) ;
|
||||
|
||||
mStringValue.mRefCount=2;
|
||||
mStringValue.mLength=aBuffer.mLength;
|
||||
mStringValue.mCapacity=aBuffer.mCapacity;
|
||||
mStringValue.mBuffer=aBuffer.mBuffer;
|
||||
|
||||
}
|
||||
nsAutoString(const nsSubsumeStr& aSubsumeStringX) ;
|
||||
|
||||
virtual ~nsAutoString();
|
||||
|
||||
virtual ~nsAutoString() { }
|
||||
|
||||
nsAutoString& operator=(const nsAutoString& aCopy);
|
||||
nsAutoString& operator=(const nsString& aString);
|
||||
nsAutoString& operator=(const nsCString& aString);
|
||||
nsAutoString& operator=(const PRUnichar* aString);
|
||||
nsAutoString& operator=(const char* aString) ;
|
||||
nsAutoString& operator=(const PRUnichar aChar);
|
||||
nsAutoString& operator=(const nsSubsumeStr &aSubsumeString);
|
||||
|
||||
|
||||
nsAutoString& operator=(const nsAutoString& aCopy) {
|
||||
if(aCopy.mStringValue.mBuffer!=mStringValue.mBuffer) {
|
||||
Assign(aCopy);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsAutoString& operator=(const nsString& aString) {
|
||||
Assign(aString);
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsAutoString& operator=(const PRUnichar* aString) {
|
||||
if(mStringValue.mBuffer!=aString) {
|
||||
nsStringValueImpl<PRUnichar> theStringValue(const_cast<PRUnichar*>(aString));
|
||||
Assign(aString);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsAutoString& operator=(const char* aString) {
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString));
|
||||
SVAssign<PRUnichar,char>(mStringValue,theStringValue,theStringValue.mLength,0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsAutoString& operator=(const char aChar) {
|
||||
Assign(aChar);
|
||||
return *this;
|
||||
}
|
||||
|
||||
protected:
|
||||
PRUnichar mInternalBuffer[kDefaultStringSize+1];
|
||||
|
||||
};
|
||||
|
||||
extern NS_COM int fputs(const nsString& aString, FILE* out);
|
||||
|
||||
extern PRUint32 HashCode(const nsString& aDest);
|
||||
|
||||
extern NS_COM void Recycle( PRUnichar* aBuffer);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -20,96 +20,155 @@
|
||||
|
||||
#ifndef NSSTRINGVALUE_
|
||||
#define NSSTRINGVALUE_
|
||||
#include <string.h>
|
||||
|
||||
#include "nsIAtom.h"
|
||||
#include "nscore.h"
|
||||
#include "nsIAllocator.h"
|
||||
#include <string.h>
|
||||
#include "nsCRT.h"
|
||||
|
||||
#if 0
|
||||
typedef int PRInt32;
|
||||
typedef unsigned int PRUint32;
|
||||
typedef short int PRUnichar;
|
||||
typedef int nsresult;
|
||||
typedef char PRBool;
|
||||
|
||||
#define NS_OK 0
|
||||
#define NS_MEMORY_ERROR 1000
|
||||
#define PR_TRUE 1
|
||||
#define PR_FALSE 0
|
||||
#define NS_SUCCESS(x) (NS_OK==x)
|
||||
#define NS_SUCCEEDED(x) (NS_OK==x)
|
||||
|
||||
static const char* kWhitespace="\b\t\r\n ";
|
||||
static const char* kPossibleNull ="Possible null being inserted into string.";
|
||||
#endif
|
||||
|
||||
|
||||
typedef long int _RefCountType;
|
||||
|
||||
static const int kRadix10=10;
|
||||
static const int kRadix16=16;
|
||||
static const int kAutoDetect=100;
|
||||
static const int kRadixUnknown=kAutoDetect+1;
|
||||
|
||||
static const int kDefaultStringSize=32;
|
||||
static const int kDefaultStringSize=64;
|
||||
static const int kNotFound=-1;
|
||||
#define IGNORE_CASE (PR_TRUE)
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* The following is the basic interface nsString searching...
|
||||
*
|
||||
* We will merge this into nsAReadableString very soon, but I've kept it
|
||||
* seperate until I can map and factor the original nsString methods.
|
||||
*
|
||||
***************************************************************************/
|
||||
class nsSearchableString {
|
||||
class nsAReadableString {
|
||||
public:
|
||||
|
||||
//We need to decide how deep (and generic) this API can go...
|
||||
virtual PRUint32 Length() const =0;
|
||||
|
||||
};
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This isn't intended as a real class, but only to illustrate that for
|
||||
* nsAReadableString, we want a common access pattern to get at the underlying
|
||||
* buffer. Iterators make perfect sense, but it will take a real implementation.
|
||||
*
|
||||
* Note: This class is intended to replace direct calls to GetBuffer()
|
||||
* in cases where iteration on an nsAReadableString is taking place.
|
||||
*
|
||||
***************************************************************************/
|
||||
class nsAReadableStringIterator {
|
||||
public:
|
||||
nsAReadableStringIterator() { }
|
||||
};
|
||||
#define MODERN_CPP //make this false for aix/solaris...
|
||||
|
||||
#ifdef MODERN_CPP
|
||||
#define CONST_CAST(type,arg) const_cast<type>(arg)
|
||||
#else
|
||||
#define CONST_CAST(type,arg) (type)arg
|
||||
#endif
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* The following is the basic interface anyone who wants to be passed
|
||||
* as a string should define.
|
||||
* The following (hack) template functions will go away, but for now they
|
||||
* provide basic string copying and appending for my prototype. (rickg)
|
||||
*
|
||||
***************************************************************************/
|
||||
class nsAReadableString : public nsSearchableString {
|
||||
|
||||
template <class T1,class T2>
|
||||
inline PRInt32 MinInt(T1 anInt1,T2 anInt2){
|
||||
return (anInt1<(T1)anInt2) ? anInt1 : anInt2;
|
||||
}
|
||||
|
||||
template <class T1,class T2>
|
||||
inline PRInt32 MaxInt(T1 anInt1,T2 anInt2){
|
||||
return (anInt1<(T1)anInt2) ? anInt2 : anInt1;
|
||||
}
|
||||
|
||||
inline size_t stringlen(const PRUnichar* theString) {
|
||||
const PRUnichar* theEnd=theString;
|
||||
while(*theEnd++); //skip to end of aDest...
|
||||
size_t result=theEnd-theString-1;
|
||||
return result;
|
||||
}
|
||||
|
||||
inline size_t stringlen(const char* theString) {
|
||||
return ::strlen(theString);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
class NS_COM CBufDescriptor {
|
||||
public:
|
||||
virtual PRUint32 Length() const =0;
|
||||
virtual size_t GetCharSize() const =0;
|
||||
CBufDescriptor(char* aString, PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1) {
|
||||
mBuffer=aString;
|
||||
mCharSize=1;
|
||||
mStackBased=aStackBased;
|
||||
mIsConst=PR_FALSE;
|
||||
mLength=mCapacity=0;
|
||||
if(aString && aCapacity>1) {
|
||||
mCapacity=aCapacity-1;
|
||||
mLength=(-1==aLength) ? strlen(aString) : aLength;
|
||||
if(mLength>PRInt32(mCapacity))
|
||||
mLength=mCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
// virtual PRUnichar operator[](PRUint32) = 0;
|
||||
CBufDescriptor(const char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1) {
|
||||
mBuffer=(char*)aString;
|
||||
mCharSize=1;
|
||||
mStackBased=aStackBased;
|
||||
mIsConst=PR_TRUE;
|
||||
mLength=mCapacity=0;
|
||||
if(aString && aCapacity>1) {
|
||||
mCapacity=aCapacity-1;
|
||||
mLength=(-1==aLength) ? stringlen(aString) : aLength;
|
||||
if(mLength>PRInt32(mCapacity))
|
||||
mLength=mCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
virtual nsAReadableStringIterator* First() = 0; //These are here so that nsReadable strings can offer a standard mechanism for
|
||||
virtual nsAReadableStringIterator* Last() = 0; //callers to access underlying data. Feel free to replace with a better pattern.
|
||||
CBufDescriptor(PRUnichar* aString, PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1) {
|
||||
mBuffer=(char*)aString;
|
||||
mCharSize=2;
|
||||
mStackBased=aStackBased;
|
||||
mLength=mCapacity=0;
|
||||
mIsConst=PR_FALSE;
|
||||
if(aString && aCapacity>1) {
|
||||
mCapacity=aCapacity-1;
|
||||
mLength=(-1==aLength) ? stringlen(aString) : aLength;
|
||||
if(mLength>PRInt32(mCapacity))
|
||||
mLength=mCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
//by moving to iterators, we can support segmented content models...
|
||||
//virtual nsStringIterator GetIterator() = 0;
|
||||
CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1) {
|
||||
mBuffer=(char*)aString;
|
||||
mCharSize=2;
|
||||
mStackBased=aStackBased;
|
||||
mLength=mCapacity=0;
|
||||
mIsConst=PR_TRUE;
|
||||
if(aString && aCapacity>1) {
|
||||
mCapacity=aCapacity-1;
|
||||
mLength=(-1==aLength) ? stringlen(aString) : aLength;
|
||||
if(mLength>PRInt32(mCapacity))
|
||||
mLength=mCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
//virtual PRBool IsEmpty(void) = 0;
|
||||
|
||||
//etc.
|
||||
char* mBuffer;
|
||||
PRUint32 mCapacity;
|
||||
PRInt32 mLength;
|
||||
PRBool mStackBased;
|
||||
PRBool mIsConst;
|
||||
char mCharSize;
|
||||
};
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This is ABT from which the basic stringvalues are derived. (rickg)
|
||||
*
|
||||
***************************************************************************/
|
||||
class nsStringValue {
|
||||
public:
|
||||
virtual void AddRef(void) =0;
|
||||
virtual void Release(void) =0;
|
||||
};
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
@@ -128,76 +187,91 @@ struct nsStackBuffer {
|
||||
PRUint32 mCapacity;
|
||||
};
|
||||
|
||||
|
||||
#if 0
|
||||
template <class CharType>
|
||||
struct RCBuffer {
|
||||
|
||||
void* operator new(size_t aSize) {
|
||||
CharType* theBuf = ::new CharType[aSize+1+sizeof(_RefCountType)];
|
||||
memset(theBuf,0xff,aSize+additionalBytes+1);
|
||||
return theBuf;
|
||||
}
|
||||
|
||||
void operator delete(void *p, size_t aSize) {
|
||||
::delete [] p;
|
||||
}
|
||||
|
||||
_RefCountType mRefCount;
|
||||
CharType mBuffer[1];
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This is the templatized base class from which stringvalues are derived. (rickg)
|
||||
*
|
||||
***************************************************************************/
|
||||
template <class CharType>
|
||||
class nsStringValueImpl : nsStringValue {
|
||||
public:
|
||||
struct nsStringValueImpl {
|
||||
|
||||
nsStringValueImpl() : nsStringValue() {
|
||||
mRefCount=1;
|
||||
nsStringValueImpl() {
|
||||
mBuffer=0;
|
||||
mLength=mCapacity=0;
|
||||
mRefCount=1;
|
||||
}
|
||||
|
||||
nsStringValueImpl(const nsStringValueImpl& aCopy) : nsStringValue() {
|
||||
mRefCount=1;
|
||||
nsStringValueImpl(const nsStringValueImpl<CharType>& aCopy) {
|
||||
mBuffer=aCopy.mBuffer;
|
||||
mLength=aCopy.mLength;
|
||||
mCapacity=aCopy.mCapacity;
|
||||
mRefCount=1;
|
||||
}
|
||||
|
||||
nsStringValueImpl(const nsStringValueImpl& aCopy,PRInt32 aLength) : nsStringValue() {
|
||||
mRefCount=1;
|
||||
nsStringValueImpl(const nsStringValueImpl<CharType>& aCopy,PRInt32 aLength){
|
||||
mBuffer=aCopy.mBuffer;
|
||||
mLength=aLength;
|
||||
mCapacity=aCopy.mCapacity;
|
||||
mRefCount=1;
|
||||
}
|
||||
|
||||
nsStringValueImpl(CharType* theString,PRInt32 aLength=-1,PRInt32 aCapacity=-1) : nsStringValue() {
|
||||
mRefCount=1;
|
||||
nsStringValueImpl(CharType* theString,PRInt32 aLength=-1,PRUint32 aCapacity=0) {
|
||||
if(theString) {
|
||||
mLength = (-1==aLength) ? stringlen(theString) : aLength;
|
||||
mCapacity=mLength+1;
|
||||
mCapacity=(0==aCapacity) ? mLength+1 : aCapacity;
|
||||
mBuffer=theString;
|
||||
}
|
||||
else {
|
||||
mBuffer=0;
|
||||
mLength=mCapacity=0;
|
||||
}
|
||||
mRefCount=1;
|
||||
}
|
||||
|
||||
nsStringValueImpl(const nsStackBuffer<CharType> &aBuffer) : nsStringValue() {
|
||||
mRefCount=2;
|
||||
nsStringValueImpl(const nsStackBuffer<CharType> &aBuffer) {
|
||||
mCapacity=aBuffer.mCapacity;
|
||||
mLength=aBuffer.mLength;
|
||||
mBuffer=aBuffer.mBuffer;
|
||||
mRefCount=2; //set it to 2 so we don't try to free it.
|
||||
}
|
||||
|
||||
operator=(const nsStringValueImpl<CharType>& aCopy) {
|
||||
mRefCount=1;
|
||||
void operator=(const nsStringValueImpl<CharType>& aCopy) {
|
||||
mBuffer=aCopy.mBuffer;
|
||||
mLength=aCopy.mLength;
|
||||
mCapacity=aCopy.mCapacity;
|
||||
mRefCount=aCopy.mRefCount;
|
||||
}
|
||||
|
||||
operator CharType*() {return mBuffer;}
|
||||
void* GetBuffer() {return mBuffer;}
|
||||
PRUint32 GetLength() {return mLength;}
|
||||
size_t GetCharSize() {return sizeof(CharType);}
|
||||
|
||||
virtual void AddRef(void) {mRefCount++;}
|
||||
virtual void Release(void){--mRefCount;}
|
||||
|
||||
virtual void* GetBuffer() {return mBuffer;}
|
||||
virtual PRUint32 GetLength() {return mLength;}
|
||||
virtual size_t GetCharSize() {return sizeof(CharType);}
|
||||
|
||||
public:
|
||||
CharType* mBuffer;
|
||||
PRUint32 mRefCount;
|
||||
PRUint32 mLength;
|
||||
PRUint32 mCapacity;
|
||||
PRUint32 mRefCount;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
|
||||
#include "nsString2x.h"
|
||||
#include "nsStringx.h"
|
||||
#include "nsString2.h"
|
||||
#include "nsString.h"
|
||||
#include "nsBufferManager.h"
|
||||
#include <stdio.h>
|
||||
#include "nsAutoStringImpl.h"
|
||||
#include <stdlib.h>
|
||||
#include "nsIAllocator.h"
|
||||
|
||||
static const char* kWhitespace="\b\t\r\n ";
|
||||
|
||||
|
||||
//******************************************
|
||||
// Ctor's
|
||||
@@ -24,13 +28,22 @@ nsCString::nsCString(const nsString& aString,PRInt32 aLength) : mStringValue() {
|
||||
|
||||
//call this version for char*'s....
|
||||
nsCString::nsCString(const char* aString,PRInt32 aLength) : mStringValue() {
|
||||
Assign(aString,aLength,0);
|
||||
Assign(aString,aLength);
|
||||
}
|
||||
|
||||
//call this version for PRUnichar*'s....
|
||||
nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength) : mStringValue() {
|
||||
nsStringValueImpl<PRUnichar> theString(const_cast<PRUnichar*>(aString),aLength);
|
||||
SVAssign<char,PRUnichar>(mStringValue,theString,theString.mLength,0);
|
||||
Assign(aString,aLength,0);
|
||||
}
|
||||
|
||||
//call this version for a single char of type char...
|
||||
nsCString::nsCString(const nsSubsumeCStr &aSubsumeString) : mStringValue(aSubsumeString.mLHS) {
|
||||
SVAppend(mStringValue,aSubsumeString.mRHS,aSubsumeString.mRHS.mLength,0);
|
||||
}
|
||||
|
||||
//call this version for a single char of type char...
|
||||
nsCString::nsCString(nsSubsumeCStr &aSubsumeString) : mStringValue(aSubsumeString.mLHS) {
|
||||
SVAppend(mStringValue,aSubsumeString.mRHS,aSubsumeString.mRHS.mLength,0);
|
||||
}
|
||||
|
||||
//call this version for a single char of type char...
|
||||
@@ -44,12 +57,39 @@ nsCString::nsCString(const nsAReadableString &aString) : mStringValue() {
|
||||
}
|
||||
|
||||
//call this version for stack-based string buffers...
|
||||
nsCString::nsCString(const nsStackBuffer<char> &aBuffer) : mStringValue(aBuffer) {
|
||||
nsCString::nsCString(const nsCStackBuffer &aBuffer) : mStringValue(aBuffer) {
|
||||
}
|
||||
|
||||
nsCString::~nsCString() { }
|
||||
|
||||
|
||||
void nsCString::Reinitialize(char* aBuffer,PRUint32 aCapacity,PRInt32 aLength) {
|
||||
mStringValue.mBuffer=aBuffer;
|
||||
mStringValue.mCapacity=aCapacity;
|
||||
mStringValue.mLength=aLength;
|
||||
mStringValue.mRefCount=1;
|
||||
}
|
||||
|
||||
|
||||
//******************************************
|
||||
// Concatenation operators
|
||||
//******************************************
|
||||
|
||||
nsSubsumeCStr nsCString::operator+(const nsCString &aCString) {
|
||||
nsSubsumeCStr result(mStringValue,aCString.mStringValue);
|
||||
return result;
|
||||
}
|
||||
|
||||
nsSubsumeCStr nsCString::operator+(const char* aCString) {
|
||||
nsSubsumeCStr result; //NOT IMPLEMENTED
|
||||
return result;
|
||||
}
|
||||
|
||||
nsSubsumeCStr nsCString::operator+(char aChar) {
|
||||
nsSubsumeCStr result; //NOT IMPLEMENTED
|
||||
return result;
|
||||
}
|
||||
|
||||
//******************************************
|
||||
// Assigment operators
|
||||
//******************************************
|
||||
@@ -68,14 +108,14 @@ nsCString& nsCString::operator=(const nsString &aString) {
|
||||
|
||||
nsCString& nsCString::operator=(const char *aString) {
|
||||
if(mStringValue.mBuffer!=aString) {
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString));
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString));
|
||||
SVAssign(mStringValue,theStringValue,theStringValue.mLength,0);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsCString& nsCString::operator=(const PRUnichar *aString) {
|
||||
nsStringValueImpl<PRUnichar> theStringValue(const_cast<PRUnichar*>(aString));
|
||||
nsStringValueImpl<PRUnichar> theStringValue(CONST_CAST(PRUnichar*,aString));
|
||||
Assign(aString);
|
||||
return *this;
|
||||
}
|
||||
@@ -85,6 +125,11 @@ nsCString& nsCString::operator=(const char aChar) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsCString& nsCString::operator=(const nsSubsumeCStr &aSubsumeString) {
|
||||
//NOT IMPLEMENTED
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//******************************************
|
||||
// Here are the accessor methods...
|
||||
@@ -93,17 +138,11 @@ nsCString& nsCString::operator=(const char aChar) {
|
||||
|
||||
nsresult nsCString::SetCapacity(PRUint32 aCapacity) {
|
||||
if(aCapacity>mStringValue.mCapacity) {
|
||||
SVGrowCapacity<char>(mStringValue,aCapacity);
|
||||
SVAddNullTerminator<char>(mStringValue);
|
||||
SVRealloc(mStringValue,aCapacity);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
char& nsCString::operator[](PRUint32 aOffset) {
|
||||
static char gSharedChar=0;
|
||||
return (mStringValue.mBuffer) ? mStringValue.mBuffer[aOffset] : gSharedChar;
|
||||
}
|
||||
|
||||
// operator const char* const() {return mStringValue.mBuffer;}
|
||||
|
||||
|
||||
@@ -116,10 +155,6 @@ PRBool nsCString::SetCharAt(char aChar,PRUint32 anIndex) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//these aren't the real deal, but serve as a placeholder for us to implement iterators.
|
||||
nsAReadableStringIterator* nsCString::First() {return new nsAReadableStringIterator(); }
|
||||
nsAReadableStringIterator* nsCString::Last() {return new nsAReadableStringIterator(); }
|
||||
|
||||
|
||||
//******************************************
|
||||
// Here are the Assignment methods,
|
||||
@@ -127,7 +162,7 @@ nsAReadableStringIterator* nsCString::Last() {return new nsAReadableStringIterat
|
||||
//******************************************
|
||||
|
||||
nsresult nsCString::Truncate(PRUint32 anOffset) {
|
||||
SVTruncate<char>(mStringValue,anOffset);
|
||||
SVTruncate(mStringValue,anOffset);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -149,6 +184,20 @@ nsresult nsCString::Assign(const nsCString& aString,PRInt32 aLength,PRUint32 aSr
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* This method assign from nsCString
|
||||
*
|
||||
* @update rickg 03.01.2000
|
||||
* @param aString -- source String to be inserted into this
|
||||
* @param aLength -- number of chars to be copied from aCopy
|
||||
* @param aSrcOffset -- insertion position within this str
|
||||
* @return this
|
||||
*/
|
||||
nsresult nsCString::Assign(const nsString& aString,PRInt32 aLength,PRUint32 aSrcOffset) {
|
||||
nsresult result=NS_OK;
|
||||
Truncate();
|
||||
return Append(aString,aLength,aSrcOffset);
|
||||
}
|
||||
|
||||
/*
|
||||
* This method assign from PRUnichar*
|
||||
@@ -159,12 +208,10 @@ nsresult nsCString::Assign(const nsCString& aString,PRInt32 aLength,PRUint32 aSr
|
||||
* @param aSrcOffset -- insertion position within this str
|
||||
* @return this
|
||||
*/
|
||||
#if 0
|
||||
nsresult nsCString::Assign(const PRUnichar* aString,PRInt32 aLength,PRUint32 aSrcOffset) {
|
||||
Truncate();
|
||||
return Append(aString,aLength,aSrcOffset);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This method assign from char*
|
||||
@@ -196,7 +243,7 @@ nsresult nsCString::Assign(const char* aString,PRInt32 aLength,PRUint32 aSrcOffs
|
||||
*/
|
||||
nsresult nsCString::Assign(const nsAReadableString &aString,PRInt32 aLength,PRUint32 aSrcOffset) {
|
||||
Truncate();
|
||||
return SVAppendReadable<char>(mStringValue,aString,aLength,aSrcOffset);
|
||||
return SVAppendReadable(mStringValue,aString,aLength,aSrcOffset);
|
||||
}
|
||||
|
||||
//assign from a char
|
||||
@@ -226,7 +273,7 @@ nsresult Append(const nsStringValueImpl<char> &aString,PRInt32 aLength,PRUint32
|
||||
* @return this
|
||||
*/
|
||||
nsresult nsCString::Append(const nsCString &aString,PRInt32 aLength,PRUint32 aSrcOffset) {
|
||||
return SVAppend< char, char > (mStringValue,aString.mStringValue,aLength,aSrcOffset);
|
||||
return SVAppend (mStringValue,aString.mStringValue,aLength,aSrcOffset);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -239,48 +286,68 @@ nsresult nsCString::Append(const nsCString &aString,PRInt32 aLength,PRUint32 aSr
|
||||
* @return this
|
||||
*/
|
||||
nsresult nsCString::Append(const nsString &aString,PRInt32 aLength,PRUint32 aSrcOffset) {
|
||||
return SVAppend< char, PRUnichar > (mStringValue,aString.mStringValue,aString.mStringValue.mLength,aSrcOffset);
|
||||
return SVAppend(mStringValue,aString.mStringValue,aString.mStringValue.mLength,aSrcOffset);
|
||||
}
|
||||
|
||||
//append from a char*
|
||||
nsresult nsCString::Append(const char* aString,PRInt32 aLength,PRUint32 aSrcOffset) {
|
||||
nsresult result=NS_OK;
|
||||
if(aString) {
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString),aLength);
|
||||
result=SVAppend< char, char > (mStringValue,theStringValue,aLength,aSrcOffset);
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString),aLength);
|
||||
result=SVAppend(mStringValue,theStringValue,aLength,aSrcOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//append from a char
|
||||
nsresult nsCString::Append(const char aChar) {
|
||||
char theBuffer[]={aChar,0};
|
||||
nsStringValueImpl<char> theStringValue(theBuffer,1);
|
||||
return SVAppend< char, char > (mStringValue,theStringValue,1,0);
|
||||
|
||||
if(mStringValue.mLength==mStringValue.mCapacity) {
|
||||
SVRealloc(mStringValue,mStringValue.mCapacity+5);
|
||||
}
|
||||
|
||||
if(mStringValue.mLength<mStringValue.mCapacity) {
|
||||
//an optimized code path when our buffer can easily contain the given char...
|
||||
mStringValue.mBuffer[mStringValue.mLength++]=aChar;
|
||||
mStringValue.mBuffer[mStringValue.mLength]=0;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//append from a PRUnichar
|
||||
nsresult nsCString::Append(const PRUnichar aChar) {
|
||||
|
||||
if(mStringValue.mLength<mStringValue.mCapacity) {
|
||||
//an optimized code path when our buffer can easily contain the given char...
|
||||
if(aChar<256) {
|
||||
mStringValue.mBuffer[mStringValue.mLength++]=(unsigned char)aChar;
|
||||
}
|
||||
else {
|
||||
mStringValue.mBuffer[mStringValue.mLength++]='.'; //XXX HACK!
|
||||
}
|
||||
mStringValue.mBuffer[mStringValue.mLength]=0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRUnichar theBuffer[]={aChar,0};
|
||||
nsStringValueImpl<PRUnichar> theStringValue(theBuffer,1);
|
||||
return SVAppend< char,PRUnichar> (mStringValue,theStringValue,1,0);
|
||||
return SVAppend(mStringValue,theStringValue,1,0);
|
||||
}
|
||||
|
||||
//append from a PRUnichar*
|
||||
#if 0
|
||||
nsresult nsCString::Append(const PRUnichar* aString,PRInt32 aLength,PRUint32 aSrcOffset) {
|
||||
nsresult result=NS_OK;
|
||||
if(aString) {
|
||||
nsStringValueImpl<PRUnichar> theStringValue(const_cast<PRUnichar*>(aString),aLength);
|
||||
result=SVAppend< char,PRUnichar> (mStringValue,theStringValue,aLength,aSrcOffset);
|
||||
nsStringValueImpl<PRUnichar> theStringValue(CONST_CAST(PRUnichar*,aString),aLength);
|
||||
result=SVAppend(mStringValue,theStringValue,aLength,aSrcOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
//append from an nsAReadableString (the ABT)
|
||||
nsresult nsCString::Append(const nsAReadableString &aString,PRInt32 aLength,PRUint32 aSrcOffset) {
|
||||
return SVAppendReadable<char> (mStringValue,aString,aLength,aSrcOffset);
|
||||
return SVAppendReadable(mStringValue,aString,aLength,aSrcOffset);
|
||||
}
|
||||
|
||||
//append an integer
|
||||
@@ -324,8 +391,7 @@ nsresult nsCString::Append(float aFloat) {
|
||||
char buf[40];
|
||||
sprintf(buf,"%g",aFloat);
|
||||
|
||||
nsStringValueImpl<char> theStringValue(buf);
|
||||
Append(theStringValue);
|
||||
Append(buf);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -336,11 +402,11 @@ nsresult nsCString::Append(float aFloat) {
|
||||
//***************************************
|
||||
|
||||
nsresult nsCString::Cut(PRUint32 anOffset,PRInt32 aCount) {
|
||||
return SVDelete<char>(mStringValue,anOffset,aCount);
|
||||
return (0<aCount) ? SVDelete(mStringValue,anOffset,aCount) : NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsCString::Trim(const char* aTrimSet,PRBool aEliminateLeading,PRBool aEliminateTrailing,PRBool aIgnoreQuotes) {
|
||||
return SVTrim<char>(mStringValue,aTrimSet,aEliminateLeading,aEliminateTrailing);
|
||||
return SVTrim(mStringValue,aTrimSet,aEliminateLeading,aEliminateTrailing);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -354,8 +420,7 @@ nsresult nsCString::Trim(const char* aTrimSet,PRBool aEliminateLeading,PRBool aE
|
||||
* @return this
|
||||
*/
|
||||
nsresult nsCString::CompressSet(const char* aSet, char aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
nsStringValueImpl<char> theSet(const_cast<char*>(aSet));
|
||||
return SVCompressSet<char>(mStringValue,theSet,aChar,aEliminateLeading,aEliminateTrailing);
|
||||
return SVCompressSet(mStringValue,aSet,aChar,aEliminateLeading,aEliminateTrailing);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -378,7 +443,7 @@ nsresult nsCString::CompressWhitespace( PRBool aEliminateLeading,PRBool aElimina
|
||||
//***************************************
|
||||
|
||||
nsresult nsCString::Insert(const nsCString& aString,PRUint32 anOffset,PRInt32 aCount) {
|
||||
return SVInsert<char>(mStringValue,anOffset,aString.mStringValue,aCount,anOffset);
|
||||
return SVInsert(mStringValue,anOffset,aString.mStringValue,aCount,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -396,10 +461,10 @@ nsresult nsCString::Insert(const char* aString,PRUint32 anOffset,PRInt32 aLength
|
||||
nsresult result=NS_OK;
|
||||
if(aString){
|
||||
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString),aLength);
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString),aLength);
|
||||
|
||||
if(0<theStringValue.mLength){
|
||||
result=SVInsert<char>(mStringValue,anOffset,theStringValue,theStringValue.mLength,0);
|
||||
result=SVInsert(mStringValue,anOffset,theStringValue,theStringValue.mLength,0);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -419,7 +484,7 @@ nsresult nsCString::Insert(char aChar,PRUint32 anOffset){
|
||||
char theBuffer[]={aChar,0};
|
||||
nsStringValueImpl<char> theStringValue(theBuffer,1);
|
||||
|
||||
return SVInsert<char>(mStringValue,anOffset,theStringValue,1,0);
|
||||
return SVInsert(mStringValue,anOffset,theStringValue,1,0);
|
||||
}
|
||||
|
||||
|
||||
@@ -433,26 +498,34 @@ nsresult nsCString::Insert(char aChar,PRUint32 anOffset){
|
||||
* @return this
|
||||
*/
|
||||
nsresult nsCString::ReplaceChar(char anOldChar,char aNewChar){
|
||||
return SVReplaceChar<char>(mStringValue,anOldChar,aNewChar,mStringValue.mLength,0);
|
||||
char *root_cp=mStringValue.mBuffer;
|
||||
char *null_cp=root_cp+mStringValue.mLength;
|
||||
|
||||
while(root_cp<null_cp) {
|
||||
if(*root_cp==anOldChar) {
|
||||
*root_cp=aNewChar;
|
||||
}
|
||||
root_cp++;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsCString::ReplaceChar(const char* aSet,char aNewChar){
|
||||
nsStringValueImpl<char> theSet(const_cast<char*>(aSet));
|
||||
return SVReplaceCharsInSet<char>(mStringValue,theSet,aNewChar,mStringValue.mLength,0);
|
||||
return SVReplaceCharsInSet(mStringValue,aSet,aNewChar,mStringValue.mLength,0);
|
||||
}
|
||||
|
||||
nsresult nsCString::ReplaceSubstring( const nsCString& aTarget,const nsCString& aNewValue){
|
||||
return SVReplace<char>(mStringValue,aTarget.mStringValue,aNewValue.mStringValue,mStringValue.mLength,0);
|
||||
return SVReplace(mStringValue,aTarget.mStringValue,aNewValue.mStringValue,mStringValue.mLength,0);
|
||||
}
|
||||
|
||||
|
||||
nsresult nsCString::ReplaceSubstring(const char* aTarget,const char* aNewValue) {
|
||||
nsresult result=NS_OK;
|
||||
|
||||
const nsStringValueImpl<char> theTarget(const_cast<char*>(aTarget));
|
||||
const nsStringValueImpl<char> theNewValue(const_cast<char*>(aNewValue));
|
||||
const nsStringValueImpl<char> theTarget(CONST_CAST(char*,aTarget));
|
||||
const nsStringValueImpl<char> theNewValue(CONST_CAST(char*,aNewValue));
|
||||
|
||||
return SVReplace<char>(mStringValue,theTarget,theNewValue,mStringValue.mLength,0);
|
||||
return SVReplace(mStringValue,theTarget,theNewValue,mStringValue.mLength,0);
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
@@ -469,7 +542,7 @@ nsresult nsCString::ReplaceSubstring(const char* aTarget,const char* aNewValue)
|
||||
* @return *this
|
||||
*/
|
||||
nsresult nsCString::StripChar(char aChar,PRUint32 anOffset){
|
||||
return SVStripChar<char>(mStringValue,aChar,mStringValue.mLength,anOffset);
|
||||
return SVStripChar(mStringValue,aChar,mStringValue.mLength,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -482,7 +555,7 @@ nsresult nsCString::StripChar(char aChar,PRUint32 anOffset){
|
||||
* @return *this
|
||||
*/
|
||||
nsresult nsCString::StripChar(PRInt32 anInt,PRUint32 anOffset){
|
||||
return SVStripChar<char>(mStringValue,(char)anInt,mStringValue.mLength,anOffset);
|
||||
return SVStripChar(mStringValue,(char)anInt,mStringValue.mLength,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -493,9 +566,9 @@ nsresult nsCString::StripChar(PRInt32 anInt,PRUint32 anOffset){
|
||||
* @param aSet -- characters to be cut from this
|
||||
* @return *this
|
||||
*/
|
||||
nsresult nsCString::StripChars(const char* aSet){
|
||||
nsStringValueImpl<char> theSet(const_cast<char*>(aSet));
|
||||
return SVStripCharsInSet<char>(mStringValue,aSet,mStringValue.mLength,0);
|
||||
nsresult nsCString::StripChars(const char* aSet,PRInt32 aLength){
|
||||
nsStringValueImpl<char> theSet(CONST_CAST(char*,aSet),aLength);
|
||||
return SVStripCharsInSet(mStringValue,aSet,mStringValue.mLength,0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -514,17 +587,18 @@ nsresult nsCString::StripWhitespace() {
|
||||
//**************************************************
|
||||
|
||||
nsresult nsCString::Left(nsCString& aCopy,PRInt32 aCount) const {
|
||||
aCount = (aCount<0) ? mStringValue.mLength : MinInt(aCount,mStringValue.mLength);
|
||||
aCount = (aCount<0) ? mStringValue.mLength : (aCount<(PRInt32)mStringValue.mLength) ? aCount : mStringValue.mLength;
|
||||
return aCopy.Assign(*this,aCount,0);
|
||||
}
|
||||
|
||||
nsresult nsCString::Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const {
|
||||
aCount = (aCount<0) ? mStringValue.mLength : MinInt(aCount,mStringValue.mLength);
|
||||
aCount = (aCount<0) ? mStringValue.mLength : (aCount<(PRInt32)mStringValue.mLength) ? aCount : mStringValue.mLength;
|
||||
return aCopy.Assign(*this,aCount,anOffset);
|
||||
}
|
||||
|
||||
nsresult nsCString::Right(nsCString& aCopy,PRInt32 aCount) const {
|
||||
PRInt32 offset=MaxInt(mStringValue.mLength-aCount,0);
|
||||
PRUint32 theLen=mStringValue.mLength-aCount;
|
||||
PRInt32 offset=(theLen<0) ? 0 : theLen;
|
||||
return Mid(aCopy,offset,aCount);
|
||||
}
|
||||
|
||||
@@ -539,12 +613,15 @@ nsCString& nsCString::operator+=(const char* aString) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*
|
||||
nsCString& nsCString::operator+=(const PRUnichar* aString) {
|
||||
Append(aString);
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
|
||||
nsCString& nsCString::operator+=(const nsCString& aCString) {
|
||||
Append(aCString);
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsCString& nsCString::operator+=(const char aChar) {
|
||||
char theBuffer[]={aChar,0};
|
||||
@@ -552,13 +629,11 @@ nsCString& nsCString::operator+=(const char aChar) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*
|
||||
nsCString& nsCString::operator+=(const PRUnichar aChar) {
|
||||
PRUnichar theBuffer[]={aChar,0};
|
||||
Append(theBuffer,1);
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
|
||||
nsCString& nsCString::operator+=(const int anInt){
|
||||
Append(anInt,10);
|
||||
@@ -566,7 +641,7 @@ nsCString& nsCString::operator+=(const int anInt){
|
||||
}
|
||||
|
||||
void nsCString::ToLowerCase() {
|
||||
SVToLowerCase<char>(mStringValue);
|
||||
SVToLowerCase(mStringValue);
|
||||
}
|
||||
|
||||
void nsCString::ToLowerCase(nsCString &aString) const {
|
||||
@@ -575,7 +650,7 @@ void nsCString::ToLowerCase(nsCString &aString) const {
|
||||
}
|
||||
|
||||
void nsCString::ToUpperCase() {
|
||||
SVToUpperCase<char>(mStringValue);
|
||||
SVToUpperCase(mStringValue);
|
||||
}
|
||||
|
||||
void nsCString::ToUpperCase(nsCString &aString) const {
|
||||
@@ -585,48 +660,43 @@ void nsCString::ToUpperCase(nsCString &aString) const {
|
||||
|
||||
|
||||
PRInt32 nsCString::Compare(const nsCString &aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
||||
return SVCompare<char,char>(mStringValue,aString.mStringValue,aIgnoreCase,aCount);
|
||||
return SVCompareChars(mStringValue,aString.mStringValue,aIgnoreCase,aCount);
|
||||
}
|
||||
|
||||
PRInt32 nsCString::Compare(const char* aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString),aCount);
|
||||
return SVCompare<char,char>(mStringValue,theStringValue,aIgnoreCase,aCount);
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString),aCount);
|
||||
return SVCompareChars(mStringValue,theStringValue,aIgnoreCase,aCount);
|
||||
}
|
||||
|
||||
PRInt32 nsCString::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
||||
nsStringValueImpl<PRUnichar> theStringValue(const_cast<PRUnichar*>(aString),aCount);
|
||||
return SVCompare<char,PRUnichar>(mStringValue,theStringValue,aIgnoreCase,aCount);
|
||||
nsStringValueImpl<PRUnichar> theStringValue(CONST_CAST(PRUnichar*,aString),aCount);
|
||||
return SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount);
|
||||
}
|
||||
|
||||
PRBool nsCString::Equals(const nsString &aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
||||
PRInt32 result=SVCompare<char,PRUnichar>(mStringValue,aString.mStringValue,aIgnoreCase,aCount);
|
||||
return PRBool(0==result);
|
||||
return PRBool(0==SVCompare(mStringValue,aString.mStringValue,aIgnoreCase,aCount));
|
||||
}
|
||||
|
||||
PRBool nsCString::Equals(const nsCString &aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
||||
PRInt32 result=SVCompare<char,char>(mStringValue,aString.mStringValue,aIgnoreCase,aCount);
|
||||
PRInt32 result=SVCompareChars(mStringValue,aString.mStringValue,aIgnoreCase,aCount);
|
||||
return PRBool(0==result);
|
||||
}
|
||||
|
||||
PRBool nsCString::Equals(const char* aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString),aCount);
|
||||
PRInt32 result=SVCompare<char,char>(mStringValue,theStringValue,aIgnoreCase,aCount);
|
||||
return PRBool(0==result);
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString),aCount);
|
||||
return PRBool(0==SVCompareChars(mStringValue,theStringValue,aIgnoreCase,aCount));
|
||||
}
|
||||
|
||||
|
||||
PRBool nsCString::Equals(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
||||
nsStringValueImpl<PRUnichar> theStringValue(const_cast<PRUnichar*>(aString),aCount);
|
||||
PRInt32 result=SVCompare<char,PRUnichar>(mStringValue,theStringValue,aIgnoreCase,aCount);
|
||||
return PRBool(0==result);
|
||||
nsStringValueImpl<PRUnichar> theStringValue(CONST_CAST(PRUnichar*,aString),aCount);
|
||||
return PRBool(0==SVCompare(mStringValue,theStringValue,aIgnoreCase,aCount));
|
||||
}
|
||||
|
||||
PRBool nsCString::EqualsIgnoreCase(const char* s1, const char* s2) const {
|
||||
PRBool result=PR_FALSE;
|
||||
return result;
|
||||
}
|
||||
|
||||
// PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
|
||||
PRBool nsCString::Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const {
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/***************************************
|
||||
@@ -644,7 +714,7 @@ PRBool nsCString::EqualsIgnoreCase(const char* s1, const char* s2) const {
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 nsCString::Find(const nsString& aTarget,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const {
|
||||
return SVFind<char,PRUnichar>(mStringValue,aTarget.mStringValue,aIgnoreCase,aRepCount,anOffset);
|
||||
return SVFind(mStringValue,aTarget.mStringValue,aIgnoreCase,aRepCount,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -658,7 +728,7 @@ PRInt32 nsCString::Find(const nsString& aTarget,PRBool aIgnoreCase,PRUint32 anOf
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 nsCString::Find(const nsCString &aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const {
|
||||
return SVFind<char,char>(mStringValue,aString.mStringValue,aIgnoreCase,aRepCount,anOffset);
|
||||
return SVFind(mStringValue,aString.mStringValue,aIgnoreCase,aRepCount,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -672,8 +742,8 @@ PRInt32 nsCString::Find(const nsCString &aString,PRBool aIgnoreCase,PRUint32 anO
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 nsCString::Find(const char* aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const {
|
||||
nsStringValueImpl<char> theString(const_cast<char*>(aString));
|
||||
return SVFind<char,char>(mStringValue,theString,aIgnoreCase,aRepCount,anOffset);
|
||||
nsStringValueImpl<char> theString(CONST_CAST(char*,aString));
|
||||
return SVFind(mStringValue,theString,aIgnoreCase,aRepCount,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -688,8 +758,8 @@ PRInt32 nsCString::Find(const char* aString,PRBool aIgnoreCase,PRUint32 anOffset
|
||||
*/
|
||||
PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRUint32 anOffset,PRInt32 aRepCount) const {
|
||||
|
||||
nsStringValueImpl<PRUnichar> theString(const_cast<PRUnichar*>(aString));
|
||||
return SVFind<char,PRUnichar>(mStringValue,theString,aIgnoreCase,aRepCount,anOffset);
|
||||
nsStringValueImpl<PRUnichar> theString(CONST_CAST(PRUnichar*,aString));
|
||||
return SVFind(mStringValue,theString,aIgnoreCase,aRepCount,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -701,8 +771,8 @@ PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRUint32 anO
|
||||
* @param anOffset -- where in this string to start searching
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsCString::FindCharInSet(const nsString& aString,PRUint32 anOffset) const{
|
||||
return SVFindCharInSet<char,PRUnichar>(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
PRInt32 nsCString::FindCharInSet(const nsCString& aString,PRUint32 anOffset) const{
|
||||
return SVFindCharInSet(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
}
|
||||
|
||||
|
||||
@@ -717,8 +787,8 @@ PRInt32 nsCString::FindCharInSet(const nsString& aString,PRUint32 anOffset) cons
|
||||
*/
|
||||
PRInt32 nsCString::FindCharInSet(const char *aString,PRUint32 anOffset) const{
|
||||
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString));
|
||||
return SVFindCharInSet<char,char>(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString));
|
||||
return SVFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -732,7 +802,7 @@ PRInt32 nsCString::FindCharInSet(const char *aString,PRUint32 anOffset) const{
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 nsCString::FindChar(char aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const {
|
||||
return SVFindChar<char>(mStringValue,aChar,aIgnoreCase,aCount,anOffset);
|
||||
return SVFindChar(mStringValue,aChar,aIgnoreCase,aCount,anOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -746,13 +816,13 @@ PRInt32 nsCString::FindChar(char aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 nsCString::RFindChar(char aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aRepCount) const{
|
||||
return SVRFindChar<char>(mStringValue,aChar,aIgnoreCase,aRepCount,anOffset);
|
||||
return SVRFindChar(mStringValue,aChar,aIgnoreCase,aRepCount,anOffset);
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aRepCount) const{
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString));
|
||||
return SVRFind<char,char>(mStringValue,theStringValue,aIgnoreCase,aRepCount,anOffset);
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString));
|
||||
return SVRFind(mStringValue,theStringValue,aIgnoreCase,aRepCount,anOffset);
|
||||
}
|
||||
|
||||
|
||||
@@ -766,7 +836,7 @@ PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsCString::RFindCharInSet(const nsCString& aString,PRInt32 anOffset) const {
|
||||
return SVRFindCharInSet<char,char>(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
return SVRFindCharInSet(mStringValue,aString.mStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
}
|
||||
|
||||
|
||||
@@ -780,8 +850,8 @@ PRInt32 nsCString::RFindCharInSet(const nsCString& aString,PRInt32 anOffset) con
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsCString::RFindCharInSet(const char* aString,PRInt32 anOffset) const{
|
||||
nsStringValueImpl<char> theStringValue(const_cast<char*>(aString));
|
||||
return SVRFindCharInSet<char,char>(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
nsStringValueImpl<char> theStringValue(CONST_CAST(char*,aString));
|
||||
return SVRFindCharInSet(mStringValue,theStringValue,PR_FALSE,mStringValue.mLength,anOffset);
|
||||
}
|
||||
|
||||
/***************************************
|
||||
@@ -827,7 +897,7 @@ char* nsCString::ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset) con
|
||||
|
||||
|
||||
PRInt32 nsCString::CountChar(char aChar) {
|
||||
return SVCountChar<char>(mStringValue,aChar);
|
||||
return SVCountChar(mStringValue,aChar);
|
||||
}
|
||||
|
||||
//******************************************
|
||||
@@ -837,7 +907,7 @@ PRInt32 nsCString::CountChar(char aChar) {
|
||||
|
||||
//This will not work correctly for any unicode set other than ascii
|
||||
void nsCString::DebugDump(void) const {
|
||||
SVDebugDump<char>(mStringValue);
|
||||
SVDebugDump(mStringValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -852,7 +922,7 @@ float nsCString::ToFloat(PRInt32* aErrorCode) const {
|
||||
return 0.0f;
|
||||
}
|
||||
char* cp = ToCString(buf, sizeof(buf));
|
||||
float f = (float) PR_strtod(cp, &cp);
|
||||
float f = (float) strtod(cp, &cp);
|
||||
if (*cp != 0) {
|
||||
*aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
@@ -860,6 +930,7 @@ float nsCString::ToFloat(PRInt32* aErrorCode) const {
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform string to int conversion.
|
||||
* @param aErrorCode will contain error if one occurs
|
||||
@@ -867,7 +938,214 @@ float nsCString::ToFloat(PRInt32* aErrorCode) const {
|
||||
* @return int rep of string value, and possible (out) error code
|
||||
*/
|
||||
PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const{
|
||||
return SVToInteger<char>(mStringValue,anErrorCode,aRadix);
|
||||
return SVToInteger(mStringValue,anErrorCode,aRadix);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
Now we declare the nsSubsumeCStr class
|
||||
*****************************************************************/
|
||||
|
||||
|
||||
nsSubsumeCStr::nsSubsumeCStr() {
|
||||
}
|
||||
|
||||
nsSubsumeCStr::nsSubsumeCStr(const nsCString& aCString) : mLHS(aCString.mStringValue), mRHS() {
|
||||
}
|
||||
|
||||
nsSubsumeCStr::nsSubsumeCStr(const nsSubsumeCStr& aSubsumeString) :
|
||||
mLHS(aSubsumeString.mLHS),
|
||||
mRHS(aSubsumeString.mRHS) {
|
||||
}
|
||||
|
||||
nsSubsumeCStr::nsSubsumeCStr(const nsStringValueImpl<char> &aLHS,const nsSubsumeCStr& aSubsumeString) :
|
||||
mLHS(aLHS),
|
||||
mRHS(aSubsumeString.mLHS) {
|
||||
}
|
||||
|
||||
nsSubsumeCStr::nsSubsumeCStr(const nsStringValueImpl<char> &aLHS,const nsStringValueImpl<char> &aRHS) :
|
||||
mLHS(aLHS),
|
||||
mRHS(aRHS) {
|
||||
}
|
||||
|
||||
nsSubsumeCStr::nsSubsumeCStr(char* aString,PRBool assumeOwnership,PRInt32 aLength) {
|
||||
}
|
||||
|
||||
nsSubsumeCStr nsSubsumeCStr::operator+(const nsSubsumeCStr &aSubsumeString) {
|
||||
nsSubsumeCStr result(*this);
|
||||
return result;
|
||||
}
|
||||
|
||||
nsSubsumeCStr nsSubsumeCStr::operator+(const nsCString &aCString) {
|
||||
SVAppend(mLHS,mRHS,mRHS.mLength,0);
|
||||
memcpy(&mRHS,&aCString.mStringValue,sizeof(mRHS));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
NS_COM int fputs(const nsCString& aString, FILE* out)
|
||||
{
|
||||
char buf[100];
|
||||
char* cp = buf;
|
||||
PRInt32 len = aString.Length();
|
||||
if (len >= PRInt32(sizeof(buf))) {
|
||||
cp = aString.ToNewCString();
|
||||
} else {
|
||||
aString.ToCString(cp, len + 1);
|
||||
}
|
||||
if(len>0)
|
||||
::fwrite(cp, 1, len, out);
|
||||
if (cp != buf) {
|
||||
delete[] cp;
|
||||
}
|
||||
return (int) len;
|
||||
}
|
||||
|
||||
PRUint32 HashCode(const nsCString& aDest) {
|
||||
PRUint32 result=0;
|
||||
// return (PRUint32)PL_HashString((const void*) aDest.GetBuffer());
|
||||
return result;
|
||||
}
|
||||
|
||||
void Recycle( char* aBuffer) {
|
||||
nsAllocator::Free(aBuffer);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
Now we declare the nsCAutoString class
|
||||
*****************************************************************/
|
||||
|
||||
|
||||
nsCAutoString::nsCAutoString() : nsCString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
}
|
||||
|
||||
//call this version nsAutoString derivatives...
|
||||
nsCAutoString::nsCAutoString(const nsCAutoString& aString,PRInt32 aLength) : nsCString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
Assign(aString,aLength);
|
||||
}
|
||||
|
||||
//call this version for nsCString,nsCString and the autostrings
|
||||
nsCAutoString::nsCAutoString(const nsCString& aString,PRInt32 aLength) : nsCString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
Assign(aString,aLength);
|
||||
}
|
||||
|
||||
//call this version for char*'s....
|
||||
nsCAutoString::nsCAutoString(const char* aString,PRInt32 aLength) : nsCString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
|
||||
nsCString theString(aString);
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
Assign(theString,aLength);
|
||||
}
|
||||
|
||||
//call this version for a single char of type char...
|
||||
nsCAutoString::nsCAutoString(const char aChar) : nsCString() {
|
||||
char theBuffer[]={aChar,0};
|
||||
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
|
||||
nsCString theString(theBuffer,1);
|
||||
Assign(theString,1,0);
|
||||
}
|
||||
|
||||
|
||||
//call this version for PRUnichar*'s....
|
||||
nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
nsStringValueImpl<PRUnichar> theString(CONST_CAST(PRUnichar*,aString),aLength);
|
||||
SVAssign(mStringValue,theString,theString.mLength,0);
|
||||
}
|
||||
|
||||
|
||||
//call this version for all other ABT versions of readable strings
|
||||
nsCAutoString::nsCAutoString(const nsAReadableString &aString) : nsCString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
Assign(aString);
|
||||
}
|
||||
|
||||
nsCAutoString::nsCAutoString(const nsCStackBuffer &aBuffer) : nsCString() {
|
||||
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
|
||||
mStringValue.mLength=aBuffer.mLength;
|
||||
mStringValue.mCapacity=aBuffer.mCapacity;
|
||||
mStringValue.mBuffer=aBuffer.mBuffer;
|
||||
|
||||
}
|
||||
|
||||
nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
|
||||
|
||||
mStringValue.mBuffer=aBuffer.mBuffer;
|
||||
mStringValue.mCapacity=aBuffer.mCapacity;
|
||||
mStringValue.mLength=aBuffer.mLength;
|
||||
mStringValue.mRefCount=(aBuffer.mStackBased) ? 2 : 1;
|
||||
|
||||
}
|
||||
|
||||
nsCAutoString::nsCAutoString(const nsSubsumeCStr& aCSubsumeStringX) : nsCString() {
|
||||
}
|
||||
|
||||
nsCAutoString::~nsCAutoString() {
|
||||
}
|
||||
|
||||
|
||||
nsCAutoString& nsCAutoString::operator=(const nsCAutoString& aCopy) {
|
||||
if(aCopy.mStringValue.mBuffer!=mStringValue.mBuffer) {
|
||||
Assign(aCopy);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsCAutoString& nsCAutoString::operator=(const nsCString& aString) {
|
||||
Assign(aString);
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsCAutoString& nsCAutoString::operator=(const char* aString) {
|
||||
if(mStringValue.mBuffer!=aString) {
|
||||
nsCString theStringValue(CONST_CAST(char*,aString));
|
||||
Assign(aString);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsCAutoString& nsCAutoString::operator=(const PRUnichar* aString) {
|
||||
nsStringValueImpl<PRUnichar> theStringValue(CONST_CAST(PRUnichar*,aString));
|
||||
SVAssign(mStringValue,theStringValue,theStringValue.mLength,0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsCAutoString& nsCAutoString::operator=(const char aChar) {
|
||||
Assign(aChar);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
nsCAutoString& nsCAutoString::operator=(const nsSubsumeCStr &aSubsumeString) {
|
||||
nsCString::operator=(aSubsumeString);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,13 @@
|
||||
#define _NS_CSTRING_
|
||||
|
||||
#include "nsStringValue.h"
|
||||
#include "nsString2.h"
|
||||
|
||||
class NS_COM nsSubsumeCStr;
|
||||
|
||||
class nsString;
|
||||
typedef nsStackBuffer<char> nsCStackBuffer;
|
||||
|
||||
class nsCString: public nsAReadableString {
|
||||
class NS_COM nsCString {
|
||||
public:
|
||||
|
||||
//******************************************
|
||||
@@ -49,48 +51,65 @@ public:
|
||||
//call this version for PRUnichar*'s....
|
||||
nsCString(const PRUnichar* aString,PRInt32 aLength=-1) ;
|
||||
|
||||
//call this version for stack-based string buffers...
|
||||
nsCString(const nsSubsumeCStr &aSubsumeString);
|
||||
|
||||
//call this version for stack-based string buffers...
|
||||
nsCString(nsSubsumeCStr &aSubsumeString);
|
||||
|
||||
//call this version for all other ABT versions of readable strings
|
||||
nsCString(const nsAReadableString &aString) ;
|
||||
|
||||
//call this version for stack-based string buffers...
|
||||
nsCString(const nsStackBuffer<char> &aBuffer);
|
||||
nsCString(const nsCStackBuffer &aBuffer);
|
||||
|
||||
virtual ~nsCString();
|
||||
|
||||
|
||||
void Reinitialize(char* aBuffer,PRUint32 aCapacity,PRInt32 aLength=-1);
|
||||
|
||||
//******************************************
|
||||
// Concat operators
|
||||
//******************************************
|
||||
|
||||
nsSubsumeCStr operator+(const nsCString &aCString);
|
||||
nsSubsumeCStr operator+(const char* aCString);
|
||||
nsSubsumeCStr operator+(char aChar);
|
||||
|
||||
|
||||
//******************************************
|
||||
// Assigment operators
|
||||
//******************************************
|
||||
|
||||
|
||||
nsCString& operator=(const nsCString& aString);
|
||||
|
||||
nsCString& operator=(const nsString& aString);
|
||||
|
||||
nsCString& operator=(const char* aString);
|
||||
|
||||
nsCString& operator=(const PRUnichar* aString);
|
||||
|
||||
nsCString& operator=(const char aChar);
|
||||
nsCString& operator=(const nsSubsumeCStr &aSubsumeString);
|
||||
|
||||
//******************************************
|
||||
// Here are the accessor methods...
|
||||
//******************************************
|
||||
|
||||
virtual nsresult SetLength(PRUint32 aLength) {
|
||||
if(aLength>mStringValue.mLength)
|
||||
SetCapacity(aLength);
|
||||
Truncate(aLength);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
virtual nsresult SetCapacity(PRUint32 aCapacity);
|
||||
|
||||
char* GetBuffer() { return mStringValue.mBuffer;}
|
||||
char* GetBuffer() const { return mStringValue.mBuffer;}
|
||||
|
||||
char& operator[](PRUint32 aOffset);
|
||||
char operator[](PRUint32 aOffset) const {return CharAt(aOffset);}
|
||||
|
||||
// operator const PRUnichar* const() {return mStringValue.mBuffer;}
|
||||
operator const char*() const {return (const char*)mStringValue.mBuffer;}
|
||||
operator char*() const {return mStringValue.mBuffer;}
|
||||
|
||||
PRUint32 Length() const {return mStringValue.mLength;}
|
||||
PRUint32 Capacity() const {return mStringValue.mCapacity;}
|
||||
|
||||
size_t GetCharSize() const {return sizeof(mStringValue.mBuffer[0]);}
|
||||
|
||||
@@ -112,10 +131,11 @@ public:
|
||||
return CharAt(mStringValue.mLength-1);
|
||||
}
|
||||
|
||||
|
||||
//these aren't the real deal, but serve as a placeholder for us to implement iterators.
|
||||
virtual nsAReadableStringIterator* First();
|
||||
virtual nsAReadableStringIterator* Last();
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
||||
if (aResult) {
|
||||
*aResult = sizeof(*this) + Capacity();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//******************************************
|
||||
@@ -137,21 +157,19 @@ public:
|
||||
*/
|
||||
virtual nsresult Assign(const nsCString& aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
|
||||
|
||||
virtual nsresult Assign(const nsString& aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
|
||||
|
||||
virtual nsresult Assign(const char* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
|
||||
|
||||
// virtual nsresult Assign(const PRUnichar* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
|
||||
virtual nsresult Assign(const PRUnichar* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
|
||||
|
||||
virtual nsresult Assign(const nsAReadableString &aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
|
||||
|
||||
virtual nsresult Assign(char aChar);
|
||||
|
||||
/**
|
||||
* Functionally equivalent to assign or operator=, and deprePRUnichared!
|
||||
*
|
||||
*/
|
||||
nsresult SetString(const nsCString &aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
|
||||
nsresult SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
|
||||
nsresult SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
|
||||
nsCString& SetString(const char* aString,PRInt32 aLength=-1) {Assign(aString, aLength); return *this;}
|
||||
nsCString& SetString(const nsCString& aString,PRInt32 aLength=-1) {Assign(aString, aLength); return *this;}
|
||||
|
||||
|
||||
//***************************************
|
||||
// Here come the append methods...
|
||||
@@ -172,7 +190,7 @@ public:
|
||||
|
||||
virtual nsresult Append(const char* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
|
||||
|
||||
// virtual nsresult Append(const PRUnichar* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
|
||||
virtual nsresult Append(const PRUnichar* aString,PRInt32 aLength=-1,PRUint32 aSrcOffset=0);
|
||||
|
||||
virtual nsresult Append(const char aChar) ;
|
||||
|
||||
@@ -273,7 +291,7 @@ public:
|
||||
|
||||
nsresult StripChar(PRInt32 anInt,PRUint32 anOffset=0);
|
||||
|
||||
nsresult StripChars(const char* aSet);
|
||||
nsresult StripChars(const char* aSet,PRInt32 aLength=-1);
|
||||
|
||||
nsresult StripWhitespace();
|
||||
|
||||
@@ -293,16 +311,15 @@ public:
|
||||
//*******************************************
|
||||
|
||||
nsCString& operator+=(const nsCString& aString);
|
||||
|
||||
nsCString& operator+=(const PRUnichar* aString);
|
||||
|
||||
nsCString& operator+=(const char* aString);
|
||||
|
||||
nsCString& operator+=(const PRUnichar aChar);
|
||||
|
||||
nsCString& operator+=(const char aChar);
|
||||
|
||||
nsCString& operator+=(const int anInt);
|
||||
nsCString& operator+=(const nsSubsumeCStr &aSubsumeString) {
|
||||
//NOT IMPLEMENTED
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/***********************************
|
||||
@@ -312,6 +329,7 @@ public:
|
||||
PRBool operator==(const nsCString& aString) const {return Equals(aString);}
|
||||
PRBool operator==(const PRUnichar* aString) const {return Equals(aString);}
|
||||
PRBool operator==(const char* aString) const {return Equals(aString);}
|
||||
PRBool operator==(char* aString) const {return Equals(aString);}
|
||||
|
||||
PRBool operator!=(const nsCString& aString) const {return PRBool(Compare(aString)!=0);}
|
||||
PRBool operator!=(const PRUnichar* aString) const {return PRBool(Compare(aString)!=0);}
|
||||
@@ -335,24 +353,18 @@ public:
|
||||
|
||||
|
||||
PRInt32 Compare(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const ;
|
||||
|
||||
PRBool Equals(const nsCString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
|
||||
|
||||
PRBool EqualsIgnoreCase(const nsCString &aString) const {return Equals(aString,PR_TRUE);}
|
||||
PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const {return Equals(aString,PR_TRUE);}
|
||||
PRBool EqualsIgnoreCase(const char* s1, const char* s2) const;
|
||||
|
||||
// PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
|
||||
PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const;
|
||||
|
||||
|
||||
/***************************************
|
||||
@@ -373,7 +385,7 @@ public:
|
||||
PRInt32 Find(const nsString& aTarget,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const;
|
||||
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const;
|
||||
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRUint32 anOffset=0,PRInt32 aRepCount=-1) const;
|
||||
PRInt32 FindChar(char aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aRepCount=-1) const ;
|
||||
PRInt32 FindChar(char aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aRepCount=-1) const ;
|
||||
|
||||
PRInt32 FindCharInSet(const nsCString& aString,PRUint32 anOffset=0) const;
|
||||
PRInt32 FindCharInSet(const nsString& aString,PRUint32 anOffset=0) const;
|
||||
@@ -443,8 +455,37 @@ protected:
|
||||
nsStringValueImpl<char> mStringValue;
|
||||
|
||||
friend class nsString;
|
||||
friend class nsSubsumeCStr;
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
Now we declare the nsSubsumeCStr class
|
||||
*****************************************************************/
|
||||
|
||||
class NS_COM nsSubsumeCStr {
|
||||
public:
|
||||
|
||||
nsSubsumeCStr();
|
||||
|
||||
nsSubsumeCStr(const nsCString& aCString);
|
||||
|
||||
nsSubsumeCStr(const nsSubsumeCStr& aSubsumeString);
|
||||
|
||||
nsSubsumeCStr(const nsStringValueImpl<char> &aLHS,const nsSubsumeCStr& aSubsumeString);
|
||||
|
||||
nsSubsumeCStr(const nsStringValueImpl<char> &aLHS,const nsStringValueImpl<char> &aSubsumeString);
|
||||
|
||||
nsSubsumeCStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
|
||||
|
||||
nsSubsumeCStr operator+(const nsSubsumeCStr &aSubsumeString);
|
||||
|
||||
nsSubsumeCStr operator+(const nsCString &aCString);
|
||||
|
||||
operator const char*() {return 0;}
|
||||
|
||||
nsStringValueImpl<char> mLHS;
|
||||
nsStringValueImpl<char> mRHS;
|
||||
};
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
@@ -452,122 +493,56 @@ protected:
|
||||
*****************************************************************/
|
||||
|
||||
|
||||
class nsCAutoString : public nsCString {
|
||||
class NS_COM nsCAutoString : public nsCString {
|
||||
public:
|
||||
|
||||
nsCAutoString() : nsCString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
}
|
||||
nsCAutoString() ;
|
||||
|
||||
//call this version nsAutoString derivatives...
|
||||
nsCAutoString(const nsCAutoString& aString,PRInt32 aLength=-1) : nsCString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
Assign(aString,aLength);
|
||||
}
|
||||
nsCAutoString(const nsCAutoString& aString,PRInt32 aLength=-1);
|
||||
|
||||
//call this version for nsCString,nsCString and the autostrings
|
||||
nsCAutoString(const nsCString& aString,PRInt32 aLength=-1) : nsCString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
Assign(aString,aLength);
|
||||
}
|
||||
|
||||
nsCAutoString(const nsCString& aString,PRInt32 aLength=-1) ;
|
||||
//call this version for char*'s....
|
||||
nsCAutoString(const char* aString,PRInt32 aLength=-1) : nsCString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
|
||||
nsCString theString(aString);
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
Assign(theString,aLength);
|
||||
}
|
||||
nsCAutoString(const char* aString,PRInt32 aLength=-1);
|
||||
|
||||
//call this version for a single char of type char...
|
||||
nsCAutoString(const char aChar) : nsCString() {
|
||||
char theBuffer[]={aChar,0};
|
||||
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
|
||||
nsCString theString(theBuffer,1);
|
||||
Assign(theString,1,0);
|
||||
}
|
||||
|
||||
nsCAutoString(const char aChar) ;
|
||||
|
||||
//call this version for PRUnichar*'s....
|
||||
nsCAutoString(const PRUnichar* aString,PRInt32 aLength=-1) : nsCString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
nsStringValueImpl<PRUnichar> theString(const_cast<PRUnichar*>(aString),aLength);
|
||||
SVAssign<char,PRUnichar>(mStringValue,theString,theString.mLength,0);
|
||||
}
|
||||
|
||||
nsCAutoString(const PRUnichar* aString,PRInt32 aLength=-1) ;
|
||||
|
||||
//call this version for all other ABT versions of readable strings
|
||||
nsCAutoString(const nsAReadableString &aString) : nsCString() {
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
mStringValue.mCapacity=kDefaultStringSize;
|
||||
mStringValue.mBuffer=mInternalBuffer;
|
||||
Assign(aString);
|
||||
}
|
||||
nsCAutoString(const nsAReadableString &aString);
|
||||
|
||||
nsCAutoString(const nsStackBuffer<char> &aBuffer) : nsCString() {
|
||||
nsCAutoString(const nsCStackBuffer &aBuffer) ;
|
||||
|
||||
memset(mInternalBuffer,0,sizeof(mInternalBuffer));
|
||||
nsCAutoString(const CBufDescriptor& aBuffer) ;
|
||||
|
||||
mStringValue.mRefCount=2;
|
||||
mStringValue.mLength=aBuffer.mLength;
|
||||
mStringValue.mCapacity=aBuffer.mCapacity;
|
||||
mStringValue.mBuffer=aBuffer.mBuffer;
|
||||
|
||||
}
|
||||
nsCAutoString(const nsSubsumeCStr& aCSubsumeStringX) ;
|
||||
|
||||
|
||||
virtual ~nsCAutoString() { }
|
||||
virtual ~nsCAutoString() ;
|
||||
|
||||
|
||||
nsCAutoString& operator=(const nsCAutoString& aCopy) {
|
||||
if(aCopy.mStringValue.mBuffer!=mStringValue.mBuffer) {
|
||||
Assign(aCopy);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
nsCAutoString& operator=(const nsCAutoString& aCopy) ;
|
||||
|
||||
nsCAutoString& operator=(const nsCString& aString) {
|
||||
Assign(aString);
|
||||
return *this;
|
||||
}
|
||||
nsCAutoString& operator=(const nsCString& aString) ;
|
||||
|
||||
nsCAutoString& operator=(const char* aString) {
|
||||
if(mStringValue.mBuffer!=aString) {
|
||||
nsCString theStringValue(const_cast<char*>(aString));
|
||||
Assign(aString);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
nsCAutoString& operator=(const char* aString) ;
|
||||
|
||||
nsCAutoString& operator=(const PRUnichar* aString) {
|
||||
nsStringValueImpl<PRUnichar> theStringValue(const_cast<PRUnichar*>(aString));
|
||||
SVAssign<char,PRUnichar>(mStringValue,theStringValue,theStringValue.mLength,0);
|
||||
return *this;
|
||||
}
|
||||
nsCAutoString& operator=(const PRUnichar* aString) ;
|
||||
|
||||
nsCAutoString& operator=(const char aChar) {
|
||||
Assign(aChar);
|
||||
return *this;
|
||||
}
|
||||
nsCAutoString& operator=(const char aChar) ;
|
||||
|
||||
nsCAutoString& operator=(const nsSubsumeCStr &aSubsumeString);
|
||||
|
||||
protected:
|
||||
char mInternalBuffer[kDefaultStringSize+1];
|
||||
};
|
||||
|
||||
extern PRUint32 HashCode(const nsCString& aDest);
|
||||
extern NS_COM int fputs(const nsCString& aString, FILE* out);
|
||||
extern NS_COM void Recycle( char* aBuffer);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user