Bug 162017: step 2: remove aIgnoreCase from FindChar1. r=peterv, sr=dbaron

This commit is contained in:
jaggernaut%netscape.com 2002-09-17 22:49:00 +00:00
Родитель 604e6568d6
Коммит 7001d81cad
4 изменённых файлов: 36 добавлений и 74 удалений

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

@ -390,11 +390,10 @@ CopyChars gCopyChars[2][2]={
* @param aDestLength is the size (in char-units, not bytes) of the buffer * @param aDestLength is the size (in char-units, not bytes) of the buffer
* @param anOffset is the start pos to begin searching * @param anOffset is the start pos to begin searching
* @param aChar is the target character we're looking for * @param aChar is the target character we're looking for
* @param aIgnorecase tells us whether to use a case sensitive search
* @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length. * @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) * @return index of pos if found, else -1 (kNotFound)
*/ */
inline PRInt32 FindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount) { inline PRInt32 FindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRInt32 aCount) {
if(anOffset < 0) if(anOffset < 0)
anOffset=0; anOffset=0;
@ -414,30 +413,15 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset
const char* max = aDest+aDestLength; const char* max = aDest+aDestLength;
const char* end = (last<max) ? last : max; const char* end = (last<max) ? last : max;
if(aIgnoreCase) { PRInt32 theMax = end-left;
// safe because aChar < 256 if(0<theMax) {
char theChar=toupper(char(aChar));
unsigned char theChar = (unsigned char) aChar;
const char* result=(const char*)memchr(left, (int)theChar, theMax);
if(result)
return result-aDest;
while(left<end){
if(toupper(*left)==theChar)
return left-aDest;
++left;
}
}
else {
PRInt32 theMax = end-left;
if(0<theMax) {
unsigned char theChar = (unsigned char) aChar;
const char* result=(const char*)memchr(left, (int)theChar, theMax);
if(result)
return result-aDest;
}
} }
} }
} }
@ -454,7 +438,6 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset
* @param aDestLength is the size (in char-units, not bytes) of the buffer * @param aDestLength is the size (in char-units, not bytes) of the buffer
* @param anOffset is the start pos to begin searching * @param anOffset is the start pos to begin searching
* @param aChar is the target character we're looking for * @param aChar is the target character we're looking for
* @param aIgnorecase tells us whether to use a case sensitive search
* @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length. * @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) * @return index of pos if found, else -1 (kNotFound)
*/ */
@ -498,7 +481,6 @@ inline PRInt32 FindChar2(const PRUnichar* aDest,PRUint32 aDestLength,PRInt32 anO
* @param aDestLength is the size (in char-units, not bytes) of the buffer * @param aDestLength is the size (in char-units, not bytes) of the buffer
* @param anOffset is the start pos to begin searching * @param anOffset is the start pos to begin searching
* @param aChar is the target character we're looking for * @param aChar is the target character we're looking for
* @param aIgnorecase tells us whether to use a case sensitive search
* @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length. * @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) * @return index of pos if found, else -1 (kNotFound)
*/ */
@ -545,7 +527,6 @@ inline PRInt32 RFindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffse
* @param aDestLength is the size (in char-units, not bytes) of the buffer * @param aDestLength is the size (in char-units, not bytes) of the buffer
* @param anOffset is the start pos to begin searching * @param anOffset is the start pos to begin searching
* @param aChar is the target character we're looking for * @param aChar is the target character we're looking for
* @param aIgnorecase tells us whether to use a case sensitive search
* @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length. * @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) * @return index of pos if found, else -1 (kNotFound)
*/ */
@ -749,10 +730,10 @@ PRInt32 CompressChars1(char* aString,PRUint32 aLength,const char* aSet){
*to++=theChar; //always copy this char... *to++=theChar; //always copy this char...
if((kNotFound!=FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen))){ if((kNotFound!=FindChar1(aSet,aSetLen,0,theChar,aSetLen))){
while (from < end) { while (from < end) {
theChar = *from++; theChar = *from++;
if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen)){ if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,aSetLen)){
*to++ = theChar; *to++ = theChar;
break; break;
} }
@ -794,10 +775,10 @@ PRInt32 CompressChars2(PRUnichar* aString,PRUint32 aLength,const char* aSet){
*to++=theChar; //always copy this char... *to++=theChar; //always copy this char...
if((theChar<256) && (kNotFound!=FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen))){ if((theChar<256) && (kNotFound!=FindChar1(aSet,aSetLen,0,theChar,aSetLen))){
while (from < end) { while (from < end) {
theChar = *from++; theChar = *from++;
if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen)){ if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,aSetLen)){
*to++ = theChar; *to++ = theChar;
break; break;
} }
@ -831,7 +812,7 @@ PRInt32 StripChars1(char* aString,PRUint32 aLength,const char* aSet){
PRUint32 aSetLen=strlen(aSet); PRUint32 aSetLen=strlen(aSet);
while (++from < end) { while (++from < end) {
char theChar = *from; char theChar = *from;
if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen)){ if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,aSetLen)){
*to++ = theChar; *to++ = theChar;
} }
} }
@ -866,7 +847,7 @@ PRInt32 StripChars2(PRUnichar* aString,PRUint32 aLength,const char* aSet){
//Note the test for ascii range below. If you have a real unicode char, //Note the test for ascii range below. If you have a real unicode char,
//and you're searching for chars in the (given) ascii string, there's no //and you're searching for chars in the (given) ascii string, there's no
//point in doing the real search since it's out of the ascii range. //point in doing the real search since it's out of the ascii range.
if((255<theChar) || (kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen))){ if((255<theChar) || (kNotFound==FindChar1(aSet,aSetLen,0,theChar,aSetLen))){
*to++ = theChar; *to++ = theChar;
} }
} }

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

@ -469,7 +469,7 @@ void nsStrPrivate::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,P
if(aEliminateLeading) { if(aEliminateLeading) {
while(++theIndex<=theMax) { while(++theIndex<=theMax) {
PRUnichar theChar=aDest.GetCharAt(theIndex); PRUnichar theChar=aDest.GetCharAt(theIndex);
PRInt32 thePos=::FindChar1(aSet,theSetLen,0,theChar,PR_FALSE,theSetLen); PRInt32 thePos=::FindChar1(aSet,theSetLen,0,theChar,theSetLen);
if(kNotFound==thePos) if(kNotFound==thePos)
break; break;
} }
@ -490,7 +490,7 @@ void nsStrPrivate::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,P
PRInt32 theNewLen=theIndex; PRInt32 theNewLen=theIndex;
while(--theIndex>=0) { while(--theIndex>=0) {
PRUnichar theChar=aDest.GetCharAt(theIndex); //read at end now... PRUnichar theChar=aDest.GetCharAt(theIndex); //read at end now...
PRInt32 thePos=::FindChar1(aSet,theSetLen,0,theChar,PR_FALSE,theSetLen); PRInt32 thePos=::FindChar1(aSet,theSetLen,0,theChar,theSetLen);
if(kNotFound<thePos) if(kNotFound<thePos)
theNewLen=theIndex; theNewLen=theIndex;
else break; else break;
@ -706,7 +706,7 @@ PRInt32 nsStrPrivate::FindSubstr2in2(const nsStr& aDest,const nsStr& aTarget, PR
PRInt32 nsStrPrivate::FindChar1(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount) { PRInt32 nsStrPrivate::FindChar1(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.GetCharSize() == eOneByte, "Must be 1 byte"); NS_ASSERTION(aDest.GetCharSize() == eOneByte, "Must be 1 byte");
return ::FindChar1(aDest.mStr,aDest.mLength,anOffset,aChar,PR_FALSE,aCount); return ::FindChar1(aDest.mStr,aDest.mLength,anOffset,aChar,aCount);
} }
PRInt32 nsStrPrivate::FindChar2(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount) { PRInt32 nsStrPrivate::FindChar2(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount) {

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

@ -390,11 +390,10 @@ CopyChars gCopyChars[2][2]={
* @param aDestLength is the size (in char-units, not bytes) of the buffer * @param aDestLength is the size (in char-units, not bytes) of the buffer
* @param anOffset is the start pos to begin searching * @param anOffset is the start pos to begin searching
* @param aChar is the target character we're looking for * @param aChar is the target character we're looking for
* @param aIgnorecase tells us whether to use a case sensitive search
* @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length. * @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) * @return index of pos if found, else -1 (kNotFound)
*/ */
inline PRInt32 FindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount) { inline PRInt32 FindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRInt32 aCount) {
if(anOffset < 0) if(anOffset < 0)
anOffset=0; anOffset=0;
@ -414,30 +413,15 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset
const char* max = aDest+aDestLength; const char* max = aDest+aDestLength;
const char* end = (last<max) ? last : max; const char* end = (last<max) ? last : max;
if(aIgnoreCase) { PRInt32 theMax = end-left;
// safe because aChar < 256 if(0<theMax) {
char theChar=toupper(char(aChar));
unsigned char theChar = (unsigned char) aChar;
const char* result=(const char*)memchr(left, (int)theChar, theMax);
if(result)
return result-aDest;
while(left<end){
if(toupper(*left)==theChar)
return left-aDest;
++left;
}
}
else {
PRInt32 theMax = end-left;
if(0<theMax) {
unsigned char theChar = (unsigned char) aChar;
const char* result=(const char*)memchr(left, (int)theChar, theMax);
if(result)
return result-aDest;
}
} }
} }
} }
@ -454,7 +438,6 @@ inline PRInt32 FindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset
* @param aDestLength is the size (in char-units, not bytes) of the buffer * @param aDestLength is the size (in char-units, not bytes) of the buffer
* @param anOffset is the start pos to begin searching * @param anOffset is the start pos to begin searching
* @param aChar is the target character we're looking for * @param aChar is the target character we're looking for
* @param aIgnorecase tells us whether to use a case sensitive search
* @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length. * @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) * @return index of pos if found, else -1 (kNotFound)
*/ */
@ -498,7 +481,6 @@ inline PRInt32 FindChar2(const PRUnichar* aDest,PRUint32 aDestLength,PRInt32 anO
* @param aDestLength is the size (in char-units, not bytes) of the buffer * @param aDestLength is the size (in char-units, not bytes) of the buffer
* @param anOffset is the start pos to begin searching * @param anOffset is the start pos to begin searching
* @param aChar is the target character we're looking for * @param aChar is the target character we're looking for
* @param aIgnorecase tells us whether to use a case sensitive search
* @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length. * @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) * @return index of pos if found, else -1 (kNotFound)
*/ */
@ -545,7 +527,6 @@ inline PRInt32 RFindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffse
* @param aDestLength is the size (in char-units, not bytes) of the buffer * @param aDestLength is the size (in char-units, not bytes) of the buffer
* @param anOffset is the start pos to begin searching * @param anOffset is the start pos to begin searching
* @param aChar is the target character we're looking for * @param aChar is the target character we're looking for
* @param aIgnorecase tells us whether to use a case sensitive search
* @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length. * @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) * @return index of pos if found, else -1 (kNotFound)
*/ */
@ -749,10 +730,10 @@ PRInt32 CompressChars1(char* aString,PRUint32 aLength,const char* aSet){
*to++=theChar; //always copy this char... *to++=theChar; //always copy this char...
if((kNotFound!=FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen))){ if((kNotFound!=FindChar1(aSet,aSetLen,0,theChar,aSetLen))){
while (from < end) { while (from < end) {
theChar = *from++; theChar = *from++;
if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen)){ if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,aSetLen)){
*to++ = theChar; *to++ = theChar;
break; break;
} }
@ -794,10 +775,10 @@ PRInt32 CompressChars2(PRUnichar* aString,PRUint32 aLength,const char* aSet){
*to++=theChar; //always copy this char... *to++=theChar; //always copy this char...
if((theChar<256) && (kNotFound!=FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen))){ if((theChar<256) && (kNotFound!=FindChar1(aSet,aSetLen,0,theChar,aSetLen))){
while (from < end) { while (from < end) {
theChar = *from++; theChar = *from++;
if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen)){ if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,aSetLen)){
*to++ = theChar; *to++ = theChar;
break; break;
} }
@ -831,7 +812,7 @@ PRInt32 StripChars1(char* aString,PRUint32 aLength,const char* aSet){
PRUint32 aSetLen=strlen(aSet); PRUint32 aSetLen=strlen(aSet);
while (++from < end) { while (++from < end) {
char theChar = *from; char theChar = *from;
if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen)){ if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,aSetLen)){
*to++ = theChar; *to++ = theChar;
} }
} }
@ -866,7 +847,7 @@ PRInt32 StripChars2(PRUnichar* aString,PRUint32 aLength,const char* aSet){
//Note the test for ascii range below. If you have a real unicode char, //Note the test for ascii range below. If you have a real unicode char,
//and you're searching for chars in the (given) ascii string, there's no //and you're searching for chars in the (given) ascii string, there's no
//point in doing the real search since it's out of the ascii range. //point in doing the real search since it's out of the ascii range.
if((255<theChar) || (kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen))){ if((255<theChar) || (kNotFound==FindChar1(aSet,aSetLen,0,theChar,aSetLen))){
*to++ = theChar; *to++ = theChar;
} }
} }

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

@ -469,7 +469,7 @@ void nsStrPrivate::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,P
if(aEliminateLeading) { if(aEliminateLeading) {
while(++theIndex<=theMax) { while(++theIndex<=theMax) {
PRUnichar theChar=aDest.GetCharAt(theIndex); PRUnichar theChar=aDest.GetCharAt(theIndex);
PRInt32 thePos=::FindChar1(aSet,theSetLen,0,theChar,PR_FALSE,theSetLen); PRInt32 thePos=::FindChar1(aSet,theSetLen,0,theChar,theSetLen);
if(kNotFound==thePos) if(kNotFound==thePos)
break; break;
} }
@ -490,7 +490,7 @@ void nsStrPrivate::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,P
PRInt32 theNewLen=theIndex; PRInt32 theNewLen=theIndex;
while(--theIndex>=0) { while(--theIndex>=0) {
PRUnichar theChar=aDest.GetCharAt(theIndex); //read at end now... PRUnichar theChar=aDest.GetCharAt(theIndex); //read at end now...
PRInt32 thePos=::FindChar1(aSet,theSetLen,0,theChar,PR_FALSE,theSetLen); PRInt32 thePos=::FindChar1(aSet,theSetLen,0,theChar,theSetLen);
if(kNotFound<thePos) if(kNotFound<thePos)
theNewLen=theIndex; theNewLen=theIndex;
else break; else break;
@ -706,7 +706,7 @@ PRInt32 nsStrPrivate::FindSubstr2in2(const nsStr& aDest,const nsStr& aTarget, PR
PRInt32 nsStrPrivate::FindChar1(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount) { PRInt32 nsStrPrivate::FindChar1(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount) {
NS_ASSERTION(aDest.GetCharSize() == eOneByte, "Must be 1 byte"); NS_ASSERTION(aDest.GetCharSize() == eOneByte, "Must be 1 byte");
return ::FindChar1(aDest.mStr,aDest.mLength,anOffset,aChar,PR_FALSE,aCount); return ::FindChar1(aDest.mStr,aDest.mLength,anOffset,aChar,aCount);
} }
PRInt32 nsStrPrivate::FindChar2(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount) { PRInt32 nsStrPrivate::FindChar2(const nsStr& aDest,PRUnichar aChar, PRInt32 anOffset,PRInt32 aCount) {