Merging backout of rev 3c687f3d4ff4

This commit is contained in:
Boris Zbarsky 2009-04-09 11:59:02 -04:00
commit b19d95cbc6
2 changed files with 92 additions and 16 deletions

View File

@ -669,19 +669,39 @@ nsCSSScanner::LookAhead(PRUnichar aChar)
return PR_FALSE; return PR_FALSE;
} }
void PRBool
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')) {
Pushback(ch); eaten = PR_TRUE;
break; continue;
} }
Pushback(ch);
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
@ -740,7 +760,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));
EatWhiteSpace(); (void) EatWhiteSpace();
return PR_TRUE; return PR_TRUE;
} }
if (ch == '/') { if (ch == '/') {
@ -835,7 +855,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));
EatWhiteSpace(); (void) EatWhiteSpace();
return PR_TRUE; return PR_TRUE;
} }
@ -870,7 +890,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
EatWhiteSpace(); (void) EatWhiteSpace();
if (LookAhead(')')) { if (LookAhead(')')) {
Pushback(')'); // leave the closing symbol Pushback(')'); // leave the closing symbol
// done! // done!
@ -959,13 +979,17 @@ 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
ch = Read(); // Consume the escaped character if (!EatNewline()) { // skip escaped newline
if ((ch > 0) && (ch != '\n')) { (void) Read();
aOutput.Append(ch); if (ch > 0) {
aOutput.Append(ch);
}
}
return;
} }
} }
@ -1169,6 +1193,53 @@ 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,14 +211,19 @@ protected:
PRInt32 Read(); PRInt32 Read();
PRInt32 Peek(); PRInt32 Peek();
PRBool LookAhead(PRUnichar aChar); PRBool LookAhead(PRUnichar aChar);
void EatWhiteSpace(); PRBool EatWhiteSpace();
PRBool EatNewline();
void ParseAndAppendEscape(nsString& aOutput); void ParseAndAppendEscape(nsString& aOutput);
PRBool ParseIdent(PRInt32 aChar, nsCSSToken& aResult); PRBool ParseIdent(PRInt32 aChar, nsCSSToken& aResult);
PRBool ParseAtKeyword(PRInt32 aChar, nsCSSToken& aResult); PRBool ParseAtKeyword(PRInt32 aChar, nsCSSToken& aResult);
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);