Bug 483971 - nsCSSScanner: cleanup of EatWhiteSpace and removal of EatNewline. r+sr=dbaron

This commit is contained in:
Alfred Kayser 2009-04-09 08:46:26 +02:00
parent 0e9fefb7d8
commit 894d7a59e8
2 changed files with 16 additions and 92 deletions

View File

@ -669,39 +669,19 @@ nsCSSScanner::LookAhead(PRUnichar aChar)
return PR_FALSE; return PR_FALSE;
} }
PRBool void
nsCSSScanner::EatWhiteSpace() nsCSSScanner::EatWhiteSpace()
{ {
PRBool eaten = PR_FALSE;
for (;;) { for (;;) {
PRInt32 ch = Read(); PRInt32 ch = Read();
if (ch < 0) { if (ch < 0) {
break; break;
} }
if ((ch == ' ') || (ch == '\n') || (ch == '\t')) { if ((ch != ' ') && (ch != '\n') && (ch != '\t')) {
eaten = PR_TRUE;
continue;
}
Pushback(ch); Pushback(ch);
break; break;
} }
return eaten;
}
PRBool
nsCSSScanner::EatNewline()
{
PRInt32 ch = Read();
if (ch < 0) {
return PR_FALSE;
} }
PRBool eaten = PR_FALSE;
if (ch == '\n') {
eaten = PR_TRUE;
} else {
Pushback(ch);
}
return eaten;
} }
PRBool PRBool
@ -760,7 +740,7 @@ nsCSSScanner::Next(nsCSSToken& aToken)
if (IsWhitespace(ch)) { if (IsWhitespace(ch)) {
aToken.mType = eCSSToken_WhiteSpace; aToken.mType = eCSSToken_WhiteSpace;
aToken.mIdent.Assign(PRUnichar(ch)); aToken.mIdent.Assign(PRUnichar(ch));
(void) EatWhiteSpace(); EatWhiteSpace();
return PR_TRUE; return PR_TRUE;
} }
if (ch == '/') { if (ch == '/') {
@ -855,7 +835,7 @@ nsCSSScanner::NextURL(nsCSSToken& aToken)
if (IsWhitespace(ch)) { if (IsWhitespace(ch)) {
aToken.mType = eCSSToken_WhiteSpace; aToken.mType = eCSSToken_WhiteSpace;
aToken.mIdent.Assign(PRUnichar(ch)); aToken.mIdent.Assign(PRUnichar(ch));
(void) EatWhiteSpace(); EatWhiteSpace();
return PR_TRUE; return PR_TRUE;
} }
@ -890,7 +870,7 @@ nsCSSScanner::NextURL(nsCSSToken& aToken)
ok = PR_FALSE; ok = PR_FALSE;
} else if (IsWhitespace(ch)) { } else if (IsWhitespace(ch)) {
// Whitespace is allowed at the end of the URL // Whitespace is allowed at the end of the URL
(void) EatWhiteSpace(); EatWhiteSpace();
if (LookAhead(')')) { if (LookAhead(')')) {
Pushback(')'); // leave the closing symbol Pushback(')'); // leave the closing symbol
// done! // done!
@ -979,18 +959,14 @@ nsCSSScanner::ParseAndAppendEscape(nsString& aOutput)
Pushback(ch); Pushback(ch);
} }
return; return;
} else { }
// "Any character except a hexidecimal digit can be escaped to // "Any character except a hexidecimal digit can be escaped to
// remove its special meaning by putting a backslash in front" // remove its special meaning by putting a backslash in front"
// -- CSS1 spec section 7.1 // -- CSS1 spec section 7.1
if (!EatNewline()) { // skip escaped newline ch = Read(); // Consume the escaped character
(void) Read(); if ((ch > 0) && (ch != '\n')) {
if (ch > 0) {
aOutput.Append(ch); aOutput.Append(ch);
} }
}
return;
}
} }
/** /**
@ -1193,53 +1169,6 @@ nsCSSScanner::SkipCComment()
return PR_FALSE; return PR_FALSE;
} }
#if 0
PRBool
nsCSSScanner::ParseCComment(nsCSSToken& aToken)
{
nsString& ident = aToken.mIdent;
for (;;) {
PRInt32 ch = Read();
if (ch < 0) break;
if (ch == '*') {
if (LookAhead('/')) {
ident.Append(PRUnichar(ch));
ident.Append(PRUnichar('/'));
break;
}
}
#ifdef COLLECT_WHITESPACE
ident.Append(PRUnichar(ch));
#endif
}
aToken.mType = eCSSToken_WhiteSpace;
return PR_TRUE;
}
#endif
#if 0
PRBool
nsCSSScanner::ParseEOLComment(nsCSSToken& aToken)
{
nsString& ident = aToken.mIdent;
ident.SetLength(0);
for (;;) {
if (EatNewline()) {
break;
}
PRInt32 ch = Read();
if (ch < 0) {
break;
}
#ifdef COLLECT_WHITESPACE
ident.Append(PRUnichar(ch));
#endif
}
aToken.mType = eCSSToken_WhiteSpace;
return PR_TRUE;
}
#endif // 0
PRBool PRBool
nsCSSScanner::ParseString(PRInt32 aStop, nsCSSToken& aToken) nsCSSScanner::ParseString(PRInt32 aStop, nsCSSToken& aToken)
{ {

View File

@ -211,8 +211,7 @@ protected:
PRInt32 Read(); PRInt32 Read();
PRInt32 Peek(); PRInt32 Peek();
PRBool LookAhead(PRUnichar aChar); PRBool LookAhead(PRUnichar aChar);
PRBool EatWhiteSpace(); void EatWhiteSpace();
PRBool EatNewline();
void ParseAndAppendEscape(nsString& aOutput); void ParseAndAppendEscape(nsString& aOutput);
PRBool ParseIdent(PRInt32 aChar, nsCSSToken& aResult); PRBool ParseIdent(PRInt32 aChar, nsCSSToken& aResult);
@ -220,10 +219,6 @@ protected:
PRBool ParseNumber(PRInt32 aChar, nsCSSToken& aResult); PRBool ParseNumber(PRInt32 aChar, nsCSSToken& aResult);
PRBool ParseRef(PRInt32 aChar, nsCSSToken& aResult); PRBool ParseRef(PRInt32 aChar, nsCSSToken& aResult);
PRBool ParseString(PRInt32 aChar, nsCSSToken& aResult); PRBool ParseString(PRInt32 aChar, nsCSSToken& aResult);
#if 0
PRBool ParseCComment(nsCSSToken& aResult);
PRBool ParseEOLComment(nsCSSToken& aResult);
#endif
PRBool SkipCComment(); PRBool SkipCComment();
PRBool GatherIdent(PRInt32 aChar, nsString& aIdent); PRBool GatherIdent(PRInt32 aChar, nsString& aIdent);