From 1de330b786afa0108b4863efb5a367d477314cf1 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 9 Apr 2009 11:58:40 -0400 Subject: [PATCH] Backed out changeset 3c687f3d4ff4 (bug 482971) on suspicion of causing intermittent leak orange. --- layout/style/nsCSSScanner.cpp | 99 ++++++++++++++++++++++++++++++----- layout/style/nsCSSScanner.h | 9 +++- 2 files changed, 92 insertions(+), 16 deletions(-) diff --git a/layout/style/nsCSSScanner.cpp b/layout/style/nsCSSScanner.cpp index f4ab452b0d0..0c516478423 100644 --- a/layout/style/nsCSSScanner.cpp +++ b/layout/style/nsCSSScanner.cpp @@ -669,19 +669,39 @@ nsCSSScanner::LookAhead(PRUnichar aChar) return PR_FALSE; } -void +PRBool nsCSSScanner::EatWhiteSpace() { + PRBool eaten = PR_FALSE; for (;;) { PRInt32 ch = Read(); if (ch < 0) { break; } - if ((ch != ' ') && (ch != '\n') && (ch != '\t')) { - Pushback(ch); - break; + if ((ch == ' ') || (ch == '\n') || (ch == '\t')) { + eaten = PR_TRUE; + 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 @@ -740,7 +760,7 @@ nsCSSScanner::Next(nsCSSToken& aToken) if (IsWhitespace(ch)) { aToken.mType = eCSSToken_WhiteSpace; aToken.mIdent.Assign(PRUnichar(ch)); - EatWhiteSpace(); + (void) EatWhiteSpace(); return PR_TRUE; } if (ch == '/') { @@ -835,7 +855,7 @@ nsCSSScanner::NextURL(nsCSSToken& aToken) if (IsWhitespace(ch)) { aToken.mType = eCSSToken_WhiteSpace; aToken.mIdent.Assign(PRUnichar(ch)); - EatWhiteSpace(); + (void) EatWhiteSpace(); return PR_TRUE; } @@ -870,7 +890,7 @@ nsCSSScanner::NextURL(nsCSSToken& aToken) ok = PR_FALSE; } else if (IsWhitespace(ch)) { // Whitespace is allowed at the end of the URL - EatWhiteSpace(); + (void) EatWhiteSpace(); if (LookAhead(')')) { Pushback(')'); // leave the closing symbol // done! @@ -959,13 +979,17 @@ nsCSSScanner::ParseAndAppendEscape(nsString& aOutput) Pushback(ch); } return; - } - // "Any character except a hexidecimal digit can be escaped to - // remove its special meaning by putting a backslash in front" - // -- CSS1 spec section 7.1 - ch = Read(); // Consume the escaped character - if ((ch > 0) && (ch != '\n')) { - aOutput.Append(ch); + } else { + // "Any character except a hexidecimal digit can be escaped to + // remove its special meaning by putting a backslash in front" + // -- CSS1 spec section 7.1 + if (!EatNewline()) { // skip escaped newline + (void) Read(); + if (ch > 0) { + aOutput.Append(ch); + } + } + return; } } @@ -1169,6 +1193,53 @@ nsCSSScanner::SkipCComment() 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 nsCSSScanner::ParseString(PRInt32 aStop, nsCSSToken& aToken) { diff --git a/layout/style/nsCSSScanner.h b/layout/style/nsCSSScanner.h index 733933090d0..70ecb611cc5 100644 --- a/layout/style/nsCSSScanner.h +++ b/layout/style/nsCSSScanner.h @@ -211,14 +211,19 @@ protected: PRInt32 Read(); PRInt32 Peek(); PRBool LookAhead(PRUnichar aChar); - void EatWhiteSpace(); - + PRBool EatWhiteSpace(); + PRBool EatNewline(); + void ParseAndAppendEscape(nsString& aOutput); PRBool ParseIdent(PRInt32 aChar, nsCSSToken& aResult); PRBool ParseAtKeyword(PRInt32 aChar, nsCSSToken& aResult); PRBool ParseNumber(PRInt32 aChar, nsCSSToken& aResult); PRBool ParseRef(PRInt32 aChar, nsCSSToken& aResult); PRBool ParseString(PRInt32 aChar, nsCSSToken& aResult); +#if 0 + PRBool ParseCComment(nsCSSToken& aResult); + PRBool ParseEOLComment(nsCSSToken& aResult); +#endif PRBool SkipCComment(); PRBool GatherIdent(PRInt32 aChar, nsString& aIdent);