2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 05:32:19 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Contributor(s):
|
2003-01-02 02:53:20 +03:00
|
|
|
* L. David Baron <dbaron@dbaron.org>
|
2001-03-03 03:54:04 +03:00
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 05:32:19 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 05:32:19 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-25 08:47:31 +03:00
|
|
|
|
|
|
|
/* tokenization of CSS style sheets */
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsCSSScanner.h"
|
2004-11-23 23:53:38 +03:00
|
|
|
#include "nsIFactory.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIUnicharInputStream.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
|
2001-03-06 04:57:30 +03:00
|
|
|
// for #ifdef CSS_REPORT_PARSE_ERRORS
|
2000-09-06 06:27:46 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2000-09-08 06:05:09 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsIComponentManager.h"
|
2000-09-08 06:05:09 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2000-09-06 06:27:46 +04:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIScriptError.h"
|
2004-10-12 22:44:14 +04:00
|
|
|
#include "nsIStringBundle.h"
|
2005-12-28 01:03:29 +03:00
|
|
|
#include "nsContentUtils.h"
|
2000-09-06 06:27:46 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Don't bother collecting whitespace characters in token's mIdent buffer
|
|
|
|
#undef COLLECT_WHITESPACE
|
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
#define BUFFER_SIZE 256
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
static const PRUnichar CSS_ESCAPE = PRUnichar('\\');
|
2004-04-03 23:01:38 +04:00
|
|
|
const PRUint8 nsCSSScanner::IS_DIGIT = 0x01;
|
|
|
|
const PRUint8 nsCSSScanner::IS_HEX_DIGIT = 0x02;
|
2005-08-31 20:15:58 +04:00
|
|
|
const PRUint8 nsCSSScanner::START_IDENT = 0x04;
|
|
|
|
const PRUint8 nsCSSScanner::IS_IDENT = 0x08;
|
|
|
|
const PRUint8 nsCSSScanner::IS_WHITESPACE = 0x10;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-10-09 00:41:19 +04:00
|
|
|
static PRBool gLexTableSetup = PR_FALSE;
|
2004-04-03 21:18:45 +04:00
|
|
|
PRUint8 nsCSSScanner::gLexTable[256];
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-09-30 09:18:05 +04:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
2005-12-28 01:03:29 +03:00
|
|
|
static PRBool gReportErrors = PR_TRUE;
|
2004-09-30 09:18:05 +04:00
|
|
|
static nsIConsoleService *gConsoleService;
|
|
|
|
static nsIFactory *gScriptErrorFactory;
|
2004-10-12 22:44:14 +04:00
|
|
|
static nsIStringBundle *gStringBundle;
|
2004-09-30 09:18:05 +04:00
|
|
|
#endif
|
|
|
|
|
2004-04-03 21:18:45 +04:00
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
nsCSSScanner::BuildLexTable()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
gLexTableSetup = PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-10-09 00:41:19 +04:00
|
|
|
PRUint8* lt = gLexTable;
|
1998-04-14 00:24:54 +04:00
|
|
|
int i;
|
|
|
|
lt[CSS_ESCAPE] = START_IDENT;
|
|
|
|
lt['-'] |= IS_IDENT;
|
2001-04-10 15:09:07 +04:00
|
|
|
lt['_'] |= IS_IDENT | START_IDENT;
|
2007-03-23 02:01:14 +03:00
|
|
|
// XXX add in other whitespace chars
|
1999-05-19 03:13:27 +04:00
|
|
|
lt[' '] |= IS_WHITESPACE; // space
|
|
|
|
lt['\t'] |= IS_WHITESPACE; // horizontal tab
|
2007-03-23 02:01:14 +03:00
|
|
|
lt['\v'] |= IS_WHITESPACE; // vertical tab
|
1999-05-19 03:13:27 +04:00
|
|
|
lt['\r'] |= IS_WHITESPACE; // carriage return
|
|
|
|
lt['\n'] |= IS_WHITESPACE; // line feed
|
|
|
|
lt['\f'] |= IS_WHITESPACE; // form feed
|
1998-04-14 00:24:54 +04:00
|
|
|
for (i = 161; i <= 255; i++) {
|
2004-04-03 21:18:45 +04:00
|
|
|
lt[i] |= IS_IDENT | START_IDENT;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
for (i = '0'; i <= '9'; i++) {
|
|
|
|
lt[i] |= IS_DIGIT | IS_HEX_DIGIT | IS_IDENT;
|
|
|
|
}
|
|
|
|
for (i = 'A'; i <= 'Z'; i++) {
|
|
|
|
if ((i >= 'A') && (i <= 'F')) {
|
|
|
|
lt[i] |= IS_HEX_DIGIT;
|
|
|
|
lt[i+32] |= IS_HEX_DIGIT;
|
|
|
|
}
|
2005-08-31 20:15:58 +04:00
|
|
|
lt[i] |= IS_IDENT | START_IDENT;
|
|
|
|
lt[i+32] |= IS_IDENT | START_IDENT;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSToken::nsCSSToken()
|
|
|
|
{
|
|
|
|
mType = eCSSToken_Symbol;
|
|
|
|
}
|
|
|
|
|
1999-02-08 00:47:48 +03:00
|
|
|
void
|
|
|
|
nsCSSToken::AppendToString(nsString& aBuffer)
|
|
|
|
{
|
|
|
|
switch (mType) {
|
|
|
|
case eCSSToken_AtKeyword:
|
|
|
|
aBuffer.Append(PRUnichar('@')); // fall through intentional
|
|
|
|
case eCSSToken_Ident:
|
|
|
|
case eCSSToken_WhiteSpace:
|
|
|
|
case eCSSToken_Function:
|
|
|
|
case eCSSToken_URL:
|
|
|
|
case eCSSToken_InvalidURL:
|
|
|
|
case eCSSToken_HTMLComment:
|
|
|
|
aBuffer.Append(mIdent);
|
|
|
|
break;
|
|
|
|
case eCSSToken_Number:
|
|
|
|
if (mIntegerValid) {
|
2000-04-16 00:15:37 +04:00
|
|
|
aBuffer.AppendInt(mInteger, 10);
|
1999-02-08 00:47:48 +03:00
|
|
|
}
|
|
|
|
else {
|
2000-04-16 00:15:37 +04:00
|
|
|
aBuffer.AppendFloat(mNumber);
|
1999-02-08 00:47:48 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case eCSSToken_Percentage:
|
2003-03-18 08:43:12 +03:00
|
|
|
NS_ASSERTION(!mIntegerValid, "How did a percentage token get this set?");
|
|
|
|
aBuffer.AppendFloat(mNumber * 100.0f);
|
2000-04-16 00:15:37 +04:00
|
|
|
aBuffer.Append(PRUnichar('%')); // STRING USE WARNING: technically, this should be |AppendWithConversion|
|
1999-02-08 00:47:48 +03:00
|
|
|
break;
|
|
|
|
case eCSSToken_Dimension:
|
|
|
|
if (mIntegerValid) {
|
2000-04-16 00:15:37 +04:00
|
|
|
aBuffer.AppendInt(mInteger, 10);
|
1999-02-08 00:47:48 +03:00
|
|
|
}
|
|
|
|
else {
|
2000-04-16 00:15:37 +04:00
|
|
|
aBuffer.AppendFloat(mNumber);
|
1999-02-08 00:47:48 +03:00
|
|
|
}
|
|
|
|
aBuffer.Append(mIdent);
|
|
|
|
break;
|
|
|
|
case eCSSToken_String:
|
|
|
|
aBuffer.Append(mSymbol);
|
|
|
|
aBuffer.Append(mIdent); // fall through intentional
|
|
|
|
case eCSSToken_Symbol:
|
|
|
|
aBuffer.Append(mSymbol);
|
|
|
|
break;
|
|
|
|
case eCSSToken_ID:
|
2005-07-20 00:49:34 +04:00
|
|
|
case eCSSToken_Ref:
|
1999-02-08 00:47:48 +03:00
|
|
|
aBuffer.Append(PRUnichar('#'));
|
|
|
|
aBuffer.Append(mIdent);
|
|
|
|
break;
|
2000-04-27 04:12:25 +04:00
|
|
|
case eCSSToken_Includes:
|
2004-06-17 04:13:25 +04:00
|
|
|
aBuffer.AppendLiteral("~=");
|
2000-04-27 04:12:25 +04:00
|
|
|
break;
|
|
|
|
case eCSSToken_Dashmatch:
|
2004-06-17 04:13:25 +04:00
|
|
|
aBuffer.AppendLiteral("|=");
|
2000-04-27 04:12:25 +04:00
|
|
|
break;
|
2005-03-18 09:56:56 +03:00
|
|
|
case eCSSToken_Error:
|
|
|
|
aBuffer.Append(mSymbol);
|
|
|
|
aBuffer.Append(mIdent);
|
|
|
|
break;
|
1999-02-08 00:47:48 +03:00
|
|
|
default:
|
|
|
|
NS_ERROR("invalid token type");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
nsCSSScanner::nsCSSScanner()
|
2005-11-11 01:26:06 +03:00
|
|
|
: mInputStream(nsnull)
|
|
|
|
, mReadPointer(nsnull)
|
2005-01-22 07:52:05 +03:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
2005-11-11 01:26:06 +03:00
|
|
|
, mError(mErrorBuf, NS_ARRAY_LENGTH(mErrorBuf), 0)
|
2005-01-22 07:52:05 +03:00
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(nsCSSScanner);
|
|
|
|
if (!gLexTableSetup) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// XXX need a monitor
|
|
|
|
BuildLexTable();
|
|
|
|
}
|
1998-09-25 05:50:51 +04:00
|
|
|
mPushback = mLocalPushback;
|
2007-03-23 02:01:14 +03:00
|
|
|
mPushbackSize = 4;
|
2004-10-14 07:30:55 +04:00
|
|
|
// No need to init the other members, since they represent state
|
|
|
|
// which can get cleared. We'll init them every time Init() is
|
|
|
|
// called.
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSScanner::~nsCSSScanner()
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_DTOR(nsCSSScanner);
|
1998-04-14 00:24:54 +04:00
|
|
|
Close();
|
1998-09-25 05:50:51 +04:00
|
|
|
if (mLocalPushback != mPushback) {
|
|
|
|
delete [] mPushback;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2005-12-28 01:03:29 +03:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
|
|
|
#define CSS_ERRORS_PREF "layout.css.report_errors"
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(int) CSSErrorsPrefChanged(const char *aPref, void *aClosure)
|
|
|
|
{
|
|
|
|
gReportErrors = nsContentUtils::GetBoolPref(CSS_ERRORS_PREF, PR_TRUE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-09-30 09:18:05 +04:00
|
|
|
/* static */ PRBool nsCSSScanner::InitGlobals()
|
|
|
|
{
|
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
|
|
|
if (gConsoleService && gScriptErrorFactory)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
nsresult rv = CallGetService(NS_CONSOLESERVICE_CONTRACTID, &gConsoleService);
|
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
|
2004-10-02 04:44:13 +04:00
|
|
|
rv = CallGetClassObject(NS_SCRIPTERROR_CONTRACTID, &gScriptErrorFactory);
|
2004-09-30 09:18:05 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
NS_ASSERTION(gConsoleService && gScriptErrorFactory,
|
|
|
|
"unexpected null pointer without failure");
|
2005-12-28 01:03:29 +03:00
|
|
|
|
|
|
|
nsContentUtils::RegisterPrefCallback(CSS_ERRORS_PREF, CSSErrorsPrefChanged, nsnull);
|
|
|
|
CSSErrorsPrefChanged(CSS_ERRORS_PREF, nsnull);
|
2004-09-30 09:18:05 +04:00
|
|
|
#endif
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void nsCSSScanner::ReleaseGlobals()
|
|
|
|
{
|
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
2005-12-28 01:03:29 +03:00
|
|
|
nsContentUtils::UnregisterPrefCallback(CSS_ERRORS_PREF, CSSErrorsPrefChanged, nsnull);
|
2004-09-30 09:18:05 +04:00
|
|
|
NS_IF_RELEASE(gConsoleService);
|
|
|
|
NS_IF_RELEASE(gScriptErrorFactory);
|
2004-10-12 22:44:14 +04:00
|
|
|
NS_IF_RELEASE(gStringBundle);
|
2004-09-30 09:18:05 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-11-11 01:26:06 +03:00
|
|
|
void nsCSSScanner::Init(nsIUnicharInputStream* aInput,
|
2007-03-23 02:01:14 +03:00
|
|
|
const PRUnichar * aBuffer, PRInt32 aCount,
|
2005-11-11 01:26:06 +03:00
|
|
|
nsIURI* aURI, PRUint32 aLineNumber)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2005-11-11 01:26:06 +03:00
|
|
|
NS_PRECONDITION(!mInputStream, "Should not have an existing input stream!");
|
|
|
|
NS_PRECONDITION(!mReadPointer, "Should not have an existing input buffer!");
|
|
|
|
|
|
|
|
// Read from stream via my own buffer
|
|
|
|
if (aInput) {
|
|
|
|
NS_PRECONDITION(!aBuffer, "Shouldn't have both input and buffer!");
|
|
|
|
NS_PRECONDITION(aCount == 0, "Shouldn't have count with a stream");
|
|
|
|
mInputStream = aInput;
|
|
|
|
mReadPointer = mBuffer;
|
|
|
|
mCount = 0;
|
|
|
|
} else {
|
|
|
|
NS_PRECONDITION(aBuffer, "Either aInput or aBuffer must be set");
|
|
|
|
// Read directly from the provided buffer
|
|
|
|
mInputStream = nsnull;
|
|
|
|
mReadPointer = aBuffer;
|
|
|
|
mCount = aCount;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-09-06 06:27:46 +04:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
2004-10-14 07:30:55 +04:00
|
|
|
// If aURI is the same as mURI, no need to reget mFileName -- it
|
|
|
|
// shouldn't have changed.
|
|
|
|
if (aURI != mURI) {
|
|
|
|
mURI = aURI;
|
|
|
|
if (aURI) {
|
|
|
|
aURI->GetSpec(mFileName);
|
|
|
|
} else {
|
2006-11-17 04:49:06 +03:00
|
|
|
mFileName.Adopt(NS_strdup("from DOM"));
|
2004-10-14 07:30:55 +04:00
|
|
|
}
|
2000-09-06 06:27:46 +04:00
|
|
|
}
|
2001-03-06 04:57:30 +03:00
|
|
|
#endif // CSS_REPORT_PARSE_ERRORS
|
2004-09-09 21:32:35 +04:00
|
|
|
mLineNumber = aLineNumber;
|
2004-10-14 07:30:55 +04:00
|
|
|
|
2005-11-11 01:26:06 +03:00
|
|
|
// Reset variables that we use to keep track of our progress through the input
|
2004-10-14 07:30:55 +04:00
|
|
|
mOffset = 0;
|
|
|
|
mPushbackCount = 0;
|
2007-03-23 02:01:14 +03:00
|
|
|
mLastRead = 0;
|
2004-10-14 07:30:55 +04:00
|
|
|
|
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
|
|
|
mColNumber = 0;
|
|
|
|
#endif
|
2000-09-06 06:27:46 +04:00
|
|
|
}
|
|
|
|
|
2001-03-06 04:57:30 +03:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
|
|
|
|
2003-01-13 10:19:49 +03:00
|
|
|
// @see REPORT_UNEXPECTED_EOF in nsCSSParser.cpp
|
2004-10-12 22:44:14 +04:00
|
|
|
#define REPORT_UNEXPECTED_EOF(lf_) \
|
|
|
|
ReportUnexpectedEOF(#lf_)
|
2003-01-13 10:19:49 +03:00
|
|
|
|
2004-09-30 09:18:05 +04:00
|
|
|
void nsCSSScanner::AddToError(const nsSubstring& aErrorText)
|
2000-09-06 06:27:46 +04:00
|
|
|
{
|
2002-01-24 05:03:19 +03:00
|
|
|
if (mError.IsEmpty()) {
|
2001-03-06 04:57:30 +03:00
|
|
|
mErrorLineNumber = mLineNumber;
|
|
|
|
mErrorColNumber = mColNumber;
|
|
|
|
mError = aErrorText;
|
|
|
|
} else {
|
2004-09-30 09:18:05 +04:00
|
|
|
mError.Append(NS_LITERAL_STRING(" ") + aErrorText);
|
2001-03-06 04:57:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSScanner::ClearError()
|
|
|
|
{
|
|
|
|
mError.Truncate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSScanner::OutputError()
|
|
|
|
{
|
2002-01-24 05:03:19 +03:00
|
|
|
if (mError.IsEmpty()) return;
|
2001-03-06 04:57:30 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2007-03-23 02:01:14 +03:00
|
|
|
fprintf(stderr, "CSS Error (%s :%u.%u): %s\n",
|
|
|
|
mFileName.get(), mErrorLineNumber, mErrorColNumber,
|
|
|
|
NS_ConvertUTF16toUTF8(mError).get());
|
2001-03-06 04:57:30 +03:00
|
|
|
#endif
|
2000-09-06 06:27:46 +04:00
|
|
|
|
2006-05-26 01:22:32 +04:00
|
|
|
// Log it to the Error console
|
2000-09-06 06:27:46 +04:00
|
|
|
|
2005-12-28 01:03:29 +03:00
|
|
|
if (InitGlobals() && gReportErrors) {
|
2004-10-02 04:44:13 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIScriptError> errorObject =
|
|
|
|
do_CreateInstance(gScriptErrorFactory, &rv);
|
2004-09-30 09:18:05 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = errorObject->Init(mError.get(),
|
2005-11-03 10:19:34 +03:00
|
|
|
NS_ConvertUTF8toUTF16(mFileName).get(),
|
2004-09-30 09:18:05 +04:00
|
|
|
EmptyString().get(),
|
|
|
|
mErrorLineNumber,
|
|
|
|
mErrorColNumber,
|
2005-12-28 01:03:29 +03:00
|
|
|
nsIScriptError::warningFlag,
|
2004-09-30 09:18:05 +04:00
|
|
|
"CSS Parser");
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
gConsoleService->LogMessage(errorObject);
|
|
|
|
}
|
2000-09-06 06:27:46 +04:00
|
|
|
}
|
2001-03-06 04:57:30 +03:00
|
|
|
ClearError();
|
2000-09-06 06:27:46 +04:00
|
|
|
}
|
2004-10-12 22:44:14 +04:00
|
|
|
|
|
|
|
static PRBool InitStringBundle()
|
|
|
|
{
|
|
|
|
if (gStringBundle)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStringBundleService> sbs =
|
|
|
|
do_GetService(NS_STRINGBUNDLE_CONTRACTID);
|
|
|
|
if (!sbs)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
sbs->CreateBundle("chrome://global/locale/css.properties", &gStringBundle);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
gStringBundle = nsnull;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ENSURE_STRINGBUNDLE \
|
|
|
|
PR_BEGIN_MACRO if (!InitStringBundle()) return; PR_END_MACRO
|
|
|
|
|
|
|
|
// aMessage must take no parameters
|
|
|
|
void nsCSSScanner::ReportUnexpected(const char* aMessage)
|
|
|
|
{
|
|
|
|
ENSURE_STRINGBUNDLE;
|
|
|
|
|
|
|
|
nsXPIDLString str;
|
|
|
|
gStringBundle->GetStringFromName(NS_ConvertASCIItoUTF16(aMessage).get(),
|
|
|
|
getter_Copies(str));
|
|
|
|
AddToError(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSScanner::ReportUnexpectedParams(const char* aMessage,
|
|
|
|
const PRUnichar **aParams,
|
|
|
|
PRUint32 aParamsLength)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aParamsLength > 0, "use the non-params version");
|
|
|
|
ENSURE_STRINGBUNDLE;
|
|
|
|
|
|
|
|
nsXPIDLString str;
|
|
|
|
gStringBundle->FormatStringFromName(NS_ConvertASCIItoUTF16(aMessage).get(),
|
|
|
|
aParams, aParamsLength,
|
|
|
|
getter_Copies(str));
|
|
|
|
AddToError(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
// aMessage must take no parameters
|
|
|
|
void nsCSSScanner::ReportUnexpectedEOF(const char* aLookingFor)
|
|
|
|
{
|
|
|
|
ENSURE_STRINGBUNDLE;
|
|
|
|
|
|
|
|
nsXPIDLString innerStr;
|
|
|
|
gStringBundle->GetStringFromName(NS_ConvertASCIItoUTF16(aLookingFor).get(),
|
|
|
|
getter_Copies(innerStr));
|
|
|
|
|
|
|
|
const PRUnichar *params[] = {
|
|
|
|
innerStr.get()
|
|
|
|
};
|
|
|
|
nsXPIDLString str;
|
2007-01-24 01:49:49 +03:00
|
|
|
gStringBundle->FormatStringFromName(NS_LITERAL_STRING("PEUnexpEOF2").get(),
|
2004-10-12 22:44:14 +04:00
|
|
|
params, NS_ARRAY_LENGTH(params),
|
|
|
|
getter_Copies(str));
|
|
|
|
AddToError(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
// aMessage must take 1 parameter (for the string representation of the
|
|
|
|
// unexpected token)
|
|
|
|
void nsCSSScanner::ReportUnexpectedToken(nsCSSToken& tok,
|
|
|
|
const char *aMessage)
|
|
|
|
{
|
|
|
|
ENSURE_STRINGBUNDLE;
|
|
|
|
|
|
|
|
nsAutoString tokenString;
|
|
|
|
tok.AppendToString(tokenString);
|
|
|
|
|
|
|
|
const PRUnichar *params[] = {
|
|
|
|
tokenString.get()
|
|
|
|
};
|
|
|
|
|
|
|
|
ReportUnexpectedParams(aMessage, params, NS_ARRAY_LENGTH(params));
|
|
|
|
}
|
|
|
|
|
|
|
|
// aParams's first entry must be null, and we'll fill in the token
|
|
|
|
void nsCSSScanner::ReportUnexpectedTokenParams(nsCSSToken& tok,
|
|
|
|
const char* aMessage,
|
|
|
|
const PRUnichar **aParams,
|
|
|
|
PRUint32 aParamsLength)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aParamsLength > 1, "use the non-params version");
|
|
|
|
NS_PRECONDITION(aParams[0] == nsnull, "first param should be empty");
|
|
|
|
|
|
|
|
ENSURE_STRINGBUNDLE;
|
|
|
|
|
|
|
|
nsAutoString tokenString;
|
|
|
|
tok.AppendToString(tokenString);
|
|
|
|
aParams[0] = tokenString.get();
|
|
|
|
|
|
|
|
ReportUnexpectedParams(aMessage, aParams, aParamsLength);
|
|
|
|
}
|
|
|
|
|
2003-01-13 11:02:17 +03:00
|
|
|
#else
|
2004-10-12 22:44:14 +04:00
|
|
|
|
|
|
|
#define REPORT_UNEXPECTED_EOF(lf_)
|
|
|
|
|
2000-09-06 06:27:46 +04:00
|
|
|
#endif // CSS_REPORT_PARSE_ERRORS
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
void nsCSSScanner::Close()
|
|
|
|
{
|
2005-11-11 01:26:06 +03:00
|
|
|
mInputStream = nsnull;
|
|
|
|
mReadPointer = nsnull;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2000-09-06 06:27:46 +04:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
|
|
|
#define TAB_STOP_WIDTH 8
|
|
|
|
#endif
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Returns -1 on error or eof
|
2003-11-14 01:48:05 +03:00
|
|
|
PRInt32 nsCSSScanner::Read(nsresult& aErrorCode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
PRInt32 rv;
|
1998-09-25 05:50:51 +04:00
|
|
|
if (0 < mPushbackCount) {
|
|
|
|
rv = PRInt32(mPushback[--mPushbackCount]);
|
1998-04-14 00:24:54 +04:00
|
|
|
} else {
|
2007-03-23 02:01:14 +03:00
|
|
|
if (mCount < 0) {
|
2007-08-24 03:01:52 +04:00
|
|
|
return -1;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
if (mOffset == mCount) {
|
|
|
|
mOffset = 0;
|
|
|
|
if (!mInputStream) {
|
|
|
|
mCount = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
aErrorCode = mInputStream->Read(mBuffer, CSS_BUFFER_SIZE, (PRUint32*)&mCount);
|
|
|
|
if (NS_FAILED(aErrorCode) || mCount == 0) {
|
|
|
|
mCount = 0;
|
|
|
|
return -1;
|
2007-08-24 03:01:52 +04:00
|
|
|
}
|
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
rv = PRInt32(mReadPointer[mOffset++]);
|
|
|
|
if (((rv == '\n') && (mLastRead != '\r')) || (rv == '\r')) {
|
2004-09-11 03:31:48 +04:00
|
|
|
// 0 is a magical line number meaning that we don't know (i.e., script)
|
|
|
|
if (mLineNumber != 0)
|
|
|
|
++mLineNumber;
|
2001-01-22 07:03:48 +03:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
2000-09-06 06:27:46 +04:00
|
|
|
mColNumber = 0;
|
2001-01-22 07:03:48 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
|
|
|
else if (rv == '\t') {
|
2000-09-06 06:27:46 +04:00
|
|
|
mColNumber = ((mColNumber - 1 + TAB_STOP_WIDTH) / TAB_STOP_WIDTH)
|
|
|
|
* TAB_STOP_WIDTH;
|
|
|
|
} else if (rv != '\n') {
|
|
|
|
mColNumber++;
|
|
|
|
}
|
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
mLastRead = rv;
|
2000-10-29 02:17:53 +04:00
|
|
|
//printf("Read => %x\n", rv);
|
1998-04-14 00:24:54 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRInt32 nsCSSScanner::Peek(nsresult& aErrorCode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-09-25 05:50:51 +04:00
|
|
|
if (0 == mPushbackCount) {
|
2007-03-23 02:01:14 +03:00
|
|
|
PRInt32 savedLastRead = mLastRead;
|
1998-10-27 02:22:40 +03:00
|
|
|
PRInt32 ch = Read(aErrorCode);
|
2007-03-23 02:01:14 +03:00
|
|
|
mLastRead = savedLastRead;
|
1998-10-27 02:22:40 +03:00
|
|
|
if (ch < 0) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return -1;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
mPushback[0] = PRUnichar(ch);
|
1998-09-25 05:50:51 +04:00
|
|
|
mPushbackCount++;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2000-10-29 02:17:53 +04:00
|
|
|
//printf("Peek => %x\n", mLookAhead);
|
1998-09-25 05:50:51 +04:00
|
|
|
return PRInt32(mPushback[mPushbackCount - 1]);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
void nsCSSScanner::Unread()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION((mLastRead >= 0), "double pushback");
|
|
|
|
Pushback(PRUnichar(mLastRead));
|
|
|
|
mLastRead = -1;
|
|
|
|
}
|
|
|
|
|
1998-09-25 05:50:51 +04:00
|
|
|
void nsCSSScanner::Pushback(PRUnichar aChar)
|
|
|
|
{
|
|
|
|
if (mPushbackCount == mPushbackSize) { // grow buffer
|
|
|
|
PRUnichar* newPushback = new PRUnichar[mPushbackSize + 4];
|
|
|
|
if (nsnull == newPushback) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mPushbackSize += 4;
|
2002-01-12 06:18:55 +03:00
|
|
|
memcpy(newPushback, mPushback, sizeof(PRUnichar) * mPushbackCount);
|
1998-09-25 05:50:51 +04:00
|
|
|
if (mPushback != mLocalPushback) {
|
|
|
|
delete [] mPushback;
|
|
|
|
}
|
|
|
|
mPushback = newPushback;
|
|
|
|
}
|
|
|
|
mPushback[mPushbackCount++] = aChar;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool nsCSSScanner::LookAhead(nsresult& aErrorCode, PRUnichar aChar)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
PRInt32 ch = Read(aErrorCode);
|
|
|
|
if (ch < 0) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (ch == aChar) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
Unread();
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool nsCSSScanner::EatWhiteSpace(nsresult& aErrorCode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
PRBool eaten = PR_FALSE;
|
|
|
|
for (;;) {
|
|
|
|
PRInt32 ch = Read(aErrorCode);
|
|
|
|
if (ch < 0) {
|
|
|
|
break;
|
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
if ((ch == ' ') || (ch == '\n') || (ch == '\r') || (ch == '\t')) {
|
1998-04-14 00:24:54 +04:00
|
|
|
eaten = PR_TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
Unread();
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return eaten;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool nsCSSScanner::EatNewline(nsresult& aErrorCode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
PRInt32 ch = Read(aErrorCode);
|
|
|
|
if (ch < 0) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
PRBool eaten = PR_FALSE;
|
2007-03-23 02:01:14 +03:00
|
|
|
if (ch == '\r') {
|
|
|
|
eaten = PR_TRUE;
|
|
|
|
ch = Peek(aErrorCode);
|
|
|
|
if (ch == '\n') {
|
|
|
|
(void) Read(aErrorCode);
|
|
|
|
}
|
|
|
|
} else if (ch == '\n') {
|
1998-04-14 00:24:54 +04:00
|
|
|
eaten = PR_TRUE;
|
|
|
|
} else {
|
2007-03-23 02:01:14 +03:00
|
|
|
Unread();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return eaten;
|
|
|
|
}
|
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
/* static */
|
|
|
|
PRBool
|
|
|
|
nsCSSScanner::CheckLexTable(PRInt32 aChar, PRUint8 aBit, PRUint8* aLexTable)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!(aBit & (START_IDENT | IS_IDENT)),
|
|
|
|
"can't use CheckLexTable with identifiers");
|
|
|
|
return aChar >= 0 && aChar < 256 && (aLexTable[aChar] & aBit) != 0;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool nsCSSScanner::Next(nsresult& aErrorCode, nsCSSToken& aToken)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
PRInt32 ch = Read(aErrorCode);
|
|
|
|
if (ch < 0) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
PRUint8* lexTable = gLexTable;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-02-08 10:29:42 +03:00
|
|
|
// IDENT
|
2007-03-23 02:01:14 +03:00
|
|
|
if (StartsIdent(ch, Peek(aErrorCode), lexTable))
|
2004-02-08 10:29:42 +03:00
|
|
|
return ParseIdent(aErrorCode, ch, aToken);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
// From this point on, 0 <= ch < 256.
|
|
|
|
|
2004-02-08 10:29:42 +03:00
|
|
|
// AT_KEYWORD
|
|
|
|
if (ch == '@') {
|
|
|
|
PRInt32 nextChar = Read(aErrorCode);
|
|
|
|
PRInt32 followingChar = Peek(aErrorCode);
|
|
|
|
Pushback(nextChar);
|
2007-03-23 02:01:14 +03:00
|
|
|
if (StartsIdent(nextChar, followingChar, lexTable))
|
2004-02-08 10:29:42 +03:00
|
|
|
return ParseAtKeyword(aErrorCode, ch, aToken);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-02-08 10:29:42 +03:00
|
|
|
// NUMBER or DIM
|
|
|
|
if ((ch == '.') || (ch == '+') || (ch == '-')) {
|
|
|
|
PRInt32 nextChar = Peek(aErrorCode);
|
2007-03-23 02:01:14 +03:00
|
|
|
if (CheckLexTable(nextChar, IS_DIGIT, lexTable)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return ParseNumber(aErrorCode, ch, aToken);
|
|
|
|
}
|
2004-02-08 10:29:42 +03:00
|
|
|
else if (('.' == nextChar) && ('.' != ch)) {
|
|
|
|
nextChar = Read(aErrorCode);
|
|
|
|
PRInt32 followingChar = Peek(aErrorCode);
|
|
|
|
Pushback(nextChar);
|
2007-03-23 02:01:14 +03:00
|
|
|
if (CheckLexTable(followingChar, IS_DIGIT, lexTable))
|
2004-02-08 10:29:42 +03:00
|
|
|
return ParseNumber(aErrorCode, ch, aToken);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2004-02-08 10:29:42 +03:00
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
if ((lexTable[ch] & IS_DIGIT) != 0) {
|
2004-02-08 10:29:42 +03:00
|
|
|
return ParseNumber(aErrorCode, ch, aToken);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-02-08 10:29:42 +03:00
|
|
|
// ID
|
|
|
|
if (ch == '#') {
|
2005-07-20 00:49:34 +04:00
|
|
|
return ParseRef(aErrorCode, ch, aToken);
|
2004-02-08 10:29:42 +03:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-02-08 10:29:42 +03:00
|
|
|
// STRING
|
|
|
|
if ((ch == '"') || (ch == '\'')) {
|
|
|
|
return ParseString(aErrorCode, ch, aToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
// WS
|
2007-03-23 02:01:14 +03:00
|
|
|
if ((lexTable[ch] & IS_WHITESPACE) != 0) {
|
2004-02-08 10:29:42 +03:00
|
|
|
aToken.mType = eCSSToken_WhiteSpace;
|
|
|
|
aToken.mIdent.Assign(PRUnichar(ch));
|
|
|
|
(void) EatWhiteSpace(aErrorCode);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (ch == '/') {
|
|
|
|
PRInt32 nextChar = Peek(aErrorCode);
|
|
|
|
if (nextChar == '*') {
|
|
|
|
(void) Read(aErrorCode);
|
2003-01-13 10:19:49 +03:00
|
|
|
#if 0
|
2004-02-08 10:29:42 +03:00
|
|
|
// If we change our storage data structures such that comments are
|
|
|
|
// stored (for Editor), we should reenable this code, condition it
|
|
|
|
// on being in editor mode, and apply glazou's patch from bug
|
|
|
|
// 60290.
|
|
|
|
aToken.mIdent.SetCapacity(2);
|
|
|
|
aToken.mIdent.Assign(PRUnichar(ch));
|
|
|
|
aToken.mIdent.Append(PRUnichar(nextChar));
|
|
|
|
return ParseCComment(aErrorCode, aToken);
|
2003-01-13 10:19:49 +03:00
|
|
|
#endif
|
2004-02-08 10:29:42 +03:00
|
|
|
return SkipCComment(aErrorCode) && Next(aErrorCode, aToken);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2004-02-08 10:29:42 +03:00
|
|
|
}
|
|
|
|
if (ch == '<') { // consume HTML comment tags
|
|
|
|
if (LookAhead(aErrorCode, '!')) {
|
2000-04-27 04:12:25 +04:00
|
|
|
if (LookAhead(aErrorCode, '-')) {
|
2004-02-08 10:29:42 +03:00
|
|
|
if (LookAhead(aErrorCode, '-')) {
|
1999-02-03 05:59:51 +03:00
|
|
|
aToken.mType = eCSSToken_HTMLComment;
|
2004-06-17 04:13:25 +04:00
|
|
|
aToken.mIdent.AssignLiteral("<!--");
|
1998-09-25 05:50:51 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2000-04-27 04:12:25 +04:00
|
|
|
Pushback('-');
|
|
|
|
}
|
2004-02-08 10:29:42 +03:00
|
|
|
Pushback('!');
|
2000-04-27 04:12:25 +04:00
|
|
|
}
|
2004-02-08 10:29:42 +03:00
|
|
|
}
|
|
|
|
if (ch == '-') { // check for HTML comment end
|
|
|
|
if (LookAhead(aErrorCode, '-')) {
|
|
|
|
if (LookAhead(aErrorCode, '>')) {
|
|
|
|
aToken.mType = eCSSToken_HTMLComment;
|
2004-06-17 04:13:25 +04:00
|
|
|
aToken.mIdent.AssignLiteral("-->");
|
2000-04-27 04:12:25 +04:00
|
|
|
return PR_TRUE;
|
1998-09-25 05:50:51 +04:00
|
|
|
}
|
2004-02-08 10:29:42 +03:00
|
|
|
Pushback('-');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// INCLUDES ("~=") and DASHMATCH ("|=")
|
|
|
|
if (( ch == '|' ) || ( ch == '~' ) || ( ch == '^' ) ||
|
|
|
|
( ch == '$' ) || ( ch == '*' )) {
|
|
|
|
PRInt32 nextChar = Read(aErrorCode);
|
|
|
|
if ( nextChar == '=' ) {
|
|
|
|
if (ch == '~') {
|
|
|
|
aToken.mType = eCSSToken_Includes;
|
|
|
|
}
|
|
|
|
else if (ch == '|') {
|
|
|
|
aToken.mType = eCSSToken_Dashmatch;
|
|
|
|
}
|
|
|
|
else if (ch == '^') {
|
|
|
|
aToken.mType = eCSSToken_Beginsmatch;
|
|
|
|
}
|
|
|
|
else if (ch == '$') {
|
|
|
|
aToken.mType = eCSSToken_Endsmatch;
|
|
|
|
}
|
|
|
|
else if (ch == '*') {
|
|
|
|
aToken.mType = eCSSToken_Containsmatch;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
|
|
|
Pushback(nextChar);
|
1998-09-25 05:50:51 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
aToken.mType = eCSSToken_Symbol;
|
|
|
|
aToken.mSymbol = ch;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool nsCSSScanner::NextURL(nsresult& aErrorCode, nsCSSToken& aToken)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
|
|
|
PRInt32 ch = Read(aErrorCode);
|
|
|
|
if (ch < 0) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
if (ch < 256) {
|
|
|
|
PRUint8* lexTable = gLexTable;
|
1998-10-27 02:22:40 +03:00
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
// STRING
|
|
|
|
if ((ch == '"') || (ch == '\'')) {
|
|
|
|
return ParseString(aErrorCode, ch, aToken);
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
// WS
|
|
|
|
if ((lexTable[ch] & IS_WHITESPACE) != 0) {
|
|
|
|
aToken.mType = eCSSToken_WhiteSpace;
|
2007-08-20 07:39:23 +04:00
|
|
|
aToken.mIdent.Assign(PRUnichar(ch));
|
2007-03-23 02:01:14 +03:00
|
|
|
(void) EatWhiteSpace(aErrorCode);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (ch == '/') {
|
|
|
|
PRInt32 nextChar = Peek(aErrorCode);
|
|
|
|
if (nextChar == '*') {
|
|
|
|
(void) Read(aErrorCode);
|
|
|
|
#if 0
|
|
|
|
// If we change our storage data structures such that comments are
|
|
|
|
// stored (for Editor), we should reenable this code, condition it
|
|
|
|
// on being in editor mode, and apply glazou's patch from bug
|
|
|
|
// 60290.
|
|
|
|
aToken.mIdent.SetCapacity(2);
|
|
|
|
aToken.mIdent.Assign(PRUnichar(ch));
|
|
|
|
aToken.mIdent.Append(PRUnichar(nextChar));
|
|
|
|
return ParseCComment(aErrorCode, aToken);
|
2003-01-13 10:19:49 +03:00
|
|
|
#endif
|
2007-03-23 02:01:14 +03:00
|
|
|
return SkipCComment(aErrorCode) && Next(aErrorCode, aToken);
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
2007-08-20 07:39:23 +04:00
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
// Process a url lexical token. A CSS1 url token can contain
|
|
|
|
// characters beyond identifier characters (e.g. '/', ':', etc.)
|
|
|
|
// Because of this the normal rules for tokenizing the input don't
|
|
|
|
// apply very well. To simplify the parser and relax some of the
|
|
|
|
// requirements on the scanner we parse url's here. If we find a
|
|
|
|
// malformed URL then we emit a token of type "InvalidURL" so that
|
|
|
|
// the CSS1 parser can ignore the invalid input. We attempt to eat
|
|
|
|
// the right amount of input data when an invalid URL is presented.
|
|
|
|
|
|
|
|
aToken.mType = eCSSToken_InvalidURL;
|
|
|
|
nsString& ident = aToken.mIdent;
|
|
|
|
ident.SetLength(0);
|
2007-08-20 07:39:23 +04:00
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
if (ch == ')') {
|
|
|
|
Pushback(ch);
|
|
|
|
// empty url spec; just get out of here
|
|
|
|
aToken.mType = eCSSToken_URL;
|
|
|
|
} else {
|
|
|
|
// start of a non-quoted url
|
|
|
|
Pushback(ch);
|
|
|
|
PRBool ok = PR_TRUE;
|
|
|
|
for (;;) {
|
|
|
|
ch = Read(aErrorCode);
|
|
|
|
if (ch < 0) break;
|
|
|
|
if (ch == CSS_ESCAPE) {
|
|
|
|
ParseAndAppendEscape(aErrorCode, ident);
|
|
|
|
} else if ((ch == '"') || (ch == '\'') || (ch == '(')) {
|
|
|
|
// This is an invalid URL spec
|
|
|
|
ok = PR_FALSE;
|
|
|
|
} else if ((256 > ch) && ((gLexTable[ch] & IS_WHITESPACE) != 0)) {
|
|
|
|
// Whitespace is allowed at the end of the URL
|
|
|
|
(void) EatWhiteSpace(aErrorCode);
|
|
|
|
if (LookAhead(aErrorCode, ')')) {
|
|
|
|
Pushback(')'); // leave the closing symbol
|
|
|
|
// done!
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Whitespace is followed by something other than a
|
|
|
|
// ")". This is an invalid url spec.
|
|
|
|
ok = PR_FALSE;
|
|
|
|
} else if (ch == ')') {
|
|
|
|
Unread();
|
|
|
|
// All done
|
1998-10-27 02:22:40 +03:00
|
|
|
break;
|
2007-03-23 02:01:14 +03:00
|
|
|
} else {
|
|
|
|
// A regular url character.
|
|
|
|
ident.Append(PRUnichar(ch));
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
// If the result of the above scanning is ok then change the token
|
|
|
|
// type to a useful one.
|
|
|
|
if (ok) {
|
|
|
|
aToken.mType = eCSSToken_URL;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-10-27 02:22:40 +03:00
|
|
|
|
2005-11-17 18:17:00 +03:00
|
|
|
void
|
|
|
|
nsCSSScanner::ParseAndAppendEscape(nsresult& aErrorCode, nsString& aOutput)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2007-03-23 02:01:14 +03:00
|
|
|
PRUint8* lexTable = gLexTable;
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 ch = Peek(aErrorCode);
|
|
|
|
if (ch < 0) {
|
2005-11-17 18:17:00 +03:00
|
|
|
aOutput.Append(CSS_ESCAPE);
|
|
|
|
return;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
if ((ch <= 255) && ((lexTable[ch] & IS_HEX_DIGIT) != 0)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 rv = 0;
|
1999-05-19 04:18:30 +04:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < 6; i++) { // up to six digits
|
1998-04-14 00:24:54 +04:00
|
|
|
ch = Read(aErrorCode);
|
|
|
|
if (ch < 0) {
|
|
|
|
// Whoops: error or premature eof
|
|
|
|
break;
|
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
if (ch >= 256 || (lexTable[ch] & (IS_HEX_DIGIT | IS_WHITESPACE)) == 0) {
|
|
|
|
Unread();
|
2004-02-08 22:22:47 +03:00
|
|
|
break;
|
2007-03-23 02:01:14 +03:00
|
|
|
} else if ((lexTable[ch] & IS_HEX_DIGIT) != 0) {
|
|
|
|
if ((lexTable[ch] & IS_DIGIT) != 0) {
|
1998-04-14 00:24:54 +04:00
|
|
|
rv = rv * 16 + (ch - '0');
|
|
|
|
} else {
|
|
|
|
// Note: c&7 just keeps the low three bits which causes
|
|
|
|
// upper and lower case alphabetics to both yield their
|
|
|
|
// "relative to 10" value for computing the hex value.
|
1999-05-19 03:13:27 +04:00
|
|
|
rv = rv * 16 + ((ch & 0x7) + 9);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2004-02-08 22:22:47 +03:00
|
|
|
} else {
|
2007-03-23 02:01:14 +03:00
|
|
|
NS_ASSERTION((lexTable[ch] & IS_WHITESPACE) != 0, "bad control flow");
|
2004-02-08 22:22:47 +03:00
|
|
|
// single space ends escape
|
2007-03-23 02:01:14 +03:00
|
|
|
if (ch == '\r' && Peek(aErrorCode) == '\n') {
|
|
|
|
// if CR/LF, eat LF too
|
|
|
|
Read(aErrorCode);
|
|
|
|
}
|
1999-05-19 03:13:27 +04:00
|
|
|
break;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-05-19 03:13:27 +04:00
|
|
|
if (6 == i) { // look for trailing whitespace and eat it
|
|
|
|
ch = Peek(aErrorCode);
|
2007-03-23 02:01:14 +03:00
|
|
|
if ((0 <= ch) && (ch <= 255) &&
|
|
|
|
((lexTable[ch] & IS_WHITESPACE) != 0)) {
|
1999-05-19 03:13:27 +04:00
|
|
|
ch = Read(aErrorCode);
|
2007-03-23 02:01:14 +03:00
|
|
|
// special case: if trailing whitespace is CR/LF, eat both chars (not part of spec, but should be)
|
|
|
|
if (ch == '\r') {
|
|
|
|
ch = Peek(aErrorCode);
|
|
|
|
if (ch == '\n') {
|
|
|
|
ch = Read(aErrorCode);
|
|
|
|
}
|
|
|
|
}
|
1999-05-19 03:13:27 +04:00
|
|
|
}
|
|
|
|
}
|
2005-11-17 18:17:00 +03:00
|
|
|
NS_ASSERTION(rv >= 0, "How did rv become negative?");
|
|
|
|
if (rv > 0) {
|
|
|
|
AppendUCS4ToUTF16(ENSURE_VALID_CHAR(rv), aOutput);
|
|
|
|
}
|
|
|
|
return;
|
1998-04-14 00:24:54 +04:00
|
|
|
} 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
|
2005-11-17 18:17:00 +03:00
|
|
|
if (!EatNewline(aErrorCode)) { // skip escaped newline
|
1999-02-08 00:47:48 +03:00
|
|
|
(void) Read(aErrorCode);
|
2005-11-17 18:17:00 +03:00
|
|
|
if (ch > 0) {
|
|
|
|
aOutput.Append(ch);
|
|
|
|
}
|
1999-02-08 00:47:48 +03:00
|
|
|
}
|
2005-11-17 18:17:00 +03:00
|
|
|
return;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gather up the characters in an identifier. The identfier was
|
|
|
|
* started by "aChar" which will be appended to aIdent. The result
|
|
|
|
* will be aIdent with all of the identifier characters appended
|
|
|
|
* until the first non-identifier character is seen. The termination
|
|
|
|
* character is unread for the future re-reading.
|
|
|
|
*/
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool nsCSSScanner::GatherIdent(nsresult& aErrorCode, PRInt32 aChar,
|
1998-04-14 00:24:54 +04:00
|
|
|
nsString& aIdent)
|
|
|
|
{
|
|
|
|
if (aChar == CSS_ESCAPE) {
|
2005-11-17 18:17:00 +03:00
|
|
|
ParseAndAppendEscape(aErrorCode, aIdent);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2005-11-17 18:17:00 +03:00
|
|
|
else if (0 < aChar) {
|
|
|
|
aIdent.Append(aChar);
|
1999-05-19 03:13:27 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
for (;;) {
|
|
|
|
aChar = Read(aErrorCode);
|
|
|
|
if (aChar < 0) break;
|
|
|
|
if (aChar == CSS_ESCAPE) {
|
2005-11-17 18:17:00 +03:00
|
|
|
ParseAndAppendEscape(aErrorCode, aIdent);
|
2007-03-23 02:01:14 +03:00
|
|
|
} else if ((aChar > 255) || ((gLexTable[aChar] & IS_IDENT) != 0)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
aIdent.Append(PRUnichar(aChar));
|
|
|
|
} else {
|
2007-03-23 02:01:14 +03:00
|
|
|
Unread();
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2005-07-20 00:49:34 +04:00
|
|
|
PRBool nsCSSScanner::ParseRef(nsresult& aErrorCode,
|
|
|
|
PRInt32 aChar,
|
|
|
|
nsCSSToken& aToken)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-10-27 02:22:40 +03:00
|
|
|
aToken.mIdent.SetLength(0);
|
2005-07-20 00:49:34 +04:00
|
|
|
aToken.mType = eCSSToken_Ref;
|
2005-08-27 09:59:51 +04:00
|
|
|
PRInt32 ch = Read(aErrorCode);
|
2005-07-20 00:49:34 +04:00
|
|
|
if (ch < 0) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
if (ch > 255 || (gLexTable[ch] & IS_IDENT) || ch == CSS_ESCAPE) {
|
2005-07-20 00:49:34 +04:00
|
|
|
// First char after the '#' is a valid ident char (or an escape),
|
|
|
|
// so it makes sense to keep going
|
2007-03-23 02:01:14 +03:00
|
|
|
if (StartsIdent(ch, Peek(aErrorCode), gLexTable)) {
|
2005-07-20 00:49:34 +04:00
|
|
|
aToken.mType = eCSSToken_ID;
|
|
|
|
}
|
|
|
|
return GatherIdent(aErrorCode, ch, aToken.mIdent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// No ident chars after the '#'. Just unread |ch| and get out of here.
|
2007-03-23 02:01:14 +03:00
|
|
|
Unread();
|
2005-07-20 00:49:34 +04:00
|
|
|
return PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool nsCSSScanner::ParseIdent(nsresult& aErrorCode,
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 aChar,
|
1998-10-27 02:22:40 +03:00
|
|
|
nsCSSToken& aToken)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-10-27 02:22:40 +03:00
|
|
|
nsString& ident = aToken.mIdent;
|
1998-04-14 00:24:54 +04:00
|
|
|
ident.SetLength(0);
|
|
|
|
if (!GatherIdent(aErrorCode, aChar, ident)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSTokenType tokenType = eCSSToken_Ident;
|
1998-10-27 02:22:40 +03:00
|
|
|
// look for functions (ie: "ident(")
|
|
|
|
if (PRUnichar('(') == PRUnichar(Peek(aErrorCode))) { // this is a function definition
|
|
|
|
tokenType = eCSSToken_Function;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
|
|
|
|
aToken.mType = tokenType;
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool nsCSSScanner::ParseAtKeyword(nsresult& aErrorCode, PRInt32 aChar,
|
1998-10-27 02:22:40 +03:00
|
|
|
nsCSSToken& aToken)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-10-27 02:22:40 +03:00
|
|
|
aToken.mIdent.SetLength(0);
|
|
|
|
aToken.mType = eCSSToken_AtKeyword;
|
1999-05-19 03:13:27 +04:00
|
|
|
return GatherIdent(aErrorCode, 0, aToken.mIdent);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool nsCSSScanner::ParseNumber(nsresult& aErrorCode, PRInt32 c,
|
1998-10-27 02:22:40 +03:00
|
|
|
nsCSSToken& aToken)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-10-27 02:22:40 +03:00
|
|
|
nsString& ident = aToken.mIdent;
|
1998-04-14 00:24:54 +04:00
|
|
|
ident.SetLength(0);
|
|
|
|
PRBool gotDot = (c == '.') ? PR_TRUE : PR_FALSE;
|
|
|
|
if (c != '+') {
|
|
|
|
ident.Append(PRUnichar(c));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gather up characters that make up the number
|
2007-03-23 02:01:14 +03:00
|
|
|
PRUint8* lexTable = gLexTable;
|
1998-04-14 00:24:54 +04:00
|
|
|
for (;;) {
|
|
|
|
c = Read(aErrorCode);
|
|
|
|
if (c < 0) break;
|
2005-08-31 20:15:58 +04:00
|
|
|
if (!gotDot && (c == '.') &&
|
2007-03-23 02:01:14 +03:00
|
|
|
CheckLexTable(Peek(aErrorCode), IS_DIGIT, lexTable)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
gotDot = PR_TRUE;
|
2007-03-23 02:01:14 +03:00
|
|
|
} else if ((c > 255) || ((lexTable[c] & IS_DIGIT) == 0)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
ident.Append(PRUnichar(c));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert number to floating point
|
|
|
|
nsCSSTokenType type = eCSSToken_Number;
|
|
|
|
PRInt32 ec;
|
|
|
|
float value = ident.ToFloat(&ec);
|
|
|
|
|
|
|
|
// Look at character that terminated the number
|
1998-10-27 02:22:40 +03:00
|
|
|
aToken.mIntegerValid = PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
if (c >= 0) {
|
2007-03-23 02:01:14 +03:00
|
|
|
if ((c <= 255) && ((lexTable[c] & START_IDENT) != 0)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
ident.SetLength(0);
|
|
|
|
if (!GatherIdent(aErrorCode, c, ident)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
type = eCSSToken_Dimension;
|
|
|
|
} else if ('%' == c) {
|
|
|
|
type = eCSSToken_Percentage;
|
|
|
|
value = value / 100.0f;
|
1999-02-11 09:42:02 +03:00
|
|
|
ident.SetLength(0);
|
1998-04-14 00:24:54 +04:00
|
|
|
} else {
|
|
|
|
// Put back character that stopped numeric scan
|
2007-03-23 02:01:14 +03:00
|
|
|
Unread();
|
1998-04-14 00:24:54 +04:00
|
|
|
if (!gotDot) {
|
1998-10-27 02:22:40 +03:00
|
|
|
aToken.mInteger = ident.ToInteger(&ec);
|
|
|
|
aToken.mIntegerValid = PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
ident.SetLength(0);
|
|
|
|
}
|
|
|
|
}
|
1999-02-11 09:42:02 +03:00
|
|
|
else { // stream ended
|
|
|
|
if (!gotDot) {
|
|
|
|
aToken.mInteger = ident.ToInteger(&ec);
|
|
|
|
aToken.mIntegerValid = PR_TRUE;
|
|
|
|
}
|
|
|
|
ident.SetLength(0);
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
aToken.mNumber = value;
|
|
|
|
aToken.mType = type;
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool nsCSSScanner::SkipCComment(nsresult& aErrorCode)
|
2003-01-13 10:19:49 +03:00
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
PRInt32 ch = Read(aErrorCode);
|
|
|
|
if (ch < 0) break;
|
|
|
|
if (ch == '*') {
|
|
|
|
if (LookAhead(aErrorCode, '/')) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-12 22:44:14 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PECommentEOF);
|
2003-01-13 10:19:49 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool nsCSSScanner::ParseCComment(nsresult& aErrorCode, nsCSSToken& aToken)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-10-27 02:22:40 +03:00
|
|
|
nsString& ident = aToken.mIdent;
|
1998-04-14 00:24:54 +04:00
|
|
|
for (;;) {
|
|
|
|
PRInt32 ch = Read(aErrorCode);
|
|
|
|
if (ch < 0) break;
|
|
|
|
if (ch == '*') {
|
|
|
|
if (LookAhead(aErrorCode, '/')) {
|
2001-12-16 14:58:03 +03:00
|
|
|
ident.Append(PRUnichar(ch));
|
|
|
|
ident.Append(PRUnichar('/'));
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef COLLECT_WHITESPACE
|
|
|
|
ident.Append(PRUnichar(ch));
|
|
|
|
#endif
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
aToken.mType = eCSSToken_WhiteSpace;
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2003-01-13 10:19:49 +03:00
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-04-27 04:12:25 +04:00
|
|
|
#if 0
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool nsCSSScanner::ParseEOLComment(nsresult& aErrorCode, nsCSSToken& aToken)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-10-27 02:22:40 +03:00
|
|
|
nsString& ident = aToken.mIdent;
|
1998-04-14 00:24:54 +04:00
|
|
|
ident.SetLength(0);
|
|
|
|
for (;;) {
|
|
|
|
if (EatNewline(aErrorCode)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PRInt32 ch = Read(aErrorCode);
|
|
|
|
if (ch < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#ifdef COLLECT_WHITESPACE
|
|
|
|
ident.Append(PRUnichar(ch));
|
|
|
|
#endif
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
aToken.mType = eCSSToken_WhiteSpace;
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2000-04-27 04:12:25 +04:00
|
|
|
#endif // 0
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2005-03-18 09:56:56 +03:00
|
|
|
PRBool nsCSSScanner::ParseString(nsresult& aErrorCode, PRInt32 aStop,
|
|
|
|
nsCSSToken& aToken)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2005-03-18 09:56:56 +03:00
|
|
|
aToken.mIdent.SetLength(0);
|
|
|
|
aToken.mType = eCSSToken_String;
|
|
|
|
aToken.mSymbol = PRUnichar(aStop); // remember how it's quoted
|
1998-04-14 00:24:54 +04:00
|
|
|
for (;;) {
|
2007-03-23 02:01:14 +03:00
|
|
|
if (EatNewline(aErrorCode)) {
|
|
|
|
aToken.mType = eCSSToken_Error;
|
2005-03-18 09:56:56 +03:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
2007-03-23 02:01:14 +03:00
|
|
|
ReportUnexpectedToken(aToken, "SEUnterminatedString");
|
2005-03-18 09:56:56 +03:00
|
|
|
#endif
|
2007-03-23 02:01:14 +03:00
|
|
|
return PR_TRUE;
|
1999-02-08 00:47:48 +03:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 ch = Read(aErrorCode);
|
2007-03-23 02:01:14 +03:00
|
|
|
if (ch < 0) {
|
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
if (ch == aStop) {
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ch == CSS_ESCAPE) {
|
2005-11-17 18:17:00 +03:00
|
|
|
ParseAndAppendEscape(aErrorCode, aToken.mIdent);
|
2007-03-23 02:01:14 +03:00
|
|
|
}
|
|
|
|
else if (0 < ch) {
|
2005-11-17 18:17:00 +03:00
|
|
|
aToken.mIdent.Append(ch);
|
1999-02-08 00:47:48 +03:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|