fix for bug 114450 - be explicit about string comparison w.r.t. character size - no more hand-rolled vtables!

sr=jag, r=dbaron
This commit is contained in:
alecf%netscape.com 2002-01-24 19:14:18 +00:00
Родитель 4400a74ab1
Коммит 0b5abd6365
14 изменённых файлов: 970 добавлений и 558 удалений

Просмотреть файл

@ -528,7 +528,7 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset
* @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length.
* @return index of pos if found, else -1 (kNotFound)
*/
inline PRInt32 FindChar2(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount) {
inline PRInt32 FindChar2(const PRUnichar* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount) {
#ifndef XPCOM_STANDALONE
if(anOffset<0)
@ -541,7 +541,7 @@ inline PRInt32 FindChar2(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset
if(0<aCount) {
const PRUnichar* root = (PRUnichar*)aDest;
const PRUnichar* root = aDest;
const PRUnichar* left = root+anOffset;
const PRUnichar* last = left+aCount;
const PRUnichar* max = root+aDestLength;
@ -647,7 +647,7 @@ inline PRInt32 RFindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffse
* @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length.
* @return index of pos if found, else -1 (kNotFound)
*/
inline PRInt32 RFindChar2(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount) {
inline PRInt32 RFindChar2(const PRUnichar* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount) {
#ifndef XPCOM_STANDALONE
if(anOffset<0)
@ -660,7 +660,7 @@ inline PRInt32 RFindChar2(const char* aDest,PRUint32 aDestLength,PRInt32 anOffse
if(0<aCount) {
const PRUnichar* root = (PRUnichar*)aDest;
const PRUnichar* root = aDest;
const PRUnichar* rightmost = root+anOffset;
const PRUnichar* min = rightmost-aCount+1;
const PRUnichar* leftmost = (min<root) ? root: min;
@ -696,9 +696,6 @@ inline PRInt32 RFindChar2(const char* aDest,PRUint32 aDestLength,PRInt32 anOffse
return kNotFound;
}
typedef PRInt32 (*FindChars)(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount);
FindChars gFindChars[]={&FindChar1,&FindChar2};
//----------------------------------------------------------------------------------------
//
// This set of methods is used to compare one buffer onto another.
@ -717,7 +714,7 @@ FindChars gFindChars[]={&FindChar1,&FindChar2};
* @param aIgnorecase tells us whether to use a case-sensitive comparison
* @return -1,0,1 depending on <,==,>
*/
PRInt32 Compare1To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
static inline PRInt32 Compare1To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
PRInt32 Compare1To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
PRInt32 result=0;
if(aIgnoreCase)
@ -735,13 +732,13 @@ PRInt32 Compare1To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool a
* @param aIgnorecase tells us whether to use a case-sensitive comparison
* @return -1,0,1 depending on <,==,>
*/
PRInt32 Compare2To2(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
PRInt32 Compare2To2(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
PRInt32 Compare2To2(const PRUnichar* aStr1,const PRUnichar* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
PRInt32 Compare2To2(const PRUnichar* aStr1,const PRUnichar* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
PRInt32 result=0;
#ifndef XPCOM_STANDALONE
if(aIgnoreCase && NS_SUCCEEDED(NS_InitCaseConversion()))
gCaseConv->CaseInsensitiveCompare((PRUnichar*)aStr1, (PRUnichar*)aStr2, aCount, &result);
else result=nsCRT::strncmp((PRUnichar*)aStr1,(PRUnichar*)aStr2,aCount);
gCaseConv->CaseInsensitiveCompare(aStr1, aStr2, aCount, &result);
else result=nsCRT::strncmp(aStr1,aStr2,aCount);
#else
NS_ERROR("call not supported in XPCOM_STANDALONE");
#endif
@ -758,10 +755,10 @@ PRInt32 Compare2To2(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool a
* @param aIgnorecase tells us whether to use a case-sensitive comparison
* @return -1,0,1 depending on <,==,>
*/
PRInt32 Compare2To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
PRInt32 Compare2To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
static PRInt32 Compare2To1(const PRUnichar* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
PRInt32 Compare2To1(const PRUnichar* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
#ifndef XPCOM_STANDALONE
PRUnichar* s1 = (PRUnichar*)aStr1;
const PRUnichar* s1 = aStr1;
const char *s2 = aStr2;
if (aIgnoreCase && NS_FAILED(NS_InitCaseConversion()))
@ -804,19 +801,12 @@ PRInt32 Compare2To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool a
* @param aIgnorecase tells us whether to use a case-sensitive comparison
* @return -1,0,1 depending on <,==,>
*/
PRInt32 Compare1To2(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
PRInt32 Compare1To2(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
static inline PRInt32 Compare1To2(const char* aStr1,const PRUnichar* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
PRInt32 Compare1To2(const char* aStr1,const PRUnichar* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
return Compare2To1(aStr2, aStr1, aCount, aIgnoreCase) * -1;
}
typedef PRInt32 (*CompareChars)(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
CompareChars gCompare[2][2]={
{&Compare1To1,&Compare1To2},
{&Compare2To1,&Compare2To2},
};
//----------------------------------------------------------------------------------------
//
// This set of methods is used compress char sequences in a buffer...

Просмотреть файл

@ -502,7 +502,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
if(aEliminateLeading) {
while(++theIndex<=theMax) {
PRUnichar theChar=GetCharAt(aDest,theIndex);
PRInt32 thePos=FindChar1(aSet,theSetLen,0,theChar,PR_FALSE,theSetLen);
PRInt32 thePos=::FindChar1(aSet,theSetLen,0,theChar,PR_FALSE,theSetLen);
if(kNotFound==thePos)
break;
}
@ -523,7 +523,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
PRInt32 theNewLen=theIndex;
while(--theIndex>=0) {
PRUnichar theChar=GetCharAt(aDest,theIndex); //read at end now...
PRInt32 thePos=FindChar1(aSet,theSetLen,0,theChar,PR_FALSE,theSetLen);
PRInt32 thePos=::FindChar1(aSet,theSetLen,0,theChar,PR_FALSE,theSetLen);
if(kNotFound<thePos)
theNewLen=theIndex;
else break;
@ -604,39 +604,161 @@ void nsStr::StripChars2(nsStr& aDest,const char* aSet){
* @param aCount tells us how many iterations to make from offset; -1 means the full length of the string
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
PRInt32 nsStr::FindSubstr1in1(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eOneByte, "Must be 1 byte");
NS_ASSERTION(aTarget.mCharSize == eOneByte, "Must be 1 byte");
PRInt32 theMaxPos = aDest.mLength-aTarget.mLength; //this is the last pos that is feasible for starting the search, with given lengths...
if(0<=theMaxPos) {
if (theMaxPos<0) return kNotFound;
if(anOffset<0)
anOffset=0;
if(anOffset<0)
anOffset=0;
if((0<aDest.mLength) && (anOffset<=theMaxPos) && (aTarget.mLength)) {
if((aDest.mLength<=0) || (anOffset>theMaxPos) || (aTarget.mLength==0))
return kNotFound;
if(aCount<0)
aCount = MaxInt(theMaxPos,1);
if(aCount<0)
aCount = MaxInt(theMaxPos,1);
if(0<aCount) {
if (aCount <= 0)
return kNotFound;
PRInt32 aDelta= (aDest.mCharSize == eOneByte) ? 1 : 2;
const char* root = aDest.mStr;
const char* left = root+(anOffset*aDelta);
const char* last = left+((aCount)*aDelta);
const char* max = root+(theMaxPos*aDelta);
const char* right = (last<max) ? last : max;
const char* root = aDest.mStr;
const char* left = root + anOffset;
const char* last = left + aCount;
const char* max = root + theMaxPos;
const char* right = (last<max) ? last : max;
while(left<=right){
PRInt32 cmp=(*gCompare[aDest.mCharSize][aTarget.mCharSize])(left,aTarget.mStr,aTarget.mLength,aIgnoreCase);
if(0==cmp) {
return (left-root)/aDelta;
}
left+=aDelta;
} //while
} //if
while(left<=right){
PRInt32 cmp=Compare1To1(left,aTarget.mStr,aTarget.mLength,aIgnoreCase);
if(0==cmp) {
return (left-root);
}
} //if
left++;
} //while
return kNotFound;
}
PRInt32 nsStr::FindSubstr2in1(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eOneByte, "Must be 1 byte");
NS_ASSERTION(aTarget.mCharSize == eTwoByte, "Must be 2 byte");
PRInt32 theMaxPos = aDest.mLength-aTarget.mLength; //this is the last pos that is feasible for starting the search, with given lengths...
if (theMaxPos<0) return kNotFound;
if(anOffset<0)
anOffset=0;
if((aDest.mLength<=0) || (anOffset>theMaxPos) || (aTarget.mLength==0))
return kNotFound;
if(aCount<0)
aCount = MaxInt(theMaxPos,1);
if (aCount <= 0)
return kNotFound;
const char* root = aDest.mStr;
const char* left = root+anOffset;
const char* last = left+aCount;
const char* max = root+theMaxPos;
const char* right = (last<max) ? last : max;
while(left<=right){
PRInt32 cmp=Compare1To2(left,aTarget.mUStr,aTarget.mLength,aIgnoreCase);
if(0==cmp) {
return (left-root);
}
left++;
} //while
return kNotFound;
}
PRInt32 nsStr::FindSubstr1in2(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eTwoByte, "Must be 2 byte");
NS_ASSERTION(aTarget.mCharSize == eOneByte, "Must be 1 byte");
PRInt32 theMaxPos = aDest.mLength-aTarget.mLength; //this is the last pos that is feasible for starting the search, with given lengths...
if (theMaxPos<0) return kNotFound;
if(anOffset<0)
anOffset=0;
if((aDest.mLength<=0) || (anOffset>theMaxPos) || (aTarget.mLength==0))
return kNotFound;
if(aCount<0)
aCount = MaxInt(theMaxPos,1);
if (aCount <= 0)
return kNotFound;
const PRUnichar* root = aDest.mUStr;
const PRUnichar* left = root+anOffset;
const PRUnichar* last = left+aCount;
const PRUnichar* max = root+theMaxPos;
const PRUnichar* right = (last<max) ? last : max;
while(left<=right){
PRInt32 cmp=Compare2To1(left,aTarget.mStr,aTarget.mLength,aIgnoreCase);
if(0==cmp) {
return (left-root);
}
left++;
} //while
return kNotFound;
}
PRInt32 nsStr::FindSubstr2in2(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eTwoByte, "Must be 2 byte");
NS_ASSERTION(aTarget.mCharSize == eTwoByte, "Must be 2 byte");
PRInt32 theMaxPos = aDest.mLength-aTarget.mLength; //this is the last pos that is feasible for starting the search, with given lengths...
if (theMaxPos<0) return kNotFound;
if(anOffset<0)
anOffset=0;
if((aDest.mLength<=0) || (anOffset>theMaxPos) || (aTarget.mLength==0))
return kNotFound;
if(aCount<0)
aCount = MaxInt(theMaxPos,1);
if (aCount <= 0)
return kNotFound;
const PRUnichar* root = aDest.mUStr;
const PRUnichar* left = root+anOffset;
const PRUnichar* last = left+aCount;
const PRUnichar* max = root+theMaxPos;
const PRUnichar* right = (last<max) ? last : max;
while(left<=right){
PRInt32 cmp=Compare2To2(left,aTarget.mUStr,aTarget.mLength,aIgnoreCase);
if(0==cmp) {
return (left-root);
}
left++;
} //while
return kNotFound;
}
@ -653,8 +775,15 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor
* @param aCount tell us how many chars to search from offset
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
return gFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase,aCount);
PRInt32 nsStr::FindChar1(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eOneByte, "Must be 1 byte");
return ::FindChar1(aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase,aCount);
}
PRInt32 nsStr::FindChar2(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eTwoByte, "Must be 2 byte");
return ::FindChar2(aDest.mUStr,aDest.mLength,anOffset,aChar,aIgnoreCase,aCount);
}
@ -668,18 +797,40 @@ PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,P
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset) {
//NS_PRECONDITION(aSet.mLength!=1,kCallFindChar);
PRInt32 nsStr::FindCharInSet1(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset) {
NS_ASSERTION(aSet.mCharSize == eOneByte, "Must be 1 byte");
PRInt32 index=(0<=anOffset) ? anOffset-1 : -1;
PRInt32 thePos;
//Note that the search is inverted here. We're scanning aDest, one char at a time
//but doing the search against the given set. That's why we use 0 as the offset below.
// Note that the search is inverted here. We're scanning aDest,
// one char at a time but doing the search against the given
// set. That's why we use 0 as the offset below.
if((0<aDest.mLength) && (0<aSet.mLength)){
while(++index<(PRInt32)aDest.mLength) {
PRUnichar theChar=GetCharAt(aDest,index);
thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase,aSet.mLength);
thePos=::FindChar1(aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase,aSet.mLength);
if(kNotFound!=thePos)
return index;
} //while
}
return kNotFound;
}
PRInt32 nsStr::FindCharInSet2(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset) {
NS_ASSERTION(aSet.mCharSize == eTwoByte, "Must be 2 byte");
PRInt32 index=(0<=anOffset) ? anOffset-1 : -1;
PRInt32 thePos;
// Note that the search is inverted here. We're scanning aDest,
// one char at a time but doing the search against the given
// set. That's why we use 0 as the offset below.
if((0<aDest.mLength) && (0<aSet.mLength)){
while(++index<(PRInt32)aDest.mLength) {
PRUnichar theChar=GetCharAt(aDest,index);
thePos=::FindChar2(aSet.mUStr,aSet.mLength,0,theChar,aIgnoreCase,aSet.mLength);
if(kNotFound!=thePos)
return index;
} //while
@ -703,41 +854,162 @@ PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnore
* @param aCount tell us how many iterations to perform from offset
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
PRInt32 nsStr::RFindSubstr1in1(const nsStr& aDest,const nsStr& aTarget,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eOneByte, "Must be 1 byte");
NS_ASSERTION(aTarget.mCharSize == eOneByte, "Must be 1 byte");
if(anOffset<0)
anOffset=(PRInt32)aDest.mLength-1;
if(aCount<0)
aCount = aDest.mLength;
if((0<aDest.mLength) &&
((PRUint32)anOffset<aDest.mLength) &&
(aTarget.mLength)) {
if ((aDest.mLength <= 0) || (PRUint32(anOffset)>=aDest.mLength) || (aTarget.mLength==0))
return kNotFound;
if (aCount<=0)
return kNotFound;
const char* root = aDest.mStr;
const char* destLast = root+aDest.mLength; //pts to last char in aDest (likely null)
const char* rightmost = root+anOffset;
const char* min = rightmost-aCount + 1;
const char* leftmost = (min<root) ? root: min;
if(0<aCount) {
while(leftmost<=rightmost) {
//don't forget to divide by delta in next text (bug found by rhp)...
if(aTarget.mLength<=PRUint32(destLast-rightmost)) {
PRInt32 result=Compare1To1(rightmost,aTarget.mStr,aTarget.mLength,aIgnoreCase);
if(0==result) {
return (rightmost-root);
}
} //if
rightmost--;
} //while
PRInt32 aDelta = (aDest.mCharSize == eOneByte) ? 1 : 2;
const char* root = aDest.mStr;
const char* destLast = root+(aDest.mLength*aDelta); //pts to last char in aDest (likely null)
return kNotFound;
}
const char* rightmost = root+(anOffset*aDelta);
const char* min = rightmost-((aCount-1)*aDelta);
PRInt32 nsStr::RFindSubstr2in1(const nsStr& aDest,const nsStr& aTarget,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
const char* leftmost = (min<root) ? root: min;
NS_ASSERTION(aDest.mCharSize == eOneByte, "Must be 1 byte");
NS_ASSERTION(aTarget.mCharSize == eTwoByte, "Must be 2 byte");
if(anOffset<0)
anOffset=(PRInt32)aDest.mLength-1;
while(leftmost<=rightmost) {
//don't forget to divide by delta in next text (bug found by rhp)...
if(aTarget.mLength<=PRUint32((destLast-rightmost)/aDelta)) {
PRInt32 result=(*gCompare[aDest.mCharSize][aTarget.mCharSize])(rightmost,aTarget.mStr,aTarget.mLength,aIgnoreCase);
if(aCount<0)
aCount = aDest.mLength;
if(0==result) {
return (rightmost-root)/aDelta;
}
} //if
rightmost-=aDelta;
} //while
}
}
if ((aDest.mLength <= 0) || (PRUint32(anOffset)>=aDest.mLength) || (aTarget.mLength==0))
return kNotFound;
if (aCount<=0)
return kNotFound;
const char* root = aDest.mStr;
const char* destLast = root+aDest.mLength; //pts to last char in aDest (likely null)
const char* rightmost = root+anOffset;
const char* min = rightmost-aCount+1;
const char* leftmost = (min<root) ? root: min;
while(leftmost<=rightmost) {
//don't forget to divide by delta in next text (bug found by rhp)...
if(aTarget.mLength<=PRUint32(destLast-rightmost)) {
PRInt32 result=Compare1To2(rightmost,aTarget.mUStr,aTarget.mLength,aIgnoreCase);
if(0==result) {
return (rightmost-root);
}
} //if
rightmost--;
} //while
return kNotFound;
}
PRInt32 nsStr::RFindSubstr1in2(const nsStr& aDest,const nsStr& aTarget,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eTwoByte, "Must be 2 byte");
NS_ASSERTION(aTarget.mCharSize == eOneByte, "Must be 1 byte");
if(anOffset<0)
anOffset=(PRInt32)aDest.mLength-1;
if(aCount<0)
aCount = aDest.mLength;
if ((aDest.mLength <= 0) || (PRUint32(anOffset)>=aDest.mLength) || (aTarget.mLength==0))
return kNotFound;
if (aCount<=0)
return kNotFound;
const PRUnichar* root = aDest.mUStr;
const PRUnichar* destLast = root+aDest.mLength; //pts to last char in aDest (likely null)
const PRUnichar* rightmost = root+anOffset;
const PRUnichar* min = rightmost-aCount+1;
const PRUnichar* leftmost = (min<root) ? root: min;
while(leftmost<=rightmost) {
//don't forget to divide by delta in next text (bug found by rhp)...
if(aTarget.mLength<=PRUint32(destLast-rightmost)) {
PRInt32 result = Compare2To1(rightmost,aTarget.mStr,aTarget.mLength,aIgnoreCase);
if(0==result) {
return rightmost-root;
}
} //if
rightmost--;
} //while
return kNotFound;
}
PRInt32 nsStr::RFindSubstr2in2(const nsStr& aDest,const nsStr& aTarget,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eTwoByte, "Must be 2 byte");
NS_ASSERTION(aTarget.mCharSize == eTwoByte, "Must be 2 byte");
if(anOffset<0)
anOffset=(PRInt32)aDest.mLength-1;
if(aCount<0)
aCount = aDest.mLength;
if ((aDest.mLength <= 0) || (PRUint32(anOffset)>=aDest.mLength) || (aTarget.mLength==0))
return kNotFound;
if (aCount<=0)
return kNotFound;
const PRUnichar* root = aDest.mUStr;
const PRUnichar* destLast = root+aDest.mLength; //pts to last char in aDest (likely null)
const PRUnichar* rightmost = root+anOffset;
const PRUnichar* min = rightmost-aCount+1;
const PRUnichar* leftmost = (min<root) ? root: min;
while(leftmost<=rightmost) {
//don't forget to divide by delta in next text (bug found by rhp)...
if(aTarget.mLength<=PRUint32(destLast-rightmost)) {
PRInt32 result = Compare2To2(rightmost,aTarget.mUStr,aTarget.mLength,aIgnoreCase);
if(0==result) {
return (rightmost-root);
}
} //if
rightmost--;
} //while
return kNotFound;
}
@ -761,7 +1033,7 @@ PRInt32 nsStr::RFindChar1(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase
}
PRInt32 nsStr::RFindChar2(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eTwoByte, "Must be 2 bytes");
return ::RFindChar2(aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase,aCount);
return ::RFindChar2(aDest.mUStr,aDest.mLength,anOffset,aChar,aIgnoreCase,aCount);
}
@ -775,8 +1047,9 @@ PRInt32 nsStr::RFindChar2(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset) {
//NS_PRECONDITION(aSet.mLength!=1,kCallRFindChar);
PRInt32 nsStr::RFindCharInSet1(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset) {
NS_ASSERTION(aSet.mCharSize == eOneByte, "Must be 1 byte");
PRInt32 index=(0<=anOffset) ? anOffset : aDest.mLength;
PRInt32 thePos;
@ -786,7 +1059,27 @@ PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnor
if(0<aDest.mLength) {
while(--index>=0) {
PRUnichar theChar=GetCharAt(aDest,index);
thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase,aSet.mLength);
thePos=::FindChar1(aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase,aSet.mLength);
if(kNotFound!=thePos)
return index;
} //while
}
return kNotFound;
}
PRInt32 nsStr::RFindCharInSet2(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset) {
NS_ASSERTION(aSet.mCharSize == eTwoByte, "Must be 2 byte");
PRInt32 index=(0<=anOffset) ? anOffset : aDest.mLength;
PRInt32 thePos;
//note that the search is inverted here. We're scanning aDest, one char at a time
//but doing the search against the given set. That's why we use 0 as the offset below.
if(0<aDest.mLength) {
while(--index>=0) {
PRUnichar theChar=GetCharAt(aDest,index);
thePos=::FindChar2(aSet.mUStr,aSet.mLength,0,theChar,aIgnoreCase,aSet.mLength);
if(kNotFound!=thePos)
return index;
} //while
@ -795,7 +1088,7 @@ PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnor
}
// from the start of the old nsStr::StrCompare - now used as helper
// routines for nsStr::Compare1to1 and so forth
// routines for nsStr::Compare1To1 and so forth
static inline PRInt32
GetCompareCount(const PRInt32 aDestLength, const PRInt32 aSourceLength,
PRInt32 aCount)
@ -860,7 +1153,7 @@ PRInt32 nsStr::StrCompare1To2(const nsStr& aDest,const nsStr& aSource,PRInt32 aC
NS_ASSERTION(aSource.mCharSize == eTwoByte, "Must be 2 byte");
if (aCount) {
PRInt32 theCount = GetCompareCount(aDest.mLength, aSource.mLength, aCount);
PRInt32 result = Compare1To2(aDest.mStr, aSource.mStr, theCount, aIgnoreCase);
PRInt32 result = Compare1To2(aDest.mStr, aSource.mUStr, theCount, aIgnoreCase);
result = TranslateCompareResult(aDest.mLength, aSource.mLength, result, aCount);
return result;
}
@ -874,7 +1167,7 @@ PRInt32 nsStr::StrCompare2To1(const nsStr& aDest,const nsStr& aSource,PRInt32 aC
if (aCount) {
PRInt32 theCount = GetCompareCount(aDest.mLength, aSource.mLength, aCount);
PRInt32 result = Compare2To1(aDest.mStr, aSource.mStr, theCount, aIgnoreCase);
PRInt32 result = Compare2To1(aDest.mUStr, aSource.mStr, theCount, aIgnoreCase);
result = TranslateCompareResult(aDest.mLength, aSource.mLength, result, aCount);
return result;
}
@ -888,7 +1181,7 @@ PRInt32 nsStr::StrCompare2To2(const nsStr& aDest,const nsStr& aSource,PRInt32 aC
if (aCount) {
PRInt32 theCount = GetCompareCount(aDest.mLength, aSource.mLength, aCount);
PRInt32 result = Compare2To2(aDest.mStr, aSource.mStr, theCount, aIgnoreCase);
PRInt32 result = Compare2To2(aDest.mUStr, aSource.mUStr, theCount, aIgnoreCase);
result = TranslateCompareResult(aDest.mLength, aSource.mLength, result, aCount);
return result;
}

Просмотреть файл

@ -443,14 +443,27 @@ struct NS_COM nsStr {
* @param anOffset tells us where in the dest string to start searching
* @return the index of the source (substr) in dest, or -1 (kNotFound) if not found.
*/
static PRInt32 FindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset);
static PRInt32 RFindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindSubstr1in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindSubstr1in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindSubstr2in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindSubstr2in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindChar1(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindChar2(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindCharInSet1(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset);
static PRInt32 FindCharInSet2(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset);
static PRInt32 RFindSubstr1in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 RFindSubstr2in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 RFindSubstr1in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 RFindSubstr2in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 RFindChar1(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 RFindChar2(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset);
static PRInt32 RFindCharInSet1(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset);
static PRInt32 RFindCharInSet2(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset);
static void Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 anOffset);

Просмотреть файл

@ -85,29 +85,6 @@ nsCString::nsCString(const char* aCString,PRInt32 aLength) {
Assign(aCString,aLength);
}
#if 0
/**
* This constructor accepts a unicode string
* @update gess 1/4/99
* @param aString is a ptr to a unichar string
* @param aLength tells us how many chars to copy from given aString
*/
nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength) {
Initialize(*this,eOneByte);
AssignWithConversion(aString,aLength);
}
/**
* This constructor works for all other nsSTr derivatives
* @update gess 1/4/99
* @param reference to another nsCString
*/
nsCString::nsCString(const nsStr &aString) {
Initialize(*this,eOneByte);
StrAssign(*this,aString,0,aString.mLength);
}
#endif
/**
* This is our copy constructor
* @update gess 1/4/99
@ -246,34 +223,18 @@ PRBool nsCString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
void
nsCString::StripChar(PRUnichar aChar,PRInt32 anOffset){
if(mLength && (anOffset<PRInt32(mLength))) {
if(eOneByte==mCharSize) {
char* to = mStr + anOffset;
char* from = mStr + anOffset;
char* end = mStr + mLength;
char* to = mStr + anOffset;
char* from = mStr + anOffset;
char* end = mStr + mLength;
while (from < end) {
char theChar = *from++;
if(aChar!=theChar) {
*to++ = theChar;
}
while (from < end) {
char theChar = *from++;
if(aChar!=theChar) {
*to++ = theChar;
}
*to = 0; //add the null
mLength=to - mStr;
}
else {
PRUnichar* to = mUStr + anOffset;
PRUnichar* from = mUStr + anOffset;
PRUnichar* end = mUStr + mLength;
while (from < end) {
PRUnichar theChar = *from++;
if(aChar!=theChar) {
*to++ = theChar;
}
}
*to = 0; //add the null
mLength=to - mUStr;
}
*to = 0; //add the null
mLength=to - mStr;
}
}
@ -392,7 +353,7 @@ nsCString::ReplaceSubstring(const nsCString& aTarget,const nsCString& aNewValue)
}
else {
PRInt32 theIndex=0;
while(kNotFound!=(theIndex=nsStr::FindSubstr(*this,aTarget,PR_FALSE,theIndex,mLength))) {
while(kNotFound!=(theIndex=nsStr::FindSubstr1in1(*this,aTarget,PR_FALSE,theIndex,mLength))) {
if(aNewValue.mLength<aTarget.mLength) {
//Since target is longer than newValue, we should delete a few chars first, then overwrite.
PRInt32 theDelLen=aTarget.mLength-aNewValue.mLength;
@ -651,7 +612,7 @@ void nsCString::AssignWithConversion(const PRUnichar* aString,PRInt32 aCount) {
// If this assertion fires, the caller is probably lying about the length of
// the passed-in string. File a bug on the caller.
#ifdef NS_DEBUG
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
PRInt32 len=nsStr::FindChar2(temp,0,PR_FALSE,0,temp.mLength);
if(kNotFound<len) {
NS_WARNING(kPossibleNull);
}
@ -882,7 +843,7 @@ PRInt32 nsCString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset
nsStr::Initialize(temp,eOneByte);
temp.mLength = nsCRT::strlen(aCString);
temp.mStr=(char*)aCString;
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount);
result=nsStr::FindSubstr1in1(*this,temp,aIgnoreCase,anOffset,aCount);
}
return result;
}
@ -906,7 +867,7 @@ PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOf
nsStr::Initialize(temp,eTwoByte);
temp.mLength = nsCRT::strlen(aString);
temp.mUStr=(PRUnichar*)aString;
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount);
result=nsStr::FindSubstr2in1(*this,temp,aIgnoreCase,anOffset,aCount);
}
return result;
}
@ -921,8 +882,13 @@ PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOf
* @param aCount tells us how many iterations to make starting at the given offset
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 nsCString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount);
PRInt32 nsCString::Find(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::FindSubstr1in1(*this,aString,aIgnoreCase,anOffset,aCount);
return result;
}
PRInt32 nsCString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::FindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount);
return result;
}
@ -938,7 +904,7 @@ PRInt32 nsCString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsCString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset,aCount);
PRInt32 result=nsStr::FindChar1(*this,aChar,aIgnoreCase,anOffset,aCount);
return result;
}
@ -960,7 +926,7 @@ PRInt32 nsCString::FindCharInSet(const char* aCStringSet,PRInt32 anOffset) const
nsStr::Initialize(temp,eOneByte);
temp.mLength=nsCRT::strlen(aCStringSet);
temp.mStr=(char*)aCStringSet;
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
result=nsStr::FindCharInSet1(*this,temp,PR_FALSE,anOffset);
}
return result;
}
@ -983,7 +949,7 @@ PRInt32 nsCString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) c
nsStr::Initialize(temp,eTwoByte);
temp.mLength=nsCRT::strlen(aStringSet);
temp.mStr=(char*)aStringSet;
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
result=nsStr::FindCharInSet2(*this,temp,PR_FALSE,anOffset);
}
return result;
}
@ -997,8 +963,13 @@ PRInt32 nsCString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) c
* @param anOffset -- where in this string to start searching
* @return
*/
PRInt32 nsCString::FindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::FindCharInSet(*this,aSet,PR_FALSE,anOffset);
PRInt32 nsCString::FindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::FindCharInSet1(*this,aSet,PR_FALSE,anOffset);
return result;
}
PRInt32 nsCString::FindCharInSet(const nsString& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::FindCharInSet2(*this,aSet,PR_FALSE,anOffset);
return result;
}
@ -1012,8 +983,13 @@ PRInt32 nsCString::FindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{
* @param aCount tells us how many iterations to make starting at the given offset
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 nsCString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount);
PRInt32 nsCString::RFind(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::RFindSubstr1in1(*this,aString,aIgnoreCase,anOffset,aCount);
return result;
}
PRInt32 nsCString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::RFindSubstr2in1(*this,aString,aIgnoreCase,anOffset,aCount);
return result;
}
@ -1037,7 +1013,7 @@ PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset
nsStr::Initialize(temp,eOneByte);
temp.mLength=nsCRT::strlen(aString);
temp.mStr=(char*)aString;
result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset,aCount);
result=nsStr::RFindSubstr1in1(*this,temp,aIgnoreCase,anOffset,aCount);
}
return result;
}
@ -1074,7 +1050,7 @@ PRInt32 nsCString::RFindCharInSet(const char* aCStringSet,PRInt32 anOffset) cons
nsStr::Initialize(temp,eOneByte);
temp.mLength=nsCRT::strlen(aCStringSet);
temp.mStr=(char*)aCStringSet;
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
result=nsStr::RFindCharInSet1(*this,temp,PR_FALSE,anOffset);
}
return result;
}
@ -1096,7 +1072,7 @@ PRInt32 nsCString::RFindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset)
nsStr::Initialize(temp,eTwoByte);
temp.mLength=nsCRT::strlen(aStringSet);
temp.mUStr=(PRUnichar*)aStringSet;
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
result=nsStr::RFindCharInSet2(*this,temp,PR_FALSE,anOffset);
}
return result;
}
@ -1110,8 +1086,13 @@ PRInt32 nsCString::RFindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset)
* @param anOffset
* @return offset of found char, or -1 (kNotFound)
*/
PRInt32 nsCString::RFindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::RFindCharInSet(*this,aSet,PR_FALSE,anOffset);
PRInt32 nsCString::RFindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::RFindCharInSet1(*this,aSet,PR_FALSE,anOffset);
return result;
}
PRInt32 nsCString::RFindCharInSet(const nsString& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::RFindCharInSet2(*this,aSet,PR_FALSE,anOffset);
return result;
}
@ -1382,40 +1363,6 @@ nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
AddNullTerminator(*this); //this isn't really needed, but it guarantees that folks don't pass string constants.
}
#if 0
/**
* Copy construct from uni-string
* @param aString is a ptr to a unistr
*/
nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() {
Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString,aLength);
}
/**
* construct from an nsStr
* @param
*/
nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString);
}
/**
* construct from a char
* @param
*/
nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
AddNullTerminator(*this);
Append(aChar);
}
#endif
/**
* deconstructor

Просмотреть файл

@ -305,7 +305,8 @@ public:
* @param aCount tells us how many iterations to make starting at the given offset
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
PRInt32 Find(const nsCString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
@ -329,7 +330,8 @@ public:
*/
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=0) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=0) const;
PRInt32 FindCharInSet(const nsCString& aString,PRInt32 anOffset=0) const;
PRInt32 FindCharInSet(const nsString& aString,PRInt32 anOffset=0) const;
/**
@ -340,7 +342,8 @@ public:
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
PRInt32 RFind(const nsCString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
@ -363,7 +366,8 @@ public:
*/
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsCString& aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsString& aString,PRInt32 anOffset=-1) const;

Просмотреть файл

@ -409,7 +409,7 @@ nsString::ReplaceSubstring(const nsString& aTarget,const nsString& aNewValue){
}
else {
PRInt32 theIndex=0;
while(kNotFound!=(theIndex=nsStr::FindSubstr(*this,aTarget,PR_FALSE,theIndex,mLength))) {
while(kNotFound!=(theIndex=nsStr::FindSubstr2in2(*this,aTarget,PR_FALSE,theIndex,mLength))) {
if(aNewValue.mLength<aTarget.mLength) {
//Since target is longer than newValue, we should delete a few chars first, then overwrite.
PRInt32 theDelLen=aTarget.mLength-aNewValue.mLength;
@ -728,7 +728,7 @@ void nsString::AppendWithConversion(const char* aCString,PRInt32 aCount) {
// the passed-in string. File a bug on the caller.
#ifdef NS_DEBUG
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
PRInt32 len=nsStr::FindChar1(temp,0,PR_FALSE,0,temp.mLength);
if(kNotFound<len) {
NS_WARNING(kPossibleNull);
}
@ -837,7 +837,7 @@ void nsString::InsertWithConversion(const char* aCString,PRUint32 anOffset,PRInt
// If this assertion fires, the caller is probably lying about the length of
// the passed-in string. File a bug on the caller.
#ifdef NS_DEBUG
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
PRInt32 len=nsStr::FindChar1(temp,0,PR_FALSE,0,temp.mLength);
if(kNotFound<len) {
NS_WARNING(kPossibleNull);
}
@ -886,7 +886,7 @@ PRInt32 nsString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset,
nsStr::Initialize(temp,eOneByte);
temp.mLength=nsCRT::strlen(aCString);
temp.mStr=(char*)aCString;
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount);
result=nsStr::FindSubstr1in2(*this,temp,aIgnoreCase,anOffset,aCount);
}
return result;
}
@ -910,7 +910,7 @@ PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOff
nsStr::Initialize(temp,eTwoByte);
temp.mLength=nsCRT::strlen(aString);
temp.mUStr=(PRUnichar*)aString;
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount);
result=nsStr::FindSubstr2in2(*this,temp,aIgnoreCase,anOffset,aCount);
}
return result;
}
@ -925,8 +925,8 @@ PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOff
* @param aCount tells us how many iterations to make starting at the given offset
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 nsString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount);
PRInt32 nsString::Find(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::FindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount);
return result;
}
@ -941,23 +941,10 @@ PRInt32 nsString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 nsString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount);
PRInt32 result=nsStr::FindSubstr2in2(*this,aString,aIgnoreCase,anOffset,aCount);
return result;
}
/**
* Search for a given char, starting at given offset
*
* @update gess 3/25/98
* @param aChar
* @return offset of found char, or -1 (kNotFound)
*/
#if 0
PRInt32 nsString::Find(PRUnichar aChar,PRInt32 anOffset,PRBool aIgnoreCase) const{
PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset);
return result;
}
#endif
/**
* Search for a given char, starting at given offset
@ -970,7 +957,7 @@ PRInt32 nsString::Find(PRUnichar aChar,PRInt32 anOffset,PRBool aIgnoreCase) cons
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 nsString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset,aCount);
PRInt32 result=nsStr::FindChar2(*this,aChar,aIgnoreCase,anOffset,aCount);
return result;
}
@ -992,7 +979,7 @@ PRInt32 nsString::FindCharInSet(const char* aCStringSet,PRInt32 anOffset) const{
nsStr::Initialize(temp,eOneByte);
temp.mLength=nsCRT::strlen(aCStringSet);
temp.mStr=(char*)aCStringSet;
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
result=nsStr::FindCharInSet1(*this,temp,PR_FALSE,anOffset);
}
return result;
}
@ -1015,7 +1002,7 @@ PRInt32 nsString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) co
nsStr::Initialize(temp,eTwoByte);
temp.mLength=nsCRT::strlen(aStringSet);
temp.mStr=(char*)aStringSet;
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
result=nsStr::FindCharInSet2(*this,temp,PR_FALSE,anOffset);
}
return result;
}
@ -1029,8 +1016,13 @@ PRInt32 nsString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) co
* @param anOffset -- where in this string to start searching
* @return
*/
PRInt32 nsString::FindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::FindCharInSet(*this,aSet,PR_FALSE,anOffset);
PRInt32 nsString::FindCharInSet(const nsString& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::FindCharInSet2(*this,aSet,PR_FALSE,anOffset);
return result;
}
PRInt32 nsString::FindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::FindCharInSet1(*this,aSet,PR_FALSE,anOffset);
return result;
}
@ -1045,8 +1037,8 @@ PRInt32 nsString::FindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{
* @param aCount tells us how many iterations to make starting at the given offset
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 nsString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount);
PRInt32 nsString::RFind(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::RFindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount);
return result;
}
@ -1061,7 +1053,7 @@ PRInt32 nsString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 nsString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount);
PRInt32 result=nsStr::RFindSubstr2in2(*this,aString,aIgnoreCase,anOffset,aCount);
return result;
}
@ -1084,28 +1076,11 @@ PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,
nsStr::Initialize(temp,eOneByte);
temp.mLength=nsCRT::strlen(aString);
temp.mStr=(char*)aString;
result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset,aCount);
result=nsStr::RFindSubstr1in2(*this,temp,aIgnoreCase,anOffset,aCount);
}
return result;
}
/**
* Reverse search for char
*
* @update gess 3/25/98
* @param achar
* @param aIgnoreCase
* @param anOffset - tells us where to begin the search
* @return offset of substring or -1
*/
#if 0
PRInt32 nsString::RFind(PRUnichar aChar,PRInt32 anOffset,PRBool aIgnoreCase) const{
PRInt32 result=nsStr::RFindChar2(*this,aChar,aIgnoreCase,anOffset);
return result;
}
#endif
/**
* Reverse search for a given char, starting at given offset
*
@ -1137,7 +1112,7 @@ PRInt32 nsString::RFindCharInSet(const char* aCStringSet,PRInt32 anOffset) const
nsStr::Initialize(temp,eOneByte);
temp.mLength=nsCRT::strlen(aCStringSet);
temp.mStr=(char*)aCStringSet;
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
result=nsStr::RFindCharInSet1(*this,temp,PR_FALSE,anOffset);
}
return result;
}
@ -1152,8 +1127,13 @@ PRInt32 nsString::RFindCharInSet(const char* aCStringSet,PRInt32 anOffset) const
* @param anOffset
* @return offset of found char, or -1 (kNotFound)
*/
PRInt32 nsString::RFindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::RFindCharInSet(*this,aSet,PR_FALSE,anOffset);
PRInt32 nsString::RFindCharInSet(const nsString& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::RFindCharInSet2(*this,aSet,PR_FALSE,anOffset);
return result;
}
PRInt32 nsString::RFindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::RFindCharInSet1(*this,aSet,PR_FALSE,anOffset);
return result;
}
@ -1176,7 +1156,7 @@ PRInt32 nsString::RFindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) c
nsStr::Initialize(temp,eTwoByte);
temp.mLength=nsCRT::strlen(aStringSet);
temp.mUStr=(PRUnichar*)aStringSet;
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
result=nsStr::RFindCharInSet2(*this,temp,PR_FALSE,anOffset);
}
return result;
}
@ -1298,7 +1278,7 @@ PRBool nsString::EqualsWithConversion(const PRUnichar* aString,PRBool aIgnoreCas
return result;
}
PRInt32 Compare2To2(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
PRInt32 Compare2To2(const PRUnichar* aStr1,const PRUnichar* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
/**
* Compare this to given atom; note that we compare full strings here.
* The optional length argument just lets us know how long the given string is.
@ -1318,7 +1298,7 @@ PRBool nsString::EqualsAtom(/*FIX: const */nsIAtom* aAtom,PRBool aIgnoreCase) co
const PRUnichar* unicode;
if (aAtom->GetUnicode(&unicode) != NS_OK || unicode == nsnull)
return PR_FALSE;
cmp=Compare2To2((const char*)mUStr,(const char*)unicode, nsCRT::strlen(mUStr), aIgnoreCase);
cmp=Compare2To2(mUStr,unicode, nsCRT::strlen(mUStr), aIgnoreCase);
result=PRBool(0==cmp);
}
@ -1695,29 +1675,6 @@ NS_ConvertUTF8toUCS2::Init( const nsACString& aCString )
NS_ASSERTION(count == mLength, "calculator calculated incorrect length");
}
#if 0
/**
* Copy construct from ascii c-string
* @param aCString is a ptr to a 1-byte cstr
* @param aLength tells us how many chars to copy from aCString
*/
nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() {
Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
AddNullTerminator(*this);
Append(aCString,aLength);
}
/**
* Copy construct from an nsStr
* @param
*/
nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString);
}
#endif
/**
* Default copy constructor
*/

Просмотреть файл

@ -325,7 +325,7 @@ public:
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
PRInt32 Find(const nsCString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
@ -351,7 +351,8 @@ public:
*/
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=0) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=0) const;
PRInt32 FindCharInSet(const nsString& aString,PRInt32 anOffset=0) const;
PRInt32 FindCharInSet(const nsCString& aString,PRInt32 anOffset=0) const;
/**
@ -364,7 +365,7 @@ public:
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
PRInt32 RFind(const nsCString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
@ -389,7 +390,8 @@ public:
*/
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsString& aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsCString& aString,PRInt32 anOffset=-1) const;
/**********************************************************************

Просмотреть файл

@ -528,7 +528,7 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset
* @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length.
* @return index of pos if found, else -1 (kNotFound)
*/
inline PRInt32 FindChar2(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount) {
inline PRInt32 FindChar2(const PRUnichar* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount) {
#ifndef XPCOM_STANDALONE
if(anOffset<0)
@ -541,7 +541,7 @@ inline PRInt32 FindChar2(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset
if(0<aCount) {
const PRUnichar* root = (PRUnichar*)aDest;
const PRUnichar* root = aDest;
const PRUnichar* left = root+anOffset;
const PRUnichar* last = left+aCount;
const PRUnichar* max = root+aDestLength;
@ -647,7 +647,7 @@ inline PRInt32 RFindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffse
* @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length.
* @return index of pos if found, else -1 (kNotFound)
*/
inline PRInt32 RFindChar2(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount) {
inline PRInt32 RFindChar2(const PRUnichar* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount) {
#ifndef XPCOM_STANDALONE
if(anOffset<0)
@ -660,7 +660,7 @@ inline PRInt32 RFindChar2(const char* aDest,PRUint32 aDestLength,PRInt32 anOffse
if(0<aCount) {
const PRUnichar* root = (PRUnichar*)aDest;
const PRUnichar* root = aDest;
const PRUnichar* rightmost = root+anOffset;
const PRUnichar* min = rightmost-aCount+1;
const PRUnichar* leftmost = (min<root) ? root: min;
@ -696,9 +696,6 @@ inline PRInt32 RFindChar2(const char* aDest,PRUint32 aDestLength,PRInt32 anOffse
return kNotFound;
}
typedef PRInt32 (*FindChars)(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount);
FindChars gFindChars[]={&FindChar1,&FindChar2};
//----------------------------------------------------------------------------------------
//
// This set of methods is used to compare one buffer onto another.
@ -717,7 +714,7 @@ FindChars gFindChars[]={&FindChar1,&FindChar2};
* @param aIgnorecase tells us whether to use a case-sensitive comparison
* @return -1,0,1 depending on <,==,>
*/
PRInt32 Compare1To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
static inline PRInt32 Compare1To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
PRInt32 Compare1To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
PRInt32 result=0;
if(aIgnoreCase)
@ -735,13 +732,13 @@ PRInt32 Compare1To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool a
* @param aIgnorecase tells us whether to use a case-sensitive comparison
* @return -1,0,1 depending on <,==,>
*/
PRInt32 Compare2To2(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
PRInt32 Compare2To2(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
PRInt32 Compare2To2(const PRUnichar* aStr1,const PRUnichar* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
PRInt32 Compare2To2(const PRUnichar* aStr1,const PRUnichar* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
PRInt32 result=0;
#ifndef XPCOM_STANDALONE
if(aIgnoreCase && NS_SUCCEEDED(NS_InitCaseConversion()))
gCaseConv->CaseInsensitiveCompare((PRUnichar*)aStr1, (PRUnichar*)aStr2, aCount, &result);
else result=nsCRT::strncmp((PRUnichar*)aStr1,(PRUnichar*)aStr2,aCount);
gCaseConv->CaseInsensitiveCompare(aStr1, aStr2, aCount, &result);
else result=nsCRT::strncmp(aStr1,aStr2,aCount);
#else
NS_ERROR("call not supported in XPCOM_STANDALONE");
#endif
@ -758,10 +755,10 @@ PRInt32 Compare2To2(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool a
* @param aIgnorecase tells us whether to use a case-sensitive comparison
* @return -1,0,1 depending on <,==,>
*/
PRInt32 Compare2To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
PRInt32 Compare2To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
static PRInt32 Compare2To1(const PRUnichar* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
PRInt32 Compare2To1(const PRUnichar* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
#ifndef XPCOM_STANDALONE
PRUnichar* s1 = (PRUnichar*)aStr1;
const PRUnichar* s1 = aStr1;
const char *s2 = aStr2;
if (aIgnoreCase && NS_FAILED(NS_InitCaseConversion()))
@ -804,19 +801,12 @@ PRInt32 Compare2To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool a
* @param aIgnorecase tells us whether to use a case-sensitive comparison
* @return -1,0,1 depending on <,==,>
*/
PRInt32 Compare1To2(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
PRInt32 Compare1To2(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
static inline PRInt32 Compare1To2(const char* aStr1,const PRUnichar* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
PRInt32 Compare1To2(const char* aStr1,const PRUnichar* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
return Compare2To1(aStr2, aStr1, aCount, aIgnoreCase) * -1;
}
typedef PRInt32 (*CompareChars)(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
CompareChars gCompare[2][2]={
{&Compare1To1,&Compare1To2},
{&Compare2To1,&Compare2To2},
};
//----------------------------------------------------------------------------------------
//
// This set of methods is used compress char sequences in a buffer...

Просмотреть файл

@ -502,7 +502,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
if(aEliminateLeading) {
while(++theIndex<=theMax) {
PRUnichar theChar=GetCharAt(aDest,theIndex);
PRInt32 thePos=FindChar1(aSet,theSetLen,0,theChar,PR_FALSE,theSetLen);
PRInt32 thePos=::FindChar1(aSet,theSetLen,0,theChar,PR_FALSE,theSetLen);
if(kNotFound==thePos)
break;
}
@ -523,7 +523,7 @@ void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool a
PRInt32 theNewLen=theIndex;
while(--theIndex>=0) {
PRUnichar theChar=GetCharAt(aDest,theIndex); //read at end now...
PRInt32 thePos=FindChar1(aSet,theSetLen,0,theChar,PR_FALSE,theSetLen);
PRInt32 thePos=::FindChar1(aSet,theSetLen,0,theChar,PR_FALSE,theSetLen);
if(kNotFound<thePos)
theNewLen=theIndex;
else break;
@ -604,39 +604,161 @@ void nsStr::StripChars2(nsStr& aDest,const char* aSet){
* @param aCount tells us how many iterations to make from offset; -1 means the full length of the string
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
PRInt32 nsStr::FindSubstr1in1(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eOneByte, "Must be 1 byte");
NS_ASSERTION(aTarget.mCharSize == eOneByte, "Must be 1 byte");
PRInt32 theMaxPos = aDest.mLength-aTarget.mLength; //this is the last pos that is feasible for starting the search, with given lengths...
if(0<=theMaxPos) {
if (theMaxPos<0) return kNotFound;
if(anOffset<0)
anOffset=0;
if(anOffset<0)
anOffset=0;
if((0<aDest.mLength) && (anOffset<=theMaxPos) && (aTarget.mLength)) {
if((aDest.mLength<=0) || (anOffset>theMaxPos) || (aTarget.mLength==0))
return kNotFound;
if(aCount<0)
aCount = MaxInt(theMaxPos,1);
if(aCount<0)
aCount = MaxInt(theMaxPos,1);
if(0<aCount) {
if (aCount <= 0)
return kNotFound;
PRInt32 aDelta= (aDest.mCharSize == eOneByte) ? 1 : 2;
const char* root = aDest.mStr;
const char* left = root+(anOffset*aDelta);
const char* last = left+((aCount)*aDelta);
const char* max = root+(theMaxPos*aDelta);
const char* right = (last<max) ? last : max;
const char* root = aDest.mStr;
const char* left = root + anOffset;
const char* last = left + aCount;
const char* max = root + theMaxPos;
const char* right = (last<max) ? last : max;
while(left<=right){
PRInt32 cmp=(*gCompare[aDest.mCharSize][aTarget.mCharSize])(left,aTarget.mStr,aTarget.mLength,aIgnoreCase);
if(0==cmp) {
return (left-root)/aDelta;
}
left+=aDelta;
} //while
} //if
while(left<=right){
PRInt32 cmp=Compare1To1(left,aTarget.mStr,aTarget.mLength,aIgnoreCase);
if(0==cmp) {
return (left-root);
}
} //if
left++;
} //while
return kNotFound;
}
PRInt32 nsStr::FindSubstr2in1(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eOneByte, "Must be 1 byte");
NS_ASSERTION(aTarget.mCharSize == eTwoByte, "Must be 2 byte");
PRInt32 theMaxPos = aDest.mLength-aTarget.mLength; //this is the last pos that is feasible for starting the search, with given lengths...
if (theMaxPos<0) return kNotFound;
if(anOffset<0)
anOffset=0;
if((aDest.mLength<=0) || (anOffset>theMaxPos) || (aTarget.mLength==0))
return kNotFound;
if(aCount<0)
aCount = MaxInt(theMaxPos,1);
if (aCount <= 0)
return kNotFound;
const char* root = aDest.mStr;
const char* left = root+anOffset;
const char* last = left+aCount;
const char* max = root+theMaxPos;
const char* right = (last<max) ? last : max;
while(left<=right){
PRInt32 cmp=Compare1To2(left,aTarget.mUStr,aTarget.mLength,aIgnoreCase);
if(0==cmp) {
return (left-root);
}
left++;
} //while
return kNotFound;
}
PRInt32 nsStr::FindSubstr1in2(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eTwoByte, "Must be 2 byte");
NS_ASSERTION(aTarget.mCharSize == eOneByte, "Must be 1 byte");
PRInt32 theMaxPos = aDest.mLength-aTarget.mLength; //this is the last pos that is feasible for starting the search, with given lengths...
if (theMaxPos<0) return kNotFound;
if(anOffset<0)
anOffset=0;
if((aDest.mLength<=0) || (anOffset>theMaxPos) || (aTarget.mLength==0))
return kNotFound;
if(aCount<0)
aCount = MaxInt(theMaxPos,1);
if (aCount <= 0)
return kNotFound;
const PRUnichar* root = aDest.mUStr;
const PRUnichar* left = root+anOffset;
const PRUnichar* last = left+aCount;
const PRUnichar* max = root+theMaxPos;
const PRUnichar* right = (last<max) ? last : max;
while(left<=right){
PRInt32 cmp=Compare2To1(left,aTarget.mStr,aTarget.mLength,aIgnoreCase);
if(0==cmp) {
return (left-root);
}
left++;
} //while
return kNotFound;
}
PRInt32 nsStr::FindSubstr2in2(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eTwoByte, "Must be 2 byte");
NS_ASSERTION(aTarget.mCharSize == eTwoByte, "Must be 2 byte");
PRInt32 theMaxPos = aDest.mLength-aTarget.mLength; //this is the last pos that is feasible for starting the search, with given lengths...
if (theMaxPos<0) return kNotFound;
if(anOffset<0)
anOffset=0;
if((aDest.mLength<=0) || (anOffset>theMaxPos) || (aTarget.mLength==0))
return kNotFound;
if(aCount<0)
aCount = MaxInt(theMaxPos,1);
if (aCount <= 0)
return kNotFound;
const PRUnichar* root = aDest.mUStr;
const PRUnichar* left = root+anOffset;
const PRUnichar* last = left+aCount;
const PRUnichar* max = root+theMaxPos;
const PRUnichar* right = (last<max) ? last : max;
while(left<=right){
PRInt32 cmp=Compare2To2(left,aTarget.mUStr,aTarget.mLength,aIgnoreCase);
if(0==cmp) {
return (left-root);
}
left++;
} //while
return kNotFound;
}
@ -653,8 +775,15 @@ PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnor
* @param aCount tell us how many chars to search from offset
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
return gFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase,aCount);
PRInt32 nsStr::FindChar1(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eOneByte, "Must be 1 byte");
return ::FindChar1(aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase,aCount);
}
PRInt32 nsStr::FindChar2(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eTwoByte, "Must be 2 byte");
return ::FindChar2(aDest.mUStr,aDest.mLength,anOffset,aChar,aIgnoreCase,aCount);
}
@ -668,18 +797,40 @@ PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,P
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset) {
//NS_PRECONDITION(aSet.mLength!=1,kCallFindChar);
PRInt32 nsStr::FindCharInSet1(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset) {
NS_ASSERTION(aSet.mCharSize == eOneByte, "Must be 1 byte");
PRInt32 index=(0<=anOffset) ? anOffset-1 : -1;
PRInt32 thePos;
//Note that the search is inverted here. We're scanning aDest, one char at a time
//but doing the search against the given set. That's why we use 0 as the offset below.
// Note that the search is inverted here. We're scanning aDest,
// one char at a time but doing the search against the given
// set. That's why we use 0 as the offset below.
if((0<aDest.mLength) && (0<aSet.mLength)){
while(++index<(PRInt32)aDest.mLength) {
PRUnichar theChar=GetCharAt(aDest,index);
thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase,aSet.mLength);
thePos=::FindChar1(aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase,aSet.mLength);
if(kNotFound!=thePos)
return index;
} //while
}
return kNotFound;
}
PRInt32 nsStr::FindCharInSet2(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset) {
NS_ASSERTION(aSet.mCharSize == eTwoByte, "Must be 2 byte");
PRInt32 index=(0<=anOffset) ? anOffset-1 : -1;
PRInt32 thePos;
// Note that the search is inverted here. We're scanning aDest,
// one char at a time but doing the search against the given
// set. That's why we use 0 as the offset below.
if((0<aDest.mLength) && (0<aSet.mLength)){
while(++index<(PRInt32)aDest.mLength) {
PRUnichar theChar=GetCharAt(aDest,index);
thePos=::FindChar2(aSet.mUStr,aSet.mLength,0,theChar,aIgnoreCase,aSet.mLength);
if(kNotFound!=thePos)
return index;
} //while
@ -703,41 +854,162 @@ PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnore
* @param aCount tell us how many iterations to perform from offset
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
PRInt32 nsStr::RFindSubstr1in1(const nsStr& aDest,const nsStr& aTarget,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eOneByte, "Must be 1 byte");
NS_ASSERTION(aTarget.mCharSize == eOneByte, "Must be 1 byte");
if(anOffset<0)
anOffset=(PRInt32)aDest.mLength-1;
if(aCount<0)
aCount = aDest.mLength;
if((0<aDest.mLength) &&
((PRUint32)anOffset<aDest.mLength) &&
(aTarget.mLength)) {
if ((aDest.mLength <= 0) || (PRUint32(anOffset)>=aDest.mLength) || (aTarget.mLength==0))
return kNotFound;
if (aCount<=0)
return kNotFound;
const char* root = aDest.mStr;
const char* destLast = root+aDest.mLength; //pts to last char in aDest (likely null)
const char* rightmost = root+anOffset;
const char* min = rightmost-aCount + 1;
const char* leftmost = (min<root) ? root: min;
if(0<aCount) {
while(leftmost<=rightmost) {
//don't forget to divide by delta in next text (bug found by rhp)...
if(aTarget.mLength<=PRUint32(destLast-rightmost)) {
PRInt32 result=Compare1To1(rightmost,aTarget.mStr,aTarget.mLength,aIgnoreCase);
if(0==result) {
return (rightmost-root);
}
} //if
rightmost--;
} //while
PRInt32 aDelta = (aDest.mCharSize == eOneByte) ? 1 : 2;
const char* root = aDest.mStr;
const char* destLast = root+(aDest.mLength*aDelta); //pts to last char in aDest (likely null)
return kNotFound;
}
const char* rightmost = root+(anOffset*aDelta);
const char* min = rightmost-((aCount-1)*aDelta);
PRInt32 nsStr::RFindSubstr2in1(const nsStr& aDest,const nsStr& aTarget,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
const char* leftmost = (min<root) ? root: min;
NS_ASSERTION(aDest.mCharSize == eOneByte, "Must be 1 byte");
NS_ASSERTION(aTarget.mCharSize == eTwoByte, "Must be 2 byte");
if(anOffset<0)
anOffset=(PRInt32)aDest.mLength-1;
while(leftmost<=rightmost) {
//don't forget to divide by delta in next text (bug found by rhp)...
if(aTarget.mLength<=PRUint32((destLast-rightmost)/aDelta)) {
PRInt32 result=(*gCompare[aDest.mCharSize][aTarget.mCharSize])(rightmost,aTarget.mStr,aTarget.mLength,aIgnoreCase);
if(aCount<0)
aCount = aDest.mLength;
if(0==result) {
return (rightmost-root)/aDelta;
}
} //if
rightmost-=aDelta;
} //while
}
}
if ((aDest.mLength <= 0) || (PRUint32(anOffset)>=aDest.mLength) || (aTarget.mLength==0))
return kNotFound;
if (aCount<=0)
return kNotFound;
const char* root = aDest.mStr;
const char* destLast = root+aDest.mLength; //pts to last char in aDest (likely null)
const char* rightmost = root+anOffset;
const char* min = rightmost-aCount+1;
const char* leftmost = (min<root) ? root: min;
while(leftmost<=rightmost) {
//don't forget to divide by delta in next text (bug found by rhp)...
if(aTarget.mLength<=PRUint32(destLast-rightmost)) {
PRInt32 result=Compare1To2(rightmost,aTarget.mUStr,aTarget.mLength,aIgnoreCase);
if(0==result) {
return (rightmost-root);
}
} //if
rightmost--;
} //while
return kNotFound;
}
PRInt32 nsStr::RFindSubstr1in2(const nsStr& aDest,const nsStr& aTarget,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eTwoByte, "Must be 2 byte");
NS_ASSERTION(aTarget.mCharSize == eOneByte, "Must be 1 byte");
if(anOffset<0)
anOffset=(PRInt32)aDest.mLength-1;
if(aCount<0)
aCount = aDest.mLength;
if ((aDest.mLength <= 0) || (PRUint32(anOffset)>=aDest.mLength) || (aTarget.mLength==0))
return kNotFound;
if (aCount<=0)
return kNotFound;
const PRUnichar* root = aDest.mUStr;
const PRUnichar* destLast = root+aDest.mLength; //pts to last char in aDest (likely null)
const PRUnichar* rightmost = root+anOffset;
const PRUnichar* min = rightmost-aCount+1;
const PRUnichar* leftmost = (min<root) ? root: min;
while(leftmost<=rightmost) {
//don't forget to divide by delta in next text (bug found by rhp)...
if(aTarget.mLength<=PRUint32(destLast-rightmost)) {
PRInt32 result = Compare2To1(rightmost,aTarget.mStr,aTarget.mLength,aIgnoreCase);
if(0==result) {
return rightmost-root;
}
} //if
rightmost--;
} //while
return kNotFound;
}
PRInt32 nsStr::RFindSubstr2in2(const nsStr& aDest,const nsStr& aTarget,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eTwoByte, "Must be 2 byte");
NS_ASSERTION(aTarget.mCharSize == eTwoByte, "Must be 2 byte");
if(anOffset<0)
anOffset=(PRInt32)aDest.mLength-1;
if(aCount<0)
aCount = aDest.mLength;
if ((aDest.mLength <= 0) || (PRUint32(anOffset)>=aDest.mLength) || (aTarget.mLength==0))
return kNotFound;
if (aCount<=0)
return kNotFound;
const PRUnichar* root = aDest.mUStr;
const PRUnichar* destLast = root+aDest.mLength; //pts to last char in aDest (likely null)
const PRUnichar* rightmost = root+anOffset;
const PRUnichar* min = rightmost-aCount+1;
const PRUnichar* leftmost = (min<root) ? root: min;
while(leftmost<=rightmost) {
//don't forget to divide by delta in next text (bug found by rhp)...
if(aTarget.mLength<=PRUint32(destLast-rightmost)) {
PRInt32 result = Compare2To2(rightmost,aTarget.mUStr,aTarget.mLength,aIgnoreCase);
if(0==result) {
return (rightmost-root);
}
} //if
rightmost--;
} //while
return kNotFound;
}
@ -761,7 +1033,7 @@ PRInt32 nsStr::RFindChar1(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase
}
PRInt32 nsStr::RFindChar2(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.mCharSize == eTwoByte, "Must be 2 bytes");
return ::RFindChar2(aDest.mStr,aDest.mLength,anOffset,aChar,aIgnoreCase,aCount);
return ::RFindChar2(aDest.mUStr,aDest.mLength,anOffset,aChar,aIgnoreCase,aCount);
}
@ -775,8 +1047,9 @@ PRInt32 nsStr::RFindChar2(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase
* @param anOffset tells us where to start the search
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset) {
//NS_PRECONDITION(aSet.mLength!=1,kCallRFindChar);
PRInt32 nsStr::RFindCharInSet1(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset) {
NS_ASSERTION(aSet.mCharSize == eOneByte, "Must be 1 byte");
PRInt32 index=(0<=anOffset) ? anOffset : aDest.mLength;
PRInt32 thePos;
@ -786,7 +1059,27 @@ PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnor
if(0<aDest.mLength) {
while(--index>=0) {
PRUnichar theChar=GetCharAt(aDest,index);
thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase,aSet.mLength);
thePos=::FindChar1(aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase,aSet.mLength);
if(kNotFound!=thePos)
return index;
} //while
}
return kNotFound;
}
PRInt32 nsStr::RFindCharInSet2(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset) {
NS_ASSERTION(aSet.mCharSize == eTwoByte, "Must be 2 byte");
PRInt32 index=(0<=anOffset) ? anOffset : aDest.mLength;
PRInt32 thePos;
//note that the search is inverted here. We're scanning aDest, one char at a time
//but doing the search against the given set. That's why we use 0 as the offset below.
if(0<aDest.mLength) {
while(--index>=0) {
PRUnichar theChar=GetCharAt(aDest,index);
thePos=::FindChar2(aSet.mUStr,aSet.mLength,0,theChar,aIgnoreCase,aSet.mLength);
if(kNotFound!=thePos)
return index;
} //while
@ -795,7 +1088,7 @@ PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnor
}
// from the start of the old nsStr::StrCompare - now used as helper
// routines for nsStr::Compare1to1 and so forth
// routines for nsStr::Compare1To1 and so forth
static inline PRInt32
GetCompareCount(const PRInt32 aDestLength, const PRInt32 aSourceLength,
PRInt32 aCount)
@ -860,7 +1153,7 @@ PRInt32 nsStr::StrCompare1To2(const nsStr& aDest,const nsStr& aSource,PRInt32 aC
NS_ASSERTION(aSource.mCharSize == eTwoByte, "Must be 2 byte");
if (aCount) {
PRInt32 theCount = GetCompareCount(aDest.mLength, aSource.mLength, aCount);
PRInt32 result = Compare1To2(aDest.mStr, aSource.mStr, theCount, aIgnoreCase);
PRInt32 result = Compare1To2(aDest.mStr, aSource.mUStr, theCount, aIgnoreCase);
result = TranslateCompareResult(aDest.mLength, aSource.mLength, result, aCount);
return result;
}
@ -874,7 +1167,7 @@ PRInt32 nsStr::StrCompare2To1(const nsStr& aDest,const nsStr& aSource,PRInt32 aC
if (aCount) {
PRInt32 theCount = GetCompareCount(aDest.mLength, aSource.mLength, aCount);
PRInt32 result = Compare2To1(aDest.mStr, aSource.mStr, theCount, aIgnoreCase);
PRInt32 result = Compare2To1(aDest.mUStr, aSource.mStr, theCount, aIgnoreCase);
result = TranslateCompareResult(aDest.mLength, aSource.mLength, result, aCount);
return result;
}
@ -888,7 +1181,7 @@ PRInt32 nsStr::StrCompare2To2(const nsStr& aDest,const nsStr& aSource,PRInt32 aC
if (aCount) {
PRInt32 theCount = GetCompareCount(aDest.mLength, aSource.mLength, aCount);
PRInt32 result = Compare2To2(aDest.mStr, aSource.mStr, theCount, aIgnoreCase);
PRInt32 result = Compare2To2(aDest.mUStr, aSource.mUStr, theCount, aIgnoreCase);
result = TranslateCompareResult(aDest.mLength, aSource.mLength, result, aCount);
return result;
}

Просмотреть файл

@ -443,14 +443,27 @@ struct NS_COM nsStr {
* @param anOffset tells us where in the dest string to start searching
* @return the index of the source (substr) in dest, or -1 (kNotFound) if not found.
*/
static PRInt32 FindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset);
static PRInt32 RFindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindSubstr1in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindSubstr1in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindSubstr2in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindSubstr2in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindChar1(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindChar2(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 FindCharInSet1(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset);
static PRInt32 FindCharInSet2(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset);
static PRInt32 RFindSubstr1in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 RFindSubstr2in1(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 RFindSubstr1in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 RFindSubstr2in2(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 RFindChar1(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 RFindChar2(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount);
static PRInt32 RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset);
static PRInt32 RFindCharInSet1(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset);
static PRInt32 RFindCharInSet2(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset);
static void Overwrite(nsStr& aDest,const nsStr& aSource,PRInt32 anOffset);

Просмотреть файл

@ -85,29 +85,6 @@ nsCString::nsCString(const char* aCString,PRInt32 aLength) {
Assign(aCString,aLength);
}
#if 0
/**
* This constructor accepts a unicode string
* @update gess 1/4/99
* @param aString is a ptr to a unichar string
* @param aLength tells us how many chars to copy from given aString
*/
nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength) {
Initialize(*this,eOneByte);
AssignWithConversion(aString,aLength);
}
/**
* This constructor works for all other nsSTr derivatives
* @update gess 1/4/99
* @param reference to another nsCString
*/
nsCString::nsCString(const nsStr &aString) {
Initialize(*this,eOneByte);
StrAssign(*this,aString,0,aString.mLength);
}
#endif
/**
* This is our copy constructor
* @update gess 1/4/99
@ -246,34 +223,18 @@ PRBool nsCString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
void
nsCString::StripChar(PRUnichar aChar,PRInt32 anOffset){
if(mLength && (anOffset<PRInt32(mLength))) {
if(eOneByte==mCharSize) {
char* to = mStr + anOffset;
char* from = mStr + anOffset;
char* end = mStr + mLength;
char* to = mStr + anOffset;
char* from = mStr + anOffset;
char* end = mStr + mLength;
while (from < end) {
char theChar = *from++;
if(aChar!=theChar) {
*to++ = theChar;
}
while (from < end) {
char theChar = *from++;
if(aChar!=theChar) {
*to++ = theChar;
}
*to = 0; //add the null
mLength=to - mStr;
}
else {
PRUnichar* to = mUStr + anOffset;
PRUnichar* from = mUStr + anOffset;
PRUnichar* end = mUStr + mLength;
while (from < end) {
PRUnichar theChar = *from++;
if(aChar!=theChar) {
*to++ = theChar;
}
}
*to = 0; //add the null
mLength=to - mUStr;
}
*to = 0; //add the null
mLength=to - mStr;
}
}
@ -392,7 +353,7 @@ nsCString::ReplaceSubstring(const nsCString& aTarget,const nsCString& aNewValue)
}
else {
PRInt32 theIndex=0;
while(kNotFound!=(theIndex=nsStr::FindSubstr(*this,aTarget,PR_FALSE,theIndex,mLength))) {
while(kNotFound!=(theIndex=nsStr::FindSubstr1in1(*this,aTarget,PR_FALSE,theIndex,mLength))) {
if(aNewValue.mLength<aTarget.mLength) {
//Since target is longer than newValue, we should delete a few chars first, then overwrite.
PRInt32 theDelLen=aTarget.mLength-aNewValue.mLength;
@ -651,7 +612,7 @@ void nsCString::AssignWithConversion(const PRUnichar* aString,PRInt32 aCount) {
// If this assertion fires, the caller is probably lying about the length of
// the passed-in string. File a bug on the caller.
#ifdef NS_DEBUG
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
PRInt32 len=nsStr::FindChar2(temp,0,PR_FALSE,0,temp.mLength);
if(kNotFound<len) {
NS_WARNING(kPossibleNull);
}
@ -882,7 +843,7 @@ PRInt32 nsCString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset
nsStr::Initialize(temp,eOneByte);
temp.mLength = nsCRT::strlen(aCString);
temp.mStr=(char*)aCString;
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount);
result=nsStr::FindSubstr1in1(*this,temp,aIgnoreCase,anOffset,aCount);
}
return result;
}
@ -906,7 +867,7 @@ PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOf
nsStr::Initialize(temp,eTwoByte);
temp.mLength = nsCRT::strlen(aString);
temp.mUStr=(PRUnichar*)aString;
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount);
result=nsStr::FindSubstr2in1(*this,temp,aIgnoreCase,anOffset,aCount);
}
return result;
}
@ -921,8 +882,13 @@ PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOf
* @param aCount tells us how many iterations to make starting at the given offset
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 nsCString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount);
PRInt32 nsCString::Find(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::FindSubstr1in1(*this,aString,aIgnoreCase,anOffset,aCount);
return result;
}
PRInt32 nsCString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::FindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount);
return result;
}
@ -938,7 +904,7 @@ PRInt32 nsCString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset
* @return index in aDest where member of aSet occurs, or -1 if not found
*/
PRInt32 nsCString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset,aCount);
PRInt32 result=nsStr::FindChar1(*this,aChar,aIgnoreCase,anOffset,aCount);
return result;
}
@ -960,7 +926,7 @@ PRInt32 nsCString::FindCharInSet(const char* aCStringSet,PRInt32 anOffset) const
nsStr::Initialize(temp,eOneByte);
temp.mLength=nsCRT::strlen(aCStringSet);
temp.mStr=(char*)aCStringSet;
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
result=nsStr::FindCharInSet1(*this,temp,PR_FALSE,anOffset);
}
return result;
}
@ -983,7 +949,7 @@ PRInt32 nsCString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) c
nsStr::Initialize(temp,eTwoByte);
temp.mLength=nsCRT::strlen(aStringSet);
temp.mStr=(char*)aStringSet;
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
result=nsStr::FindCharInSet2(*this,temp,PR_FALSE,anOffset);
}
return result;
}
@ -997,8 +963,13 @@ PRInt32 nsCString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) c
* @param anOffset -- where in this string to start searching
* @return
*/
PRInt32 nsCString::FindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::FindCharInSet(*this,aSet,PR_FALSE,anOffset);
PRInt32 nsCString::FindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::FindCharInSet1(*this,aSet,PR_FALSE,anOffset);
return result;
}
PRInt32 nsCString::FindCharInSet(const nsString& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::FindCharInSet2(*this,aSet,PR_FALSE,anOffset);
return result;
}
@ -1012,8 +983,13 @@ PRInt32 nsCString::FindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{
* @param aCount tells us how many iterations to make starting at the given offset
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 nsCString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount);
PRInt32 nsCString::RFind(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::RFindSubstr1in1(*this,aString,aIgnoreCase,anOffset,aCount);
return result;
}
PRInt32 nsCString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::RFindSubstr2in1(*this,aString,aIgnoreCase,anOffset,aCount);
return result;
}
@ -1037,7 +1013,7 @@ PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset
nsStr::Initialize(temp,eOneByte);
temp.mLength=nsCRT::strlen(aString);
temp.mStr=(char*)aString;
result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset,aCount);
result=nsStr::RFindSubstr1in1(*this,temp,aIgnoreCase,anOffset,aCount);
}
return result;
}
@ -1074,7 +1050,7 @@ PRInt32 nsCString::RFindCharInSet(const char* aCStringSet,PRInt32 anOffset) cons
nsStr::Initialize(temp,eOneByte);
temp.mLength=nsCRT::strlen(aCStringSet);
temp.mStr=(char*)aCStringSet;
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
result=nsStr::RFindCharInSet1(*this,temp,PR_FALSE,anOffset);
}
return result;
}
@ -1096,7 +1072,7 @@ PRInt32 nsCString::RFindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset)
nsStr::Initialize(temp,eTwoByte);
temp.mLength=nsCRT::strlen(aStringSet);
temp.mUStr=(PRUnichar*)aStringSet;
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
result=nsStr::RFindCharInSet2(*this,temp,PR_FALSE,anOffset);
}
return result;
}
@ -1110,8 +1086,13 @@ PRInt32 nsCString::RFindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset)
* @param anOffset
* @return offset of found char, or -1 (kNotFound)
*/
PRInt32 nsCString::RFindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::RFindCharInSet(*this,aSet,PR_FALSE,anOffset);
PRInt32 nsCString::RFindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::RFindCharInSet1(*this,aSet,PR_FALSE,anOffset);
return result;
}
PRInt32 nsCString::RFindCharInSet(const nsString& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::RFindCharInSet2(*this,aSet,PR_FALSE,anOffset);
return result;
}
@ -1382,40 +1363,6 @@ nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
AddNullTerminator(*this); //this isn't really needed, but it guarantees that folks don't pass string constants.
}
#if 0
/**
* Copy construct from uni-string
* @param aString is a ptr to a unistr
*/
nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() {
Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString,aLength);
}
/**
* construct from an nsStr
* @param
*/
nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString);
}
/**
* construct from a char
* @param
*/
nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
AddNullTerminator(*this);
Append(aChar);
}
#endif
/**
* deconstructor

Просмотреть файл

@ -305,7 +305,8 @@ public:
* @param aCount tells us how many iterations to make starting at the given offset
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
PRInt32 Find(const nsCString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
@ -329,7 +330,8 @@ public:
*/
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=0) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=0) const;
PRInt32 FindCharInSet(const nsCString& aString,PRInt32 anOffset=0) const;
PRInt32 FindCharInSet(const nsString& aString,PRInt32 anOffset=0) const;
/**
@ -340,7 +342,8 @@ public:
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
PRInt32 RFind(const nsCString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
@ -363,7 +366,8 @@ public:
*/
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsCString& aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsString& aString,PRInt32 anOffset=-1) const;

Просмотреть файл

@ -409,7 +409,7 @@ nsString::ReplaceSubstring(const nsString& aTarget,const nsString& aNewValue){
}
else {
PRInt32 theIndex=0;
while(kNotFound!=(theIndex=nsStr::FindSubstr(*this,aTarget,PR_FALSE,theIndex,mLength))) {
while(kNotFound!=(theIndex=nsStr::FindSubstr2in2(*this,aTarget,PR_FALSE,theIndex,mLength))) {
if(aNewValue.mLength<aTarget.mLength) {
//Since target is longer than newValue, we should delete a few chars first, then overwrite.
PRInt32 theDelLen=aTarget.mLength-aNewValue.mLength;
@ -728,7 +728,7 @@ void nsString::AppendWithConversion(const char* aCString,PRInt32 aCount) {
// the passed-in string. File a bug on the caller.
#ifdef NS_DEBUG
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
PRInt32 len=nsStr::FindChar1(temp,0,PR_FALSE,0,temp.mLength);
if(kNotFound<len) {
NS_WARNING(kPossibleNull);
}
@ -837,7 +837,7 @@ void nsString::InsertWithConversion(const char* aCString,PRUint32 anOffset,PRInt
// If this assertion fires, the caller is probably lying about the length of
// the passed-in string. File a bug on the caller.
#ifdef NS_DEBUG
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
PRInt32 len=nsStr::FindChar1(temp,0,PR_FALSE,0,temp.mLength);
if(kNotFound<len) {
NS_WARNING(kPossibleNull);
}
@ -886,7 +886,7 @@ PRInt32 nsString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset,
nsStr::Initialize(temp,eOneByte);
temp.mLength=nsCRT::strlen(aCString);
temp.mStr=(char*)aCString;
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount);
result=nsStr::FindSubstr1in2(*this,temp,aIgnoreCase,anOffset,aCount);
}
return result;
}
@ -910,7 +910,7 @@ PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOff
nsStr::Initialize(temp,eTwoByte);
temp.mLength=nsCRT::strlen(aString);
temp.mUStr=(PRUnichar*)aString;
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount);
result=nsStr::FindSubstr2in2(*this,temp,aIgnoreCase,anOffset,aCount);
}
return result;
}
@ -925,8 +925,8 @@ PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOff
* @param aCount tells us how many iterations to make starting at the given offset
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 nsString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount);
PRInt32 nsString::Find(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::FindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount);
return result;
}
@ -941,23 +941,10 @@ PRInt32 nsString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 nsString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount);
PRInt32 result=nsStr::FindSubstr2in2(*this,aString,aIgnoreCase,anOffset,aCount);
return result;
}
/**
* Search for a given char, starting at given offset
*
* @update gess 3/25/98
* @param aChar
* @return offset of found char, or -1 (kNotFound)
*/
#if 0
PRInt32 nsString::Find(PRUnichar aChar,PRInt32 anOffset,PRBool aIgnoreCase) const{
PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset);
return result;
}
#endif
/**
* Search for a given char, starting at given offset
@ -970,7 +957,7 @@ PRInt32 nsString::Find(PRUnichar aChar,PRInt32 anOffset,PRBool aIgnoreCase) cons
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 nsString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset,aCount);
PRInt32 result=nsStr::FindChar2(*this,aChar,aIgnoreCase,anOffset,aCount);
return result;
}
@ -992,7 +979,7 @@ PRInt32 nsString::FindCharInSet(const char* aCStringSet,PRInt32 anOffset) const{
nsStr::Initialize(temp,eOneByte);
temp.mLength=nsCRT::strlen(aCStringSet);
temp.mStr=(char*)aCStringSet;
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
result=nsStr::FindCharInSet1(*this,temp,PR_FALSE,anOffset);
}
return result;
}
@ -1015,7 +1002,7 @@ PRInt32 nsString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) co
nsStr::Initialize(temp,eTwoByte);
temp.mLength=nsCRT::strlen(aStringSet);
temp.mStr=(char*)aStringSet;
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
result=nsStr::FindCharInSet2(*this,temp,PR_FALSE,anOffset);
}
return result;
}
@ -1029,8 +1016,13 @@ PRInt32 nsString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) co
* @param anOffset -- where in this string to start searching
* @return
*/
PRInt32 nsString::FindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::FindCharInSet(*this,aSet,PR_FALSE,anOffset);
PRInt32 nsString::FindCharInSet(const nsString& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::FindCharInSet2(*this,aSet,PR_FALSE,anOffset);
return result;
}
PRInt32 nsString::FindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::FindCharInSet1(*this,aSet,PR_FALSE,anOffset);
return result;
}
@ -1045,8 +1037,8 @@ PRInt32 nsString::FindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{
* @param aCount tells us how many iterations to make starting at the given offset
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 nsString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount);
PRInt32 nsString::RFind(const nsCString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::RFindSubstr1in2(*this,aString,aIgnoreCase,anOffset,aCount);
return result;
}
@ -1061,7 +1053,7 @@ PRInt32 nsString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 nsString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount);
PRInt32 result=nsStr::RFindSubstr2in2(*this,aString,aIgnoreCase,anOffset,aCount);
return result;
}
@ -1084,28 +1076,11 @@ PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,
nsStr::Initialize(temp,eOneByte);
temp.mLength=nsCRT::strlen(aString);
temp.mStr=(char*)aString;
result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset,aCount);
result=nsStr::RFindSubstr1in2(*this,temp,aIgnoreCase,anOffset,aCount);
}
return result;
}
/**
* Reverse search for char
*
* @update gess 3/25/98
* @param achar
* @param aIgnoreCase
* @param anOffset - tells us where to begin the search
* @return offset of substring or -1
*/
#if 0
PRInt32 nsString::RFind(PRUnichar aChar,PRInt32 anOffset,PRBool aIgnoreCase) const{
PRInt32 result=nsStr::RFindChar2(*this,aChar,aIgnoreCase,anOffset);
return result;
}
#endif
/**
* Reverse search for a given char, starting at given offset
*
@ -1137,7 +1112,7 @@ PRInt32 nsString::RFindCharInSet(const char* aCStringSet,PRInt32 anOffset) const
nsStr::Initialize(temp,eOneByte);
temp.mLength=nsCRT::strlen(aCStringSet);
temp.mStr=(char*)aCStringSet;
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
result=nsStr::RFindCharInSet1(*this,temp,PR_FALSE,anOffset);
}
return result;
}
@ -1152,8 +1127,13 @@ PRInt32 nsString::RFindCharInSet(const char* aCStringSet,PRInt32 anOffset) const
* @param anOffset
* @return offset of found char, or -1 (kNotFound)
*/
PRInt32 nsString::RFindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::RFindCharInSet(*this,aSet,PR_FALSE,anOffset);
PRInt32 nsString::RFindCharInSet(const nsString& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::RFindCharInSet2(*this,aSet,PR_FALSE,anOffset);
return result;
}
PRInt32 nsString::RFindCharInSet(const nsCString& aSet,PRInt32 anOffset) const{
PRInt32 result=nsStr::RFindCharInSet1(*this,aSet,PR_FALSE,anOffset);
return result;
}
@ -1176,7 +1156,7 @@ PRInt32 nsString::RFindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) c
nsStr::Initialize(temp,eTwoByte);
temp.mLength=nsCRT::strlen(aStringSet);
temp.mUStr=(PRUnichar*)aStringSet;
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
result=nsStr::RFindCharInSet2(*this,temp,PR_FALSE,anOffset);
}
return result;
}
@ -1298,7 +1278,7 @@ PRBool nsString::EqualsWithConversion(const PRUnichar* aString,PRBool aIgnoreCas
return result;
}
PRInt32 Compare2To2(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
PRInt32 Compare2To2(const PRUnichar* aStr1,const PRUnichar* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
/**
* Compare this to given atom; note that we compare full strings here.
* The optional length argument just lets us know how long the given string is.
@ -1318,7 +1298,7 @@ PRBool nsString::EqualsAtom(/*FIX: const */nsIAtom* aAtom,PRBool aIgnoreCase) co
const PRUnichar* unicode;
if (aAtom->GetUnicode(&unicode) != NS_OK || unicode == nsnull)
return PR_FALSE;
cmp=Compare2To2((const char*)mUStr,(const char*)unicode, nsCRT::strlen(mUStr), aIgnoreCase);
cmp=Compare2To2(mUStr,unicode, nsCRT::strlen(mUStr), aIgnoreCase);
result=PRBool(0==cmp);
}
@ -1695,29 +1675,6 @@ NS_ConvertUTF8toUCS2::Init( const nsACString& aCString )
NS_ASSERTION(count == mLength, "calculator calculated incorrect length");
}
#if 0
/**
* Copy construct from ascii c-string
* @param aCString is a ptr to a 1-byte cstr
* @param aLength tells us how many chars to copy from aCString
*/
nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() {
Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
AddNullTerminator(*this);
Append(aCString,aLength);
}
/**
* Copy construct from an nsStr
* @param
*/
nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
AddNullTerminator(*this);
Append(aString);
}
#endif
/**
* Default copy constructor
*/

Просмотреть файл

@ -325,7 +325,7 @@ public:
* @return offset in string, or -1 (kNotFound)
*/
PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
PRInt32 Find(const nsCString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
@ -351,7 +351,8 @@ public:
*/
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const;
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=0) const;
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=0) const;
PRInt32 FindCharInSet(const nsString& aString,PRInt32 anOffset=0) const;
PRInt32 FindCharInSet(const nsCString& aString,PRInt32 anOffset=0) const;
/**
@ -364,7 +365,7 @@ public:
*/
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
PRInt32 RFind(const nsCString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
@ -389,7 +390,8 @@ public:
*/
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsString& aString,PRInt32 anOffset=-1) const;
PRInt32 RFindCharInSet(const nsCString& aString,PRInt32 anOffset=-1) const;
/**********************************************************************