Switch variants of |nsScanner::ReadUntil| to accept new string classes for |aTermSet| and to use |FindCharInReadable| instead of |nsString::FindChar|. Remove (function-scope) |static nsString|s from nsHTMLTokens.cpp. r=harishd@netscape.com sr=vidur@netscape.com b=65431

This commit is contained in:
dbaron%fas.harvard.edu 2001-04-11 02:28:17 +00:00
parent 96d16a52dc
commit 9c4a46ab61
6 changed files with 150 additions and 126 deletions

View File

@ -527,7 +527,11 @@ PRInt32 CTextToken::GetTextLength(void) {
* @return error result
*/
nsresult CTextToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aMode) {
static nsString theTerminals = NS_ConvertASCIItoUCS2("\n\r&<"); // XXXjag
static const PRUnichar theTerminalsChars[] =
{ PRUnichar('\n'), PRUnichar('\r'), PRUnichar('&'), PRUnichar('<'),
PRUnichar(0) };
const nsLocalString theTerminals(theTerminalsChars,
sizeof(theTerminalsChars)/sizeof(theTerminalsChars[0]) - 1);
nsresult result=NS_OK;
PRBool done=PR_FALSE;
nsReadingIterator<PRUnichar> origin, start, end;
@ -897,7 +901,12 @@ PRInt32 CMarkupDeclToken::GetTokenType(void) {
* @return error result
*/
nsresult CMarkupDeclToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aMode) {
static nsString theTerminals = NS_ConvertASCIItoUCS2("\n\r'\">"); // XXXjag
static const PRUnichar theTerminalsChars[] =
{ PRUnichar('\n'), PRUnichar('\r'), PRUnichar('\''), PRUnichar('"'),
PRUnichar('>'),
PRUnichar(0) };
const nsLocalString theTerminals(theTerminalsChars,
sizeof(theTerminalsChars)/sizeof(theTerminalsChars[0]) - 1);
nsresult result=NS_OK;
PRBool done=PR_FALSE;
PRUnichar quote=0;
@ -1520,7 +1529,12 @@ nsresult ConsumeQuotedString(PRUnichar aChar,nsString& aString,nsScanner& aScann
*/
static
nsresult ConsumeAttributeValueText(PRUnichar,nsString& aString,nsScanner& aScanner){
static nsString theTerminals = NS_ConvertASCIItoUCS2("\b\t\n\r >"); // XXXjag
static const PRUnichar theTerminalsChars[] =
{ PRUnichar('\b'), PRUnichar('\t'), PRUnichar('\n'), PRUnichar('\r'),
PRUnichar(' '), PRUnichar('>'),
PRUnichar(0) };
const nsLocalString theTerminals(theTerminalsChars,
sizeof(theTerminalsChars)/sizeof(theTerminalsChars[0]) - 1);
nsresult result=aScanner.ReadUntil(aString,theTerminals,PR_FALSE);
//Let's force quotes if either the first or last char is quoted.
@ -1569,7 +1583,12 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 a
}
else {
//If you're here, handle an unquoted key.
static nsAutoString theTerminals = NS_ConvertASCIItoUCS2("\b\t\n\r \"=>"); // XXXjag
static const PRUnichar theTerminalsChars[] =
{ PRUnichar('\b'), PRUnichar('\t'), PRUnichar('\n'), PRUnichar('\r'),
PRUnichar(' '), PRUnichar('"'), PRUnichar('='), PRUnichar('>'),
PRUnichar(0) };
const nsLocalString theTerminals(theTerminalsChars,
sizeof(theTerminalsChars)/sizeof(theTerminalsChars[0]) - 1);
result=aScanner.ReadUntil(start,end,theTerminals,PR_FALSE);
}
if (!aRetain) {

View File

@ -1155,17 +1155,17 @@ nsresult nsScanner::ReadWhile(nsString& aString,
* the set of INVALID characters
* @return error code
*/
nsresult nsScanner::ReadUntil(nsString& aString,
nsString& aTerminalSet,
PRBool addTerminal){
nsresult nsScanner::ReadUntil(nsAWritableString& aString,
const nsAReadableString& aTerminalSet,
PRBool addTerminal)
{
if (!mSlidingBuffer) {
return kEOF;
}
PRUnichar theChar=0;
nsresult result=Peek(theChar);
nsReadingIterator<PRUnichar> origin, current, end;
nsReadingIterator<PRUnichar> origin, current, end, setstart, setend;
origin = mCurrentPosition;
current = origin;
@ -1175,8 +1175,9 @@ nsresult nsScanner::ReadUntil(nsString& aString,
theChar=*current;
if(theChar) {
PRInt32 pos=aTerminalSet.FindChar(theChar);
if(kNotFound!=pos) {
aTerminalSet.BeginReading(setstart);
aTerminalSet.EndReading(setend);
if (FindCharInReadable(theChar, setstart, setend)) {
if(addTerminal)
current++;
AppendUnicodeTo(origin, current, aString);
@ -1208,10 +1209,10 @@ nsresult nsScanner::ReadUntil(nsString& aString,
* the set of INVALID characters
* @return error code
*/
nsresult nsScanner::ReadUntil(nsString& aString,
nsCString& aTerminalSet,
PRBool addTerminal){
nsresult nsScanner::ReadUntil(nsAWritableString& aString,
const nsAReadableCString& aTerminalSet,
PRBool addTerminal)
{
if (!mSlidingBuffer) {
return kEOF;
}
@ -1219,6 +1220,7 @@ nsresult nsScanner::ReadUntil(nsString& aString,
PRUnichar theChar=0;
nsresult result=Peek(theChar);
nsReadingIterator<PRUnichar> origin, current, end;
nsReadingIterator<char> setstart, setend;
origin = mCurrentPosition;
current = origin;
@ -1228,8 +1230,9 @@ nsresult nsScanner::ReadUntil(nsString& aString,
theChar=*current;
if(theChar) {
PRInt32 pos=aTerminalSet.FindChar(theChar);
if(kNotFound!=pos) {
aTerminalSet.BeginReading(setstart);
aTerminalSet.EndReading(setend);
if (FindCharInReadable(theChar, setstart, setend)) {
if(addTerminal)
current++;
AppendUnicodeTo(origin, current, aString);
@ -1252,16 +1255,16 @@ nsresult nsScanner::ReadUntil(nsString& aString,
nsresult nsScanner::ReadUntil(nsReadingIterator<PRUnichar>& aStart,
nsReadingIterator<PRUnichar>& aEnd,
nsString& aTerminalSet,
PRBool addTerminal){
const nsAReadableString& aTerminalSet,
PRBool addTerminal)
{
if (!mSlidingBuffer) {
return kEOF;
}
PRUnichar theChar=0;
nsresult result=Peek(theChar);
nsReadingIterator<PRUnichar> origin, current, end;
nsReadingIterator<PRUnichar> origin, current, end, setstart, setend;
origin = mCurrentPosition;
current = origin;
@ -1271,8 +1274,9 @@ nsresult nsScanner::ReadUntil(nsReadingIterator<PRUnichar>& aStart,
theChar=*current;
if(theChar) {
PRInt32 pos=aTerminalSet.FindChar(theChar);
if(kNotFound!=pos) {
aTerminalSet.BeginReading(setstart);
aTerminalSet.EndReading(setend);
if (FindCharInReadable(theChar, setstart, setend)) {
if(addTerminal)
current++;
aStart = origin;
@ -1293,38 +1297,6 @@ nsresult nsScanner::ReadUntil(nsReadingIterator<PRUnichar>& aStart,
return result;
}
/**
* Consume characters until you encounter one contained in given
* input set.
*
* @update gess 3/25/98
* @param aString will contain the result of this method
* @param aTerminalSet is an ordered string that contains
* the set of INVALID characters
* @return error code
*/
nsresult nsScanner::ReadUntil(nsString& aString,
const char* aTerminalSet,
PRBool addTerminal)
{
if (!mSlidingBuffer) {
return kEOF;
}
nsresult result=NS_OK;
if(aTerminalSet) {
PRInt32 len=nsCRT::strlen(aTerminalSet);
if(0<len) {
CBufDescriptor buf(aTerminalSet,PR_TRUE,len+1,len);
nsCAutoString theSet(buf);
result=ReadUntil(aString,theSet,addTerminal);
} //if
}//if
return result;
}
/**
* Consumes chars until you see the given terminalChar
*
@ -1332,9 +1304,10 @@ nsresult nsScanner::ReadUntil(nsString& aString,
* @param
* @return error code
*/
nsresult nsScanner::ReadUntil(nsString& aString,
PRUnichar aTerminalChar,
PRBool addTerminal){
nsresult nsScanner::ReadUntil(nsAWritableString& aString,
PRUnichar aTerminalChar,
PRBool addTerminal)
{
if (!mSlidingBuffer) {
return kEOF;
}

View File

@ -200,7 +200,9 @@ class nsScanner {
* @param addTerminal tells us whether to append terminal to aString
* @return error code
*/
nsresult ReadUntil(nsString& aString,PRUnichar aTerminal,PRBool addTerminal);
nsresult ReadUntil(nsAWritableString& aString,
PRUnichar aTerminal,
PRBool addTerminal);
/**
* Consume characters until you find one contained in given
@ -212,10 +214,28 @@ class nsScanner {
* @param addTerminal tells us whether to append terminal to aString
* @return error code
*/
nsresult ReadUntil(nsString& aString,nsString& aTermSet,PRBool addTerminal);
nsresult ReadUntil(nsString& aString,nsCString& aTermSet,PRBool addTerminal);
nsresult ReadUntil(nsString& aString,const char* aTermSet,PRBool addTerminal);
nsresult ReadUntil(nsReadingIterator<PRUnichar>& aStart, nsReadingIterator<PRUnichar>& aEnd, nsString& aTerminalSet,PRBool addTerminal);
nsresult ReadUntil(nsAWritableString& aString,
const nsAReadableString& aTermSet,
PRBool addTerminal);
nsresult ReadUntil(nsAWritableString& aString,
const nsAReadableCString& aTermSet,
PRBool addTerminal);
nsresult ReadUntil(nsAWritableString& aString,
const char* aTerminalSet,
PRBool addTerminal)
{
return ReadUntil(aString,
NS_STATIC_CAST(const nsAReadableCString&,
nsLiteralCString(aTerminalSet)),
addTerminal);
}
nsresult ReadUntil(nsReadingIterator<PRUnichar>& aStart,
nsReadingIterator<PRUnichar>& aEnd,
const nsAReadableString& aTerminalSet,
PRBool addTerminal);
/**

View File

@ -527,7 +527,11 @@ PRInt32 CTextToken::GetTextLength(void) {
* @return error result
*/
nsresult CTextToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aMode) {
static nsString theTerminals = NS_ConvertASCIItoUCS2("\n\r&<"); // XXXjag
static const PRUnichar theTerminalsChars[] =
{ PRUnichar('\n'), PRUnichar('\r'), PRUnichar('&'), PRUnichar('<'),
PRUnichar(0) };
const nsLocalString theTerminals(theTerminalsChars,
sizeof(theTerminalsChars)/sizeof(theTerminalsChars[0]) - 1);
nsresult result=NS_OK;
PRBool done=PR_FALSE;
nsReadingIterator<PRUnichar> origin, start, end;
@ -897,7 +901,12 @@ PRInt32 CMarkupDeclToken::GetTokenType(void) {
* @return error result
*/
nsresult CMarkupDeclToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aMode) {
static nsString theTerminals = NS_ConvertASCIItoUCS2("\n\r'\">"); // XXXjag
static const PRUnichar theTerminalsChars[] =
{ PRUnichar('\n'), PRUnichar('\r'), PRUnichar('\''), PRUnichar('"'),
PRUnichar('>'),
PRUnichar(0) };
const nsLocalString theTerminals(theTerminalsChars,
sizeof(theTerminalsChars)/sizeof(theTerminalsChars[0]) - 1);
nsresult result=NS_OK;
PRBool done=PR_FALSE;
PRUnichar quote=0;
@ -1520,7 +1529,12 @@ nsresult ConsumeQuotedString(PRUnichar aChar,nsString& aString,nsScanner& aScann
*/
static
nsresult ConsumeAttributeValueText(PRUnichar,nsString& aString,nsScanner& aScanner){
static nsString theTerminals = NS_ConvertASCIItoUCS2("\b\t\n\r >"); // XXXjag
static const PRUnichar theTerminalsChars[] =
{ PRUnichar('\b'), PRUnichar('\t'), PRUnichar('\n'), PRUnichar('\r'),
PRUnichar(' '), PRUnichar('>'),
PRUnichar(0) };
const nsLocalString theTerminals(theTerminalsChars,
sizeof(theTerminalsChars)/sizeof(theTerminalsChars[0]) - 1);
nsresult result=aScanner.ReadUntil(aString,theTerminals,PR_FALSE);
//Let's force quotes if either the first or last char is quoted.
@ -1569,7 +1583,12 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 a
}
else {
//If you're here, handle an unquoted key.
static nsAutoString theTerminals = NS_ConvertASCIItoUCS2("\b\t\n\r \"=>"); // XXXjag
static const PRUnichar theTerminalsChars[] =
{ PRUnichar('\b'), PRUnichar('\t'), PRUnichar('\n'), PRUnichar('\r'),
PRUnichar(' '), PRUnichar('"'), PRUnichar('='), PRUnichar('>'),
PRUnichar(0) };
const nsLocalString theTerminals(theTerminalsChars,
sizeof(theTerminalsChars)/sizeof(theTerminalsChars[0]) - 1);
result=aScanner.ReadUntil(start,end,theTerminals,PR_FALSE);
}
if (!aRetain) {

View File

@ -1155,17 +1155,17 @@ nsresult nsScanner::ReadWhile(nsString& aString,
* the set of INVALID characters
* @return error code
*/
nsresult nsScanner::ReadUntil(nsString& aString,
nsString& aTerminalSet,
PRBool addTerminal){
nsresult nsScanner::ReadUntil(nsAWritableString& aString,
const nsAReadableString& aTerminalSet,
PRBool addTerminal)
{
if (!mSlidingBuffer) {
return kEOF;
}
PRUnichar theChar=0;
nsresult result=Peek(theChar);
nsReadingIterator<PRUnichar> origin, current, end;
nsReadingIterator<PRUnichar> origin, current, end, setstart, setend;
origin = mCurrentPosition;
current = origin;
@ -1175,8 +1175,9 @@ nsresult nsScanner::ReadUntil(nsString& aString,
theChar=*current;
if(theChar) {
PRInt32 pos=aTerminalSet.FindChar(theChar);
if(kNotFound!=pos) {
aTerminalSet.BeginReading(setstart);
aTerminalSet.EndReading(setend);
if (FindCharInReadable(theChar, setstart, setend)) {
if(addTerminal)
current++;
AppendUnicodeTo(origin, current, aString);
@ -1208,10 +1209,10 @@ nsresult nsScanner::ReadUntil(nsString& aString,
* the set of INVALID characters
* @return error code
*/
nsresult nsScanner::ReadUntil(nsString& aString,
nsCString& aTerminalSet,
PRBool addTerminal){
nsresult nsScanner::ReadUntil(nsAWritableString& aString,
const nsAReadableCString& aTerminalSet,
PRBool addTerminal)
{
if (!mSlidingBuffer) {
return kEOF;
}
@ -1219,6 +1220,7 @@ nsresult nsScanner::ReadUntil(nsString& aString,
PRUnichar theChar=0;
nsresult result=Peek(theChar);
nsReadingIterator<PRUnichar> origin, current, end;
nsReadingIterator<char> setstart, setend;
origin = mCurrentPosition;
current = origin;
@ -1228,8 +1230,9 @@ nsresult nsScanner::ReadUntil(nsString& aString,
theChar=*current;
if(theChar) {
PRInt32 pos=aTerminalSet.FindChar(theChar);
if(kNotFound!=pos) {
aTerminalSet.BeginReading(setstart);
aTerminalSet.EndReading(setend);
if (FindCharInReadable(theChar, setstart, setend)) {
if(addTerminal)
current++;
AppendUnicodeTo(origin, current, aString);
@ -1252,16 +1255,16 @@ nsresult nsScanner::ReadUntil(nsString& aString,
nsresult nsScanner::ReadUntil(nsReadingIterator<PRUnichar>& aStart,
nsReadingIterator<PRUnichar>& aEnd,
nsString& aTerminalSet,
PRBool addTerminal){
const nsAReadableString& aTerminalSet,
PRBool addTerminal)
{
if (!mSlidingBuffer) {
return kEOF;
}
PRUnichar theChar=0;
nsresult result=Peek(theChar);
nsReadingIterator<PRUnichar> origin, current, end;
nsReadingIterator<PRUnichar> origin, current, end, setstart, setend;
origin = mCurrentPosition;
current = origin;
@ -1271,8 +1274,9 @@ nsresult nsScanner::ReadUntil(nsReadingIterator<PRUnichar>& aStart,
theChar=*current;
if(theChar) {
PRInt32 pos=aTerminalSet.FindChar(theChar);
if(kNotFound!=pos) {
aTerminalSet.BeginReading(setstart);
aTerminalSet.EndReading(setend);
if (FindCharInReadable(theChar, setstart, setend)) {
if(addTerminal)
current++;
aStart = origin;
@ -1293,38 +1297,6 @@ nsresult nsScanner::ReadUntil(nsReadingIterator<PRUnichar>& aStart,
return result;
}
/**
* Consume characters until you encounter one contained in given
* input set.
*
* @update gess 3/25/98
* @param aString will contain the result of this method
* @param aTerminalSet is an ordered string that contains
* the set of INVALID characters
* @return error code
*/
nsresult nsScanner::ReadUntil(nsString& aString,
const char* aTerminalSet,
PRBool addTerminal)
{
if (!mSlidingBuffer) {
return kEOF;
}
nsresult result=NS_OK;
if(aTerminalSet) {
PRInt32 len=nsCRT::strlen(aTerminalSet);
if(0<len) {
CBufDescriptor buf(aTerminalSet,PR_TRUE,len+1,len);
nsCAutoString theSet(buf);
result=ReadUntil(aString,theSet,addTerminal);
} //if
}//if
return result;
}
/**
* Consumes chars until you see the given terminalChar
*
@ -1332,9 +1304,10 @@ nsresult nsScanner::ReadUntil(nsString& aString,
* @param
* @return error code
*/
nsresult nsScanner::ReadUntil(nsString& aString,
PRUnichar aTerminalChar,
PRBool addTerminal){
nsresult nsScanner::ReadUntil(nsAWritableString& aString,
PRUnichar aTerminalChar,
PRBool addTerminal)
{
if (!mSlidingBuffer) {
return kEOF;
}

View File

@ -200,7 +200,9 @@ class nsScanner {
* @param addTerminal tells us whether to append terminal to aString
* @return error code
*/
nsresult ReadUntil(nsString& aString,PRUnichar aTerminal,PRBool addTerminal);
nsresult ReadUntil(nsAWritableString& aString,
PRUnichar aTerminal,
PRBool addTerminal);
/**
* Consume characters until you find one contained in given
@ -212,10 +214,28 @@ class nsScanner {
* @param addTerminal tells us whether to append terminal to aString
* @return error code
*/
nsresult ReadUntil(nsString& aString,nsString& aTermSet,PRBool addTerminal);
nsresult ReadUntil(nsString& aString,nsCString& aTermSet,PRBool addTerminal);
nsresult ReadUntil(nsString& aString,const char* aTermSet,PRBool addTerminal);
nsresult ReadUntil(nsReadingIterator<PRUnichar>& aStart, nsReadingIterator<PRUnichar>& aEnd, nsString& aTerminalSet,PRBool addTerminal);
nsresult ReadUntil(nsAWritableString& aString,
const nsAReadableString& aTermSet,
PRBool addTerminal);
nsresult ReadUntil(nsAWritableString& aString,
const nsAReadableCString& aTermSet,
PRBool addTerminal);
nsresult ReadUntil(nsAWritableString& aString,
const char* aTerminalSet,
PRBool addTerminal)
{
return ReadUntil(aString,
NS_STATIC_CAST(const nsAReadableCString&,
nsLiteralCString(aTerminalSet)),
addTerminal);
}
nsresult ReadUntil(nsReadingIterator<PRUnichar>& aStart,
nsReadingIterator<PRUnichar>& aEnd,
const nsAReadableString& aTerminalSet,
PRBool addTerminal);
/**