2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-10-11 05:50:08 +00:00
|
|
|
|
|
|
|
|
2006-03-25 05:47:31 +00:00
|
|
|
/* tokenization of CSS style sheets */
|
|
|
|
|
2011-05-19 22:44:14 +00:00
|
|
|
#include <math.h> // must be first due to symbol conflicts
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsCSSScanner.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCRT.h"
|
2011-05-19 22:44:14 +00:00
|
|
|
#include "mozilla/Util.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2001-03-06 01:57:30 +00:00
|
|
|
// for #ifdef CSS_REPORT_PARSE_ERRORS
|
2000-09-06 02:27:46 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2000-09-08 02:05:09 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsIComponentManager.h"
|
2000-09-08 02:05:09 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2000-09-06 02:27:46 +00:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIScriptError.h"
|
2004-10-12 18:44:14 +00:00
|
|
|
#include "nsIStringBundle.h"
|
2011-05-28 23:42:57 +00:00
|
|
|
#include "nsIDocument.h"
|
2010-05-14 09:24:41 +00:00
|
|
|
#include "mozilla/Services.h"
|
2010-12-20 16:21:59 +00:00
|
|
|
#include "mozilla/css/Loader.h"
|
|
|
|
#include "nsCSSStyleSheet.h"
|
2011-05-25 06:31:59 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2000-09-06 02:27:46 +00:00
|
|
|
|
2004-09-30 05:18:05 +00:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool gReportErrors = true;
|
2004-09-30 05:18:05 +00:00
|
|
|
static nsIConsoleService *gConsoleService;
|
|
|
|
static nsIFactory *gScriptErrorFactory;
|
2004-10-12 18:44:14 +00:00
|
|
|
static nsIStringBundle *gStringBundle;
|
2004-09-30 05:18:05 +00:00
|
|
|
#endif
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static const uint8_t IS_HEX_DIGIT = 0x01;
|
|
|
|
static const uint8_t START_IDENT = 0x02;
|
|
|
|
static const uint8_t IS_IDENT = 0x04;
|
|
|
|
static const uint8_t IS_WHITESPACE = 0x08;
|
|
|
|
static const uint8_t IS_URL_CHAR = 0x10;
|
2009-10-15 20:18:21 +00:00
|
|
|
|
2012-05-14 23:01:05 +00:00
|
|
|
#define W IS_WHITESPACE
|
|
|
|
#define I IS_IDENT
|
|
|
|
#define U IS_URL_CHAR
|
|
|
|
#define S START_IDENT
|
|
|
|
#define UI IS_IDENT |IS_URL_CHAR
|
|
|
|
#define USI IS_IDENT|START_IDENT |IS_URL_CHAR
|
|
|
|
#define UXI IS_IDENT |IS_HEX_DIGIT|IS_URL_CHAR
|
|
|
|
#define UXSI IS_IDENT|START_IDENT|IS_HEX_DIGIT|IS_URL_CHAR
|
2009-10-15 20:18:21 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static const uint8_t gLexTable[] = {
|
2009-10-15 20:18:21 +00:00
|
|
|
// TAB LF FF CR
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, W, W, 0, W, W, 0, 0,
|
|
|
|
//
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
// SPC ! " # $ % & ' ( ) * + , - . /
|
2012-05-14 23:01:05 +00:00
|
|
|
W, U, 0, U, U, U, U, 0, 0, 0, U, U, U, UI, U, U,
|
2009-10-15 20:18:21 +00:00
|
|
|
// 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
|
2012-05-14 23:01:05 +00:00
|
|
|
UXI,UXI,UXI,UXI,UXI,UXI,UXI,UXI,UXI,UXI,U, U, U, U, U, U,
|
|
|
|
// @ A B C D E F G H I J K L M N O
|
|
|
|
U,UXSI,UXSI,UXSI,UXSI,UXSI,UXSI,USI,USI,USI,USI,USI,USI,USI,USI,USI,
|
2009-10-15 20:18:21 +00:00
|
|
|
// P Q R S T U V W X Y Z [ \ ] ^ _
|
2012-05-14 23:01:05 +00:00
|
|
|
USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,U, S, U, U, USI,
|
|
|
|
// ` a b c d e f g h i j k l m n o
|
|
|
|
U,UXSI,UXSI,UXSI,UXSI,UXSI,UXSI,USI,USI,USI,USI,USI,USI,USI,USI,USI,
|
2009-10-15 20:18:21 +00:00
|
|
|
// p q r s t u v w x y z { | } ~
|
2012-05-14 23:01:05 +00:00
|
|
|
USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,U, U, U, U, 0,
|
2011-04-17 21:13:15 +00:00
|
|
|
// U+008*
|
2009-10-15 20:18:21 +00:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2011-04-17 21:13:15 +00:00
|
|
|
// U+009*
|
2009-10-15 20:18:21 +00:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2011-04-17 21:13:15 +00:00
|
|
|
// U+00A*
|
2012-05-14 23:01:05 +00:00
|
|
|
USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,
|
2011-04-17 21:13:15 +00:00
|
|
|
// U+00B*
|
2012-05-14 23:01:05 +00:00
|
|
|
USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,
|
2011-04-17 21:13:15 +00:00
|
|
|
// U+00C*
|
2012-05-14 23:01:05 +00:00
|
|
|
USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,
|
2011-04-17 21:13:15 +00:00
|
|
|
// U+00D*
|
2012-05-14 23:01:05 +00:00
|
|
|
USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,
|
2011-04-17 21:13:15 +00:00
|
|
|
// U+00E*
|
2012-05-14 23:01:05 +00:00
|
|
|
USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,
|
2011-04-17 21:13:15 +00:00
|
|
|
// U+00F*
|
2012-05-14 23:01:05 +00:00
|
|
|
USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI,USI
|
2009-10-15 20:18:21 +00:00
|
|
|
};
|
|
|
|
|
2012-02-23 16:19:00 +00:00
|
|
|
MOZ_STATIC_ASSERT(NS_ARRAY_LENGTH(gLexTable) == 256,
|
|
|
|
"gLexTable expected to cover all 2^8 possible PRUint8s");
|
2011-04-17 21:13:15 +00:00
|
|
|
|
2009-10-15 20:18:21 +00:00
|
|
|
#undef W
|
|
|
|
#undef S
|
|
|
|
#undef I
|
2012-05-14 23:01:05 +00:00
|
|
|
#undef U
|
|
|
|
#undef UI
|
|
|
|
#undef USI
|
|
|
|
#undef UXI
|
|
|
|
#undef UXSI
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static inline bool
|
2012-08-22 15:56:38 +00:00
|
|
|
IsIdentStart(int32_t aChar)
|
2008-09-10 04:38:29 +00:00
|
|
|
{
|
|
|
|
return aChar >= 0 &&
|
|
|
|
(aChar >= 256 || (gLexTable[aChar] & START_IDENT) != 0);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static inline bool
|
2012-08-22 15:56:38 +00:00
|
|
|
StartsIdent(int32_t aFirstChar, int32_t aSecondChar)
|
2008-09-10 04:38:29 +00:00
|
|
|
{
|
|
|
|
return IsIdentStart(aFirstChar) ||
|
|
|
|
(aFirstChar == '-' && IsIdentStart(aSecondChar));
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static inline bool
|
2012-08-22 15:56:38 +00:00
|
|
|
IsWhitespace(int32_t ch) {
|
|
|
|
return uint32_t(ch) < 256 && (gLexTable[ch] & IS_WHITESPACE) != 0;
|
2008-09-10 04:38:29 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static inline bool
|
2012-08-22 15:56:38 +00:00
|
|
|
IsDigit(int32_t ch) {
|
2009-09-04 12:25:27 +00:00
|
|
|
return (ch >= '0') && (ch <= '9');
|
2008-09-10 04:38:29 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static inline bool
|
2012-08-22 15:56:38 +00:00
|
|
|
IsHexDigit(int32_t ch) {
|
|
|
|
return uint32_t(ch) < 256 && (gLexTable[ch] & IS_HEX_DIGIT) != 0;
|
2008-09-10 04:38:29 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static inline bool
|
2012-08-22 15:56:38 +00:00
|
|
|
IsIdent(int32_t ch) {
|
2008-09-10 04:38:29 +00:00
|
|
|
return ch >= 0 && (ch >= 256 || (gLexTable[ch] & IS_IDENT) != 0);
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:01:05 +00:00
|
|
|
static inline bool
|
2012-08-22 15:56:38 +00:00
|
|
|
IsURLChar(int32_t ch) {
|
2012-05-14 23:01:05 +00:00
|
|
|
return ch >= 0 && (ch >= 256 || (gLexTable[ch] & IS_URL_CHAR) != 0);
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static inline uint32_t
|
|
|
|
DecimalDigitValue(int32_t ch)
|
2009-08-20 21:52:47 +00:00
|
|
|
{
|
|
|
|
return ch - '0';
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static inline uint32_t
|
|
|
|
HexDigitValue(int32_t ch)
|
2009-08-20 21:52:47 +00:00
|
|
|
{
|
|
|
|
if (IsDigit(ch)) {
|
|
|
|
return DecimalDigitValue(ch);
|
|
|
|
} 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.
|
|
|
|
return (ch & 0x7) + 9;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
nsCSSToken::nsCSSToken()
|
|
|
|
{
|
|
|
|
mType = eCSSToken_Symbol;
|
|
|
|
}
|
|
|
|
|
2009-08-20 21:52:47 +00:00
|
|
|
void
|
1999-02-07 21:47:48 +00:00
|
|
|
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_HTMLComment:
|
2009-08-20 21:52:47 +00:00
|
|
|
case eCSSToken_URange:
|
1999-02-07 21:47:48 +00:00
|
|
|
aBuffer.Append(mIdent);
|
2010-01-28 00:20:04 +00:00
|
|
|
if (mType == eCSSToken_Function)
|
|
|
|
aBuffer.Append(PRUnichar('('));
|
1999-02-07 21:47:48 +00:00
|
|
|
break;
|
2011-03-11 17:29:45 +00:00
|
|
|
case eCSSToken_URL:
|
|
|
|
case eCSSToken_Bad_URL:
|
2011-03-11 17:29:45 +00:00
|
|
|
aBuffer.AppendLiteral("url(");
|
2011-03-11 17:29:45 +00:00
|
|
|
if (mSymbol != PRUnichar(0)) {
|
|
|
|
aBuffer.Append(mSymbol);
|
|
|
|
}
|
|
|
|
aBuffer.Append(mIdent);
|
|
|
|
if (mSymbol != PRUnichar(0)) {
|
|
|
|
aBuffer.Append(mSymbol);
|
|
|
|
}
|
|
|
|
if (mType == eCSSToken_URL) {
|
|
|
|
aBuffer.Append(PRUnichar(')'));
|
|
|
|
}
|
|
|
|
break;
|
1999-02-07 21:47:48 +00:00
|
|
|
case eCSSToken_Number:
|
|
|
|
if (mIntegerValid) {
|
2000-04-15 20:15:37 +00:00
|
|
|
aBuffer.AppendInt(mInteger, 10);
|
1999-02-07 21:47:48 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-04-15 20:15:37 +00:00
|
|
|
aBuffer.AppendFloat(mNumber);
|
1999-02-07 21:47:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case eCSSToken_Percentage:
|
2003-03-18 05:43:12 +00:00
|
|
|
NS_ASSERTION(!mIntegerValid, "How did a percentage token get this set?");
|
|
|
|
aBuffer.AppendFloat(mNumber * 100.0f);
|
2011-05-19 22:44:14 +00:00
|
|
|
aBuffer.Append(PRUnichar('%'));
|
1999-02-07 21:47:48 +00:00
|
|
|
break;
|
|
|
|
case eCSSToken_Dimension:
|
|
|
|
if (mIntegerValid) {
|
2000-04-15 20:15:37 +00:00
|
|
|
aBuffer.AppendInt(mInteger, 10);
|
1999-02-07 21:47:48 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-04-15 20:15:37 +00:00
|
|
|
aBuffer.AppendFloat(mNumber);
|
1999-02-07 21:47:48 +00: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-19 20:49:34 +00:00
|
|
|
case eCSSToken_Ref:
|
1999-02-07 21:47:48 +00:00
|
|
|
aBuffer.Append(PRUnichar('#'));
|
|
|
|
aBuffer.Append(mIdent);
|
|
|
|
break;
|
2000-04-27 00:12:25 +00:00
|
|
|
case eCSSToken_Includes:
|
2004-06-17 00:13:25 +00:00
|
|
|
aBuffer.AppendLiteral("~=");
|
2000-04-27 00:12:25 +00:00
|
|
|
break;
|
|
|
|
case eCSSToken_Dashmatch:
|
2004-06-17 00:13:25 +00:00
|
|
|
aBuffer.AppendLiteral("|=");
|
2000-04-27 00:12:25 +00:00
|
|
|
break;
|
2008-07-11 22:49:46 +00:00
|
|
|
case eCSSToken_Beginsmatch:
|
|
|
|
aBuffer.AppendLiteral("^=");
|
|
|
|
break;
|
|
|
|
case eCSSToken_Endsmatch:
|
|
|
|
aBuffer.AppendLiteral("$=");
|
|
|
|
break;
|
|
|
|
case eCSSToken_Containsmatch:
|
|
|
|
aBuffer.AppendLiteral("*=");
|
|
|
|
break;
|
2011-03-11 17:29:44 +00:00
|
|
|
case eCSSToken_Bad_String:
|
2005-03-18 06:56:56 +00:00
|
|
|
aBuffer.Append(mSymbol);
|
|
|
|
aBuffer.Append(mIdent);
|
|
|
|
break;
|
1999-02-07 21:47:48 +00:00
|
|
|
default:
|
|
|
|
NS_ERROR("invalid token type");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
nsCSSScanner::nsCSSScanner()
|
2012-07-30 14:20:58 +00:00
|
|
|
: mReadPointer(nullptr)
|
2011-10-17 14:59:28 +00:00
|
|
|
, mSVGMode(false)
|
2005-01-22 04:52:05 +00:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
2011-10-11 05:50:08 +00:00
|
|
|
, mError(mErrorBuf, ArrayLength(mErrorBuf), 0)
|
2011-08-24 20:44:35 +00:00
|
|
|
, mInnerWindowID(0)
|
2011-10-17 14:59:28 +00:00
|
|
|
, mWindowIDCached(false)
|
2012-07-30 14:20:58 +00:00
|
|
|
, mSheet(nullptr)
|
|
|
|
, mLoader(nullptr)
|
2005-01-22 04:52:05 +00:00
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_CTOR(nsCSSScanner);
|
1998-09-25 01:50:51 +00:00
|
|
|
mPushback = mLocalPushback;
|
2011-10-11 05:50:08 +00:00
|
|
|
mPushbackSize = ArrayLength(mLocalPushback);
|
2004-10-14 03:30:55 +00: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-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSScanner::~nsCSSScanner()
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_DTOR(nsCSSScanner);
|
1998-04-13 20:24:54 +00:00
|
|
|
Close();
|
1998-09-25 01:50:51 +00:00
|
|
|
if (mLocalPushback != mPushback) {
|
|
|
|
delete [] mPushback;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2005-12-27 22:03:29 +00:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
|
|
|
#define CSS_ERRORS_PREF "layout.css.report_errors"
|
|
|
|
|
2008-10-10 15:04:34 +00:00
|
|
|
static int
|
2008-09-10 04:38:14 +00:00
|
|
|
CSSErrorsPrefChanged(const char *aPref, void *aClosure)
|
2005-12-27 22:03:29 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
gReportErrors = Preferences::GetBool(CSS_ERRORS_PREF, true);
|
2012-08-07 15:11:35 +00:00
|
|
|
return 0;
|
2005-12-27 22:03:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
/* static */ bool
|
2008-09-10 04:38:14 +00:00
|
|
|
nsCSSScanner::InitGlobals()
|
2004-09-30 05:18:05 +00:00
|
|
|
{
|
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
|
|
|
if (gConsoleService && gScriptErrorFactory)
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2004-09-30 05:18:05 +00:00
|
|
|
|
|
|
|
nsresult rv = CallGetService(NS_CONSOLESERVICE_CONTRACTID, &gConsoleService);
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2004-09-30 05:18:05 +00:00
|
|
|
|
2004-10-02 00:44:13 +00:00
|
|
|
rv = CallGetClassObject(NS_SCRIPTERROR_CONTRACTID, &gScriptErrorFactory);
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2004-09-30 05:18:05 +00:00
|
|
|
NS_ASSERTION(gConsoleService && gScriptErrorFactory,
|
|
|
|
"unexpected null pointer without failure");
|
2005-12-27 22:03:29 +00:00
|
|
|
|
2011-05-28 23:42:57 +00:00
|
|
|
Preferences::RegisterCallback(CSSErrorsPrefChanged, CSS_ERRORS_PREF);
|
2012-07-30 14:20:58 +00:00
|
|
|
CSSErrorsPrefChanged(CSS_ERRORS_PREF, nullptr);
|
2004-09-30 05:18:05 +00:00
|
|
|
#endif
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2004-09-30 05:18:05 +00:00
|
|
|
}
|
|
|
|
|
2008-09-10 04:38:14 +00:00
|
|
|
/* static */ void
|
|
|
|
nsCSSScanner::ReleaseGlobals()
|
2004-09-30 05:18:05 +00:00
|
|
|
{
|
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
2011-05-28 23:42:57 +00:00
|
|
|
Preferences::UnregisterCallback(CSSErrorsPrefChanged, CSS_ERRORS_PREF);
|
2004-09-30 05:18:05 +00:00
|
|
|
NS_IF_RELEASE(gConsoleService);
|
|
|
|
NS_IF_RELEASE(gScriptErrorFactory);
|
2004-10-12 18:44:14 +00:00
|
|
|
NS_IF_RELEASE(gStringBundle);
|
2004-09-30 05:18:05 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-09-10 04:38:14 +00:00
|
|
|
void
|
2011-05-18 17:33:16 +00:00
|
|
|
nsCSSScanner::Init(const nsAString& aBuffer,
|
2012-08-22 15:56:38 +00:00
|
|
|
nsIURI* aURI, uint32_t aLineNumber,
|
2010-12-20 16:21:59 +00:00
|
|
|
nsCSSStyleSheet* aSheet, mozilla::css::Loader* aLoader)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2005-11-10 22:26:06 +00:00
|
|
|
NS_PRECONDITION(!mReadPointer, "Should not have an existing input buffer!");
|
|
|
|
|
2011-05-18 17:33:16 +00:00
|
|
|
mReadPointer = aBuffer.BeginReading();
|
|
|
|
mCount = aBuffer.Length();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2000-09-06 02:27:46 +00:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
2004-10-14 03:30:55 +00: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 01:49:06 +00:00
|
|
|
mFileName.Adopt(NS_strdup("from DOM"));
|
2004-10-14 03:30:55 +00:00
|
|
|
}
|
2000-09-06 02:27:46 +00:00
|
|
|
}
|
2001-03-06 01:57:30 +00:00
|
|
|
#endif // CSS_REPORT_PARSE_ERRORS
|
2004-09-09 17:32:35 +00:00
|
|
|
mLineNumber = aLineNumber;
|
2004-10-14 03:30:55 +00:00
|
|
|
|
2005-11-10 22:26:06 +00:00
|
|
|
// Reset variables that we use to keep track of our progress through the input
|
2004-10-14 03:30:55 +00:00
|
|
|
mOffset = 0;
|
|
|
|
mPushbackCount = 0;
|
2012-08-02 00:32:12 +00:00
|
|
|
mRecording = false;
|
2004-10-14 03:30:55 +00:00
|
|
|
|
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
|
|
|
mColNumber = 0;
|
2010-12-20 16:21:59 +00:00
|
|
|
mSheet = aSheet;
|
|
|
|
mLoader = aLoader;
|
2004-10-14 03:30:55 +00:00
|
|
|
#endif
|
2000-09-06 02:27:46 +00:00
|
|
|
}
|
|
|
|
|
2001-03-06 01:57:30 +00:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
|
|
|
|
2003-01-13 07:19:49 +00:00
|
|
|
// @see REPORT_UNEXPECTED_EOF in nsCSSParser.cpp
|
2004-10-12 18:44:14 +00:00
|
|
|
#define REPORT_UNEXPECTED_EOF(lf_) \
|
|
|
|
ReportUnexpectedEOF(#lf_)
|
2003-01-13 07:19:49 +00:00
|
|
|
|
2008-09-10 04:38:14 +00:00
|
|
|
void
|
|
|
|
nsCSSScanner::AddToError(const nsSubstring& aErrorText)
|
2000-09-06 02:27:46 +00:00
|
|
|
{
|
2002-01-24 02:03:19 +00:00
|
|
|
if (mError.IsEmpty()) {
|
2001-03-06 01:57:30 +00:00
|
|
|
mErrorLineNumber = mLineNumber;
|
|
|
|
mErrorColNumber = mColNumber;
|
|
|
|
mError = aErrorText;
|
|
|
|
} else {
|
2004-09-30 05:18:05 +00:00
|
|
|
mError.Append(NS_LITERAL_STRING(" ") + aErrorText);
|
2001-03-06 01:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-10 04:38:14 +00:00
|
|
|
void
|
|
|
|
nsCSSScanner::ClearError()
|
2001-03-06 01:57:30 +00:00
|
|
|
{
|
|
|
|
mError.Truncate();
|
|
|
|
}
|
|
|
|
|
2008-09-10 04:38:14 +00:00
|
|
|
void
|
|
|
|
nsCSSScanner::OutputError()
|
2001-03-06 01:57:30 +00:00
|
|
|
{
|
2002-01-24 02:03:19 +00:00
|
|
|
if (mError.IsEmpty()) return;
|
2001-03-06 01:57:30 +00:00
|
|
|
|
2006-05-25 21:22:32 +00:00
|
|
|
// Log it to the Error console
|
2000-09-06 02:27:46 +00:00
|
|
|
|
2005-12-27 22:03:29 +00:00
|
|
|
if (InitGlobals() && gReportErrors) {
|
2010-12-20 16:21:59 +00:00
|
|
|
if (!mWindowIDCached) {
|
|
|
|
if (mSheet) {
|
2011-08-24 20:44:35 +00:00
|
|
|
mInnerWindowID = mSheet->FindOwningWindowInnerID();
|
2010-12-20 16:21:59 +00:00
|
|
|
}
|
2011-08-24 20:44:35 +00:00
|
|
|
if (mInnerWindowID == 0 && mLoader) {
|
2010-12-20 16:21:59 +00:00
|
|
|
nsIDocument* doc = mLoader->GetDocument();
|
|
|
|
if (doc) {
|
2011-08-24 20:44:35 +00:00
|
|
|
mInnerWindowID = doc->InnerWindowID();
|
2010-12-20 16:21:59 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
mWindowIDCached = true;
|
2010-12-20 16:21:59 +00:00
|
|
|
}
|
|
|
|
|
2004-10-02 00:44:13 +00:00
|
|
|
nsresult rv;
|
2011-12-21 21:51:29 +00:00
|
|
|
nsCOMPtr<nsIScriptError> errorObject =
|
2004-10-02 00:44:13 +00:00
|
|
|
do_CreateInstance(gScriptErrorFactory, &rv);
|
2010-12-20 16:21:59 +00:00
|
|
|
|
2004-09-30 05:18:05 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2010-12-20 16:21:59 +00:00
|
|
|
rv = errorObject->InitWithWindowID(mError.get(),
|
|
|
|
NS_ConvertUTF8toUTF16(mFileName).get(),
|
|
|
|
EmptyString().get(),
|
|
|
|
mErrorLineNumber,
|
|
|
|
mErrorColNumber,
|
|
|
|
nsIScriptError::warningFlag,
|
2011-08-24 20:44:35 +00:00
|
|
|
"CSS Parser",
|
|
|
|
mInnerWindowID);
|
2010-12-20 16:21:59 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-12-21 21:51:29 +00:00
|
|
|
gConsoleService->LogMessage(errorObject);
|
2010-12-20 16:21:59 +00:00
|
|
|
}
|
2004-09-30 05:18:05 +00:00
|
|
|
}
|
2000-09-06 02:27:46 +00:00
|
|
|
}
|
2001-03-06 01:57:30 +00:00
|
|
|
ClearError();
|
2000-09-06 02:27:46 +00:00
|
|
|
}
|
2004-10-12 18:44:14 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2008-09-10 04:38:14 +00:00
|
|
|
InitStringBundle()
|
2004-10-12 18:44:14 +00:00
|
|
|
{
|
|
|
|
if (gStringBundle)
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2004-10-12 18:44:14 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIStringBundleService> sbs =
|
2010-05-14 09:24:41 +00:00
|
|
|
mozilla::services::GetStringBundleService();
|
2004-10-12 18:44:14 +00:00
|
|
|
if (!sbs)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2004-10-12 18:44:14 +00:00
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
sbs->CreateBundle("chrome://global/locale/css.properties", &gStringBundle);
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-07-30 14:20:58 +00:00
|
|
|
gStringBundle = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2004-10-12 18:44:14 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2004-10-12 18:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
2008-09-10 04:38:14 +00:00
|
|
|
void
|
|
|
|
nsCSSScanner::ReportUnexpectedParams(const char* aMessage,
|
|
|
|
const PRUnichar **aParams,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aParamsLength)
|
2004-10-12 18:44:14 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-07-19 22:52:09 +00:00
|
|
|
// aLookingFor is a plain string, not a format string
|
2008-09-10 04:38:14 +00:00
|
|
|
void
|
|
|
|
nsCSSScanner::ReportUnexpectedEOF(const char* aLookingFor)
|
2004-10-12 18:44:14 +00:00
|
|
|
{
|
|
|
|
ENSURE_STRINGBUNDLE;
|
|
|
|
|
|
|
|
nsXPIDLString innerStr;
|
|
|
|
gStringBundle->GetStringFromName(NS_ConvertASCIItoUTF16(aLookingFor).get(),
|
|
|
|
getter_Copies(innerStr));
|
|
|
|
|
|
|
|
const PRUnichar *params[] = {
|
|
|
|
innerStr.get()
|
|
|
|
};
|
|
|
|
nsXPIDLString str;
|
2007-01-23 22:49:49 +00:00
|
|
|
gStringBundle->FormatStringFromName(NS_LITERAL_STRING("PEUnexpEOF2").get(),
|
2011-10-11 05:50:08 +00:00
|
|
|
params, ArrayLength(params),
|
2004-10-12 18:44:14 +00:00
|
|
|
getter_Copies(str));
|
|
|
|
AddToError(str);
|
|
|
|
}
|
|
|
|
|
2008-07-19 22:52:09 +00:00
|
|
|
// aLookingFor is a single character
|
2008-09-10 04:38:14 +00:00
|
|
|
void
|
|
|
|
nsCSSScanner::ReportUnexpectedEOF(PRUnichar aLookingFor)
|
2008-07-19 22:52:09 +00:00
|
|
|
{
|
|
|
|
ENSURE_STRINGBUNDLE;
|
|
|
|
|
|
|
|
const PRUnichar lookingForStr[] = {
|
|
|
|
PRUnichar('\''), aLookingFor, PRUnichar('\''), PRUnichar(0)
|
|
|
|
};
|
|
|
|
const PRUnichar *params[] = { lookingForStr };
|
|
|
|
nsXPIDLString str;
|
|
|
|
gStringBundle->FormatStringFromName(NS_LITERAL_STRING("PEUnexpEOF2").get(),
|
2011-10-11 05:50:08 +00:00
|
|
|
params, ArrayLength(params),
|
2008-07-19 22:52:09 +00:00
|
|
|
getter_Copies(str));
|
|
|
|
AddToError(str);
|
|
|
|
}
|
|
|
|
|
2004-10-12 18:44:14 +00:00
|
|
|
// aMessage must take 1 parameter (for the string representation of the
|
|
|
|
// unexpected token)
|
2008-09-10 04:38:14 +00:00
|
|
|
void
|
|
|
|
nsCSSScanner::ReportUnexpectedToken(nsCSSToken& tok,
|
|
|
|
const char *aMessage)
|
2004-10-12 18:44:14 +00:00
|
|
|
{
|
|
|
|
ENSURE_STRINGBUNDLE;
|
|
|
|
|
|
|
|
nsAutoString tokenString;
|
|
|
|
tok.AppendToString(tokenString);
|
|
|
|
|
|
|
|
const PRUnichar *params[] = {
|
|
|
|
tokenString.get()
|
|
|
|
};
|
|
|
|
|
2012-03-09 02:22:57 +00:00
|
|
|
ReportUnexpectedParams(aMessage, params);
|
2004-10-12 18:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// aParams's first entry must be null, and we'll fill in the token
|
2008-09-10 04:38:14 +00:00
|
|
|
void
|
|
|
|
nsCSSScanner::ReportUnexpectedTokenParams(nsCSSToken& tok,
|
|
|
|
const char* aMessage,
|
|
|
|
const PRUnichar **aParams,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aParamsLength)
|
2004-10-12 18:44:14 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aParamsLength > 1, "use the non-params version");
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_PRECONDITION(aParams[0] == nullptr, "first param should be empty");
|
2004-10-12 18:44:14 +00:00
|
|
|
|
|
|
|
ENSURE_STRINGBUNDLE;
|
|
|
|
|
|
|
|
nsAutoString tokenString;
|
|
|
|
tok.AppendToString(tokenString);
|
|
|
|
aParams[0] = tokenString.get();
|
|
|
|
|
|
|
|
ReportUnexpectedParams(aMessage, aParams, aParamsLength);
|
|
|
|
}
|
|
|
|
|
2003-01-13 08:02:17 +00:00
|
|
|
#else
|
2004-10-12 18:44:14 +00:00
|
|
|
|
|
|
|
#define REPORT_UNEXPECTED_EOF(lf_)
|
|
|
|
|
2000-09-06 02:27:46 +00:00
|
|
|
#endif // CSS_REPORT_PARSE_ERRORS
|
|
|
|
|
2008-09-10 04:38:14 +00:00
|
|
|
void
|
|
|
|
nsCSSScanner::Close()
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
mReadPointer = nullptr;
|
2008-02-15 04:21:57 +00:00
|
|
|
|
|
|
|
// Clean things up so we don't hold on to memory if our parser gets recycled.
|
2008-02-24 07:39:47 +00:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
2008-02-15 04:21:57 +00:00
|
|
|
mFileName.Truncate();
|
2012-07-30 14:20:58 +00:00
|
|
|
mURI = nullptr;
|
2008-02-15 04:21:57 +00:00
|
|
|
mError.Truncate();
|
2011-08-24 20:44:35 +00:00
|
|
|
mInnerWindowID = 0;
|
2011-10-17 14:59:28 +00:00
|
|
|
mWindowIDCached = false;
|
2012-07-30 14:20:58 +00:00
|
|
|
mSheet = nullptr;
|
|
|
|
mLoader = nullptr;
|
2008-02-24 07:39:47 +00:00
|
|
|
#endif
|
2008-02-15 04:21:57 +00:00
|
|
|
if (mPushback != mLocalPushback) {
|
|
|
|
delete [] mPushback;
|
|
|
|
mPushback = mLocalPushback;
|
2011-10-11 05:50:08 +00:00
|
|
|
mPushbackSize = ArrayLength(mLocalPushback);
|
2008-02-15 04:21:57 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns -1 on error or eof
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
2008-09-10 04:38:14 +00:00
|
|
|
nsCSSScanner::Read()
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t rv;
|
1998-09-25 01:50:51 +00:00
|
|
|
if (0 < mPushbackCount) {
|
2012-08-22 15:56:38 +00:00
|
|
|
rv = int32_t(mPushback[--mPushbackCount]);
|
1998-04-13 20:24:54 +00:00
|
|
|
} else {
|
2011-05-18 17:33:16 +00:00
|
|
|
if (mOffset == mCount) {
|
2007-08-23 23:01:52 +00:00
|
|
|
return -1;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
rv = int32_t(mReadPointer[mOffset++]);
|
2007-08-23 23:01:52 +00:00
|
|
|
// There are four types of newlines in CSS: "\r", "\n", "\r\n", and "\f".
|
|
|
|
// To simplify dealing with newlines, they are all normalized to "\n" here
|
|
|
|
if (rv == '\r') {
|
2011-05-18 17:33:16 +00:00
|
|
|
if (mOffset < mCount && mReadPointer[mOffset] == '\n') {
|
2007-08-23 23:01:52 +00:00
|
|
|
mOffset++;
|
|
|
|
}
|
|
|
|
rv = '\n';
|
|
|
|
} else if (rv == '\f') {
|
|
|
|
rv = '\n';
|
|
|
|
}
|
|
|
|
if (rv == '\n') {
|
2004-09-10 23:31:48 +00:00
|
|
|
// 0 is a magical line number meaning that we don't know (i.e., script)
|
|
|
|
if (mLineNumber != 0)
|
|
|
|
++mLineNumber;
|
2001-01-22 04:03:48 +00:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
2000-09-06 02:27:46 +00:00
|
|
|
mColNumber = 0;
|
2011-05-19 22:44:14 +00:00
|
|
|
} else {
|
2000-09-06 02:27:46 +00:00
|
|
|
mColNumber++;
|
|
|
|
#endif
|
2011-05-19 22:44:14 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
2008-09-10 04:38:14 +00:00
|
|
|
nsCSSScanner::Peek()
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-09-25 01:50:51 +00:00
|
|
|
if (0 == mPushbackCount) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t ch = Read();
|
1998-10-26 23:22:40 +00:00
|
|
|
if (ch < 0) {
|
1998-04-13 20:24:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
1998-10-26 23:22:40 +00:00
|
|
|
mPushback[0] = PRUnichar(ch);
|
1998-09-25 01:50:51 +00:00
|
|
|
mPushbackCount++;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
return int32_t(mPushback[mPushbackCount - 1]);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2008-09-10 04:38:14 +00:00
|
|
|
void
|
|
|
|
nsCSSScanner::Pushback(PRUnichar aChar)
|
1998-09-25 01:50:51 +00:00
|
|
|
{
|
|
|
|
if (mPushbackCount == mPushbackSize) { // grow buffer
|
|
|
|
PRUnichar* newPushback = new PRUnichar[mPushbackSize + 4];
|
2012-07-30 14:20:58 +00:00
|
|
|
if (nullptr == newPushback) {
|
1998-09-25 01:50:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mPushbackSize += 4;
|
2002-01-12 03:18:55 +00:00
|
|
|
memcpy(newPushback, mPushback, sizeof(PRUnichar) * mPushbackCount);
|
1998-09-25 01:50:51 +00:00
|
|
|
if (mPushback != mLocalPushback) {
|
|
|
|
delete [] mPushback;
|
|
|
|
}
|
|
|
|
mPushback = newPushback;
|
|
|
|
}
|
|
|
|
mPushback[mPushbackCount++] = aChar;
|
|
|
|
}
|
|
|
|
|
2012-08-02 00:32:12 +00:00
|
|
|
void
|
|
|
|
nsCSSScanner::StartRecording()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mRecording, "already started recording");
|
|
|
|
mRecording = true;
|
|
|
|
mRecordStartOffset = mOffset - mPushbackCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSScanner::StopRecording()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mRecording, "haven't started recording");
|
|
|
|
mRecording = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSScanner::StopRecording(nsString& aBuffer)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mRecording, "haven't started recording");
|
|
|
|
mRecording = false;
|
|
|
|
aBuffer.Append(mReadPointer + mRecordStartOffset,
|
|
|
|
mOffset - mPushbackCount - mRecordStartOffset);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2008-09-10 04:38:14 +00:00
|
|
|
nsCSSScanner::LookAhead(PRUnichar aChar)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t ch = Read();
|
1998-04-13 20:24:54 +00:00
|
|
|
if (ch < 0) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
if (ch == aChar) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2007-08-21 18:29:50 +00:00
|
|
|
Pushback(ch);
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2011-03-11 17:29:45 +00:00
|
|
|
nsCSSScanner::LookAheadOrEOF(PRUnichar aChar)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t ch = Read();
|
2011-03-11 17:29:45 +00:00
|
|
|
if (ch < 0) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2011-03-11 17:29:45 +00:00
|
|
|
}
|
|
|
|
if (ch == aChar) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2011-03-11 17:29:45 +00:00
|
|
|
}
|
|
|
|
Pushback(ch);
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-03-11 17:29:45 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 06:46:26 +00:00
|
|
|
void
|
2008-09-10 04:38:14 +00:00
|
|
|
nsCSSScanner::EatWhiteSpace()
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
for (;;) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t ch = Read();
|
1998-04-13 20:24:54 +00:00
|
|
|
if (ch < 0) {
|
|
|
|
break;
|
|
|
|
}
|
2009-04-09 06:46:26 +00:00
|
|
|
if ((ch != ' ') && (ch != '\n') && (ch != '\t')) {
|
|
|
|
Pushback(ch);
|
|
|
|
break;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2008-09-10 04:38:14 +00:00
|
|
|
nsCSSScanner::Next(nsCSSToken& aToken)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2009-01-17 03:44:21 +00:00
|
|
|
for (;;) { // Infinite loop so we can restart after comments.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t ch = Read();
|
2009-01-17 03:44:21 +00:00
|
|
|
if (ch < 0) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2008-07-11 21:02:16 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2009-08-20 21:52:47 +00:00
|
|
|
// UNICODE-RANGE
|
|
|
|
if ((ch == 'u' || ch == 'U') && Peek() == '+')
|
|
|
|
return ParseURange(ch, aToken);
|
|
|
|
|
2009-01-17 03:44:21 +00:00
|
|
|
// IDENT
|
|
|
|
if (StartsIdent(ch, Peek()))
|
|
|
|
return ParseIdent(ch, aToken);
|
|
|
|
|
|
|
|
// AT_KEYWORD
|
|
|
|
if (ch == '@') {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t nextChar = Read();
|
2009-01-17 03:44:21 +00:00
|
|
|
if (nextChar >= 0) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t followingChar = Peek();
|
2009-01-17 03:44:21 +00:00
|
|
|
Pushback(nextChar);
|
|
|
|
if (StartsIdent(nextChar, followingChar))
|
|
|
|
return ParseAtKeyword(ch, aToken);
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2009-01-17 03:44:21 +00:00
|
|
|
|
|
|
|
// NUMBER or DIM
|
|
|
|
if ((ch == '.') || (ch == '+') || (ch == '-')) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t nextChar = Peek();
|
2009-01-17 03:44:21 +00:00
|
|
|
if (IsDigit(nextChar)) {
|
2008-09-10 04:38:14 +00:00
|
|
|
return ParseNumber(ch, aToken);
|
2009-01-17 03:44:21 +00:00
|
|
|
}
|
|
|
|
else if (('.' == nextChar) && ('.' != ch)) {
|
|
|
|
nextChar = Read();
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t followingChar = Peek();
|
2009-01-17 03:44:21 +00:00
|
|
|
Pushback(nextChar);
|
|
|
|
if (IsDigit(followingChar))
|
|
|
|
return ParseNumber(ch, aToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (IsDigit(ch)) {
|
|
|
|
return ParseNumber(ch, aToken);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2009-01-17 03:44:21 +00:00
|
|
|
// ID
|
|
|
|
if (ch == '#') {
|
|
|
|
return ParseRef(ch, aToken);
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2009-01-17 03:44:21 +00:00
|
|
|
// STRING
|
|
|
|
if ((ch == '"') || (ch == '\'')) {
|
|
|
|
return ParseString(ch, aToken);
|
|
|
|
}
|
2004-02-08 07:29:42 +00:00
|
|
|
|
2009-01-17 03:44:21 +00:00
|
|
|
// WS
|
|
|
|
if (IsWhitespace(ch)) {
|
|
|
|
aToken.mType = eCSSToken_WhiteSpace;
|
2004-02-08 07:29:42 +00:00
|
|
|
aToken.mIdent.Assign(PRUnichar(ch));
|
2009-04-09 06:46:26 +00:00
|
|
|
EatWhiteSpace();
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-01-17 03:44:21 +00:00
|
|
|
}
|
2010-12-05 20:37:39 +00:00
|
|
|
if (ch == '/' && !IsSVGMode()) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t nextChar = Peek();
|
2009-01-17 03:44:21 +00:00
|
|
|
if (nextChar == '*') {
|
2011-05-19 22:44:14 +00:00
|
|
|
Read();
|
|
|
|
// FIXME: Editor wants comments to be preserved (bug 60290).
|
2009-01-17 03:44:21 +00:00
|
|
|
if (!SkipCComment()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-01-17 03:44:21 +00:00
|
|
|
}
|
|
|
|
continue; // start again at the beginning
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2009-01-17 03:44:21 +00:00
|
|
|
if (ch == '<') { // consume HTML comment tags
|
|
|
|
if (LookAhead('!')) {
|
2008-09-10 04:38:14 +00:00
|
|
|
if (LookAhead('-')) {
|
2009-01-17 03:44:21 +00:00
|
|
|
if (LookAhead('-')) {
|
|
|
|
aToken.mType = eCSSToken_HTMLComment;
|
|
|
|
aToken.mIdent.AssignLiteral("<!--");
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-01-17 03:44:21 +00:00
|
|
|
}
|
|
|
|
Pushback('-');
|
|
|
|
}
|
|
|
|
Pushback('!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ch == '-') { // check for HTML comment end
|
|
|
|
if (LookAhead('-')) {
|
|
|
|
if (LookAhead('>')) {
|
1999-02-03 02:59:51 +00:00
|
|
|
aToken.mType = eCSSToken_HTMLComment;
|
2009-01-17 03:44:21 +00:00
|
|
|
aToken.mIdent.AssignLiteral("-->");
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
1998-09-25 01:50:51 +00:00
|
|
|
}
|
2000-04-27 00:12:25 +00:00
|
|
|
Pushback('-');
|
|
|
|
}
|
2004-02-08 07:29:42 +00:00
|
|
|
}
|
|
|
|
|
2009-01-17 03:44:21 +00:00
|
|
|
// INCLUDES ("~=") and DASHMATCH ("|=")
|
|
|
|
if (( ch == '|' ) || ( ch == '~' ) || ( ch == '^' ) ||
|
|
|
|
( ch == '$' ) || ( ch == '*' )) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t nextChar = Read();
|
2009-01-17 03:44:21 +00:00
|
|
|
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;
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-01-17 03:44:21 +00:00
|
|
|
} else if (nextChar >= 0) {
|
|
|
|
Pushback(nextChar);
|
2004-02-08 07:29:42 +00:00
|
|
|
}
|
1998-09-25 01:50:51 +00:00
|
|
|
}
|
2009-01-17 03:44:21 +00:00
|
|
|
aToken.mType = eCSSToken_Symbol;
|
|
|
|
aToken.mSymbol = ch;
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-10-26 23:22:40 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2008-09-10 04:38:14 +00:00
|
|
|
nsCSSScanner::NextURL(nsCSSToken& aToken)
|
1998-10-26 23:22:40 +00:00
|
|
|
{
|
2011-03-11 17:29:44 +00:00
|
|
|
EatWhiteSpace();
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t ch = Read();
|
1998-10-26 23:22:40 +00:00
|
|
|
if (ch < 0) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
1998-10-26 23:22:40 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 03:39:22 +00:00
|
|
|
// STRING
|
|
|
|
if ((ch == '"') || (ch == '\'')) {
|
2011-03-11 17:29:44 +00:00
|
|
|
#ifdef DEBUG
|
2011-09-29 06:19:26 +00:00
|
|
|
bool ok =
|
2011-03-11 17:29:44 +00:00
|
|
|
#endif
|
|
|
|
ParseString(ch, aToken);
|
|
|
|
NS_ABORT_IF_FALSE(ok, "ParseString should never fail, "
|
|
|
|
"since there's always something read");
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(aToken.mType == eCSSToken_String ||
|
|
|
|
aToken.mType == eCSSToken_Bad_String,
|
|
|
|
"unexpected token type");
|
|
|
|
if (NS_LIKELY(aToken.mType == eCSSToken_String)) {
|
|
|
|
EatWhiteSpace();
|
2011-03-11 17:29:45 +00:00
|
|
|
if (LookAheadOrEOF(')')) {
|
|
|
|
aToken.mType = eCSSToken_URL;
|
|
|
|
} else {
|
|
|
|
aToken.mType = eCSSToken_Bad_URL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aToken.mType = eCSSToken_Bad_URL;
|
2011-03-11 17:29:44 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2007-08-20 03:39:22 +00:00
|
|
|
}
|
1998-10-26 23:22:40 +00:00
|
|
|
|
2007-08-20 03:39:22 +00: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
|
2011-03-11 17:29:44 +00:00
|
|
|
// malformed URL then we emit a token of type "Bad_URL" so that
|
2009-08-06 00:45:49 +00:00
|
|
|
// the CSS1 parser can ignore the invalid input. The parser must
|
2011-03-11 17:29:44 +00:00
|
|
|
// treat a Bad_URL token like a Function token, and process
|
2009-08-06 00:45:49 +00:00
|
|
|
// tokens until a matching parenthesis.
|
2007-08-20 03:39:22 +00:00
|
|
|
|
2011-03-11 17:29:44 +00:00
|
|
|
aToken.mType = eCSSToken_Bad_URL;
|
2011-03-11 17:29:45 +00:00
|
|
|
aToken.mSymbol = PRUnichar(0);
|
2007-08-20 03:39:22 +00:00
|
|
|
nsString& ident = aToken.mIdent;
|
|
|
|
ident.SetLength(0);
|
|
|
|
|
2009-08-06 00:45:49 +00:00
|
|
|
// start of a non-quoted url (which may be empty)
|
2011-09-29 06:19:26 +00:00
|
|
|
bool ok = true;
|
2009-08-06 00:45:49 +00:00
|
|
|
for (;;) {
|
2012-05-14 23:01:05 +00:00
|
|
|
if (IsURLChar(ch)) {
|
|
|
|
// A regular url character.
|
|
|
|
ident.Append(PRUnichar(ch));
|
|
|
|
} else if (ch == ')') {
|
|
|
|
// All done
|
|
|
|
break;
|
2009-08-06 00:45:49 +00:00
|
|
|
} else if (IsWhitespace(ch)) {
|
|
|
|
// Whitespace is allowed at the end of the URL
|
2011-03-11 17:29:44 +00:00
|
|
|
EatWhiteSpace();
|
2011-03-11 17:29:45 +00:00
|
|
|
// Consume the close paren if we have it; if not we're an invalid URL.
|
|
|
|
ok = LookAheadOrEOF(')');
|
2009-08-06 00:45:49 +00:00
|
|
|
break;
|
2012-05-14 23:01:05 +00:00
|
|
|
} else if (ch == '\\') {
|
|
|
|
if (!ParseAndAppendEscape(ident, false)) {
|
|
|
|
ok = false;
|
|
|
|
Pushback(ch);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2011-03-11 17:29:44 +00:00
|
|
|
// This is an invalid URL spec
|
2011-10-17 14:59:28 +00:00
|
|
|
ok = false;
|
2011-03-11 17:29:44 +00:00
|
|
|
Pushback(ch); // push it back so the parser can match tokens and
|
|
|
|
// then closing parenthesis
|
|
|
|
break;
|
2012-05-14 23:01:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ch = Read();
|
|
|
|
if (ch < 0) {
|
2009-08-06 00:45:49 +00:00
|
|
|
break;
|
2007-08-20 03:39:22 +00:00
|
|
|
}
|
2009-08-06 00:45:49 +00:00
|
|
|
}
|
1998-10-26 23:22:40 +00:00
|
|
|
|
2009-08-06 00:45:49 +00: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-26 23:22:40 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-10-26 23:22:40 +00:00
|
|
|
|
2011-05-03 20:19:19 +00:00
|
|
|
/**
|
|
|
|
* Returns whether an escape was succesfully parsed; if it was not,
|
|
|
|
* the backslash needs to be its own symbol token.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
|
|
|
nsCSSScanner::ParseAndAppendEscape(nsString& aOutput, bool aInString)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t ch = Read();
|
1998-04-13 20:24:54 +00:00
|
|
|
if (ch < 0) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2007-08-26 02:20:27 +00:00
|
|
|
if (IsHexDigit(ch)) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t rv = 0;
|
1999-05-19 00:18:30 +00:00
|
|
|
int i;
|
2011-05-03 20:19:19 +00:00
|
|
|
Pushback(ch);
|
1999-05-19 00:18:30 +00:00
|
|
|
for (i = 0; i < 6; i++) { // up to six digits
|
2008-09-10 04:38:14 +00:00
|
|
|
ch = Read();
|
1998-04-13 20:24:54 +00:00
|
|
|
if (ch < 0) {
|
|
|
|
// Whoops: error or premature eof
|
|
|
|
break;
|
|
|
|
}
|
2007-08-26 02:20:27 +00:00
|
|
|
if (!IsHexDigit(ch) && !IsWhitespace(ch)) {
|
2007-08-21 18:29:50 +00:00
|
|
|
Pushback(ch);
|
2004-02-08 19:22:47 +00:00
|
|
|
break;
|
2007-08-26 02:20:27 +00:00
|
|
|
} else if (IsHexDigit(ch)) {
|
2009-08-20 21:52:47 +00:00
|
|
|
rv = rv * 16 + HexDigitValue(ch);
|
2004-02-08 19:22:47 +00:00
|
|
|
} else {
|
2007-08-26 02:20:27 +00:00
|
|
|
NS_ASSERTION(IsWhitespace(ch), "bad control flow");
|
2004-02-08 19:22:47 +00:00
|
|
|
// single space ends escape
|
1999-05-18 23:13:27 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1999-05-18 23:13:27 +00:00
|
|
|
if (6 == i) { // look for trailing whitespace and eat it
|
2008-09-10 04:38:14 +00:00
|
|
|
ch = Peek();
|
2007-08-26 02:20:27 +00:00
|
|
|
if (IsWhitespace(ch)) {
|
2008-10-23 16:29:24 +00:00
|
|
|
(void) Read();
|
1999-05-18 23:13:27 +00:00
|
|
|
}
|
|
|
|
}
|
2005-11-17 15:17:00 +00:00
|
|
|
NS_ASSERTION(rv >= 0, "How did rv become negative?");
|
2008-10-23 16:29:24 +00:00
|
|
|
// "[at most six hexadecimal digits following a backslash] stand
|
|
|
|
// for the ISO 10646 character with that number, which must not be
|
|
|
|
// zero. (It is undefined in CSS 2.1 what happens if a style sheet
|
|
|
|
// does contain a character with Unicode codepoint zero.)"
|
|
|
|
// -- CSS2.1 section 4.1.3
|
|
|
|
//
|
|
|
|
// Silently deleting \0 opens a content-filtration loophole (see
|
|
|
|
// bug 228856), so what we do instead is pretend the "cancels the
|
|
|
|
// meaning of special characters" rule applied.
|
2005-11-17 15:17:00 +00:00
|
|
|
if (rv > 0) {
|
|
|
|
AppendUCS4ToUTF16(ENSURE_VALID_CHAR(rv), aOutput);
|
2008-10-23 16:29:24 +00:00
|
|
|
} else {
|
|
|
|
while (i--)
|
|
|
|
aOutput.Append('0');
|
|
|
|
if (IsWhitespace(ch))
|
|
|
|
Pushback(ch);
|
2005-11-17 15:17:00 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-04-09 06:46:26 +00:00
|
|
|
}
|
|
|
|
// "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
|
2011-05-03 20:19:19 +00:00
|
|
|
if (ch == '\n') {
|
|
|
|
if (!aInString) {
|
|
|
|
// Outside of strings (which includes url() that contains a
|
|
|
|
// string), escaped newlines aren't special, and just tokenize as
|
|
|
|
// eCSSToken_Symbol (DELIM).
|
|
|
|
Pushback(ch);
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-05-03 20:19:19 +00:00
|
|
|
}
|
|
|
|
// In strings (and in url() containing a string), escaped newlines
|
|
|
|
// are just dropped to allow splitting over multiple lines.
|
|
|
|
} else {
|
2009-04-09 06:46:26 +00:00
|
|
|
aOutput.Append(ch);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2011-05-03 20:19:19 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
1998-04-13 20:24:54 +00: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.
|
2011-05-03 20:19:19 +00:00
|
|
|
*
|
|
|
|
* Returns failure when the character sequence does not form an ident at
|
|
|
|
* all, in which case the caller is responsible for pushing back or
|
|
|
|
* otherwise handling aChar. (This occurs only when aChar is '\'.)
|
1998-04-13 20:24:54 +00:00
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
nsCSSScanner::GatherIdent(int32_t aChar, nsString& aIdent)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2011-05-19 22:44:14 +00:00
|
|
|
if (aChar == '\\') {
|
2011-10-17 14:59:28 +00:00
|
|
|
if (!ParseAndAppendEscape(aIdent, false)) {
|
|
|
|
return false;
|
2011-05-03 20:19:19 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2005-11-17 15:17:00 +00:00
|
|
|
else if (0 < aChar) {
|
|
|
|
aIdent.Append(aChar);
|
1999-05-18 23:13:27 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
for (;;) {
|
2008-02-22 01:37:04 +00:00
|
|
|
// If nothing in pushback, first try to get as much as possible in one go
|
2011-05-18 17:33:16 +00:00
|
|
|
if (!mPushbackCount && mOffset < mCount) {
|
2008-02-22 01:37:04 +00:00
|
|
|
// See how much we can consume and append in one go
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t n = mOffset;
|
2008-02-22 01:37:04 +00:00
|
|
|
// Count number of Ident characters that can be processed
|
|
|
|
while (n < mCount && IsIdent(mReadPointer[n])) {
|
|
|
|
++n;
|
|
|
|
}
|
|
|
|
// Add to the token what we have so far
|
|
|
|
if (n > mOffset) {
|
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
|
|
|
mColNumber += n - mOffset;
|
|
|
|
#endif
|
|
|
|
aIdent.Append(&mReadPointer[mOffset], n - mOffset);
|
|
|
|
mOffset = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-10 04:38:14 +00:00
|
|
|
aChar = Read();
|
1998-04-13 20:24:54 +00:00
|
|
|
if (aChar < 0) break;
|
2011-05-19 22:44:14 +00:00
|
|
|
if (aChar == '\\') {
|
2011-10-17 14:59:28 +00:00
|
|
|
if (!ParseAndAppendEscape(aIdent, false)) {
|
2011-05-03 20:19:19 +00:00
|
|
|
Pushback(aChar);
|
|
|
|
break;
|
|
|
|
}
|
2007-08-26 02:20:27 +00:00
|
|
|
} else if (IsIdent(aChar)) {
|
1998-04-13 20:24:54 +00:00
|
|
|
aIdent.Append(PRUnichar(aChar));
|
|
|
|
} else {
|
2007-08-21 18:29:50 +00:00
|
|
|
Pushback(aChar);
|
1998-04-13 20:24:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
nsCSSScanner::ParseRef(int32_t aChar, nsCSSToken& aToken)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2011-05-03 20:19:19 +00:00
|
|
|
// Fall back for when we don't have name characters following:
|
|
|
|
aToken.mType = eCSSToken_Symbol;
|
|
|
|
aToken.mSymbol = aChar;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t ch = Read();
|
2005-07-19 20:49:34 +00:00
|
|
|
if (ch < 0) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2005-07-19 20:49:34 +00:00
|
|
|
}
|
2011-05-19 22:44:14 +00:00
|
|
|
if (IsIdent(ch) || ch == '\\') {
|
2005-07-19 20:49:34 +00:00
|
|
|
// First char after the '#' is a valid ident char (or an escape),
|
|
|
|
// so it makes sense to keep going
|
2011-05-03 20:19:19 +00:00
|
|
|
nsCSSTokenType type =
|
|
|
|
StartsIdent(ch, Peek()) ? eCSSToken_ID : eCSSToken_Ref;
|
|
|
|
aToken.mIdent.SetLength(0);
|
|
|
|
if (GatherIdent(ch, aToken.mIdent)) {
|
|
|
|
aToken.mType = type;
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2005-07-19 20:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No ident chars after the '#'. Just unread |ch| and get out of here.
|
2007-08-21 18:29:50 +00:00
|
|
|
Pushback(ch);
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
nsCSSScanner::ParseIdent(int32_t aChar, nsCSSToken& aToken)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-10-26 23:22:40 +00:00
|
|
|
nsString& ident = aToken.mIdent;
|
1998-04-13 20:24:54 +00:00
|
|
|
ident.SetLength(0);
|
2008-09-10 04:38:14 +00:00
|
|
|
if (!GatherIdent(aChar, ident)) {
|
2011-05-03 20:19:19 +00:00
|
|
|
aToken.mType = eCSSToken_Symbol;
|
|
|
|
aToken.mSymbol = aChar;
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSTokenType tokenType = eCSSToken_Ident;
|
1998-10-26 23:22:40 +00:00
|
|
|
// look for functions (ie: "ident(")
|
2010-01-28 00:20:04 +00:00
|
|
|
if (Peek() == PRUnichar('(')) {
|
|
|
|
Read();
|
1998-10-26 23:22:40 +00:00
|
|
|
tokenType = eCSSToken_Function;
|
2011-03-11 17:29:45 +00:00
|
|
|
|
|
|
|
if (ident.LowerCaseEqualsLiteral("url")) {
|
|
|
|
NextURL(aToken); // ignore return value, since *we* read something
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2011-03-11 17:29:45 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-10-26 23:22:40 +00:00
|
|
|
|
|
|
|
aToken.mType = tokenType;
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
nsCSSScanner::ParseAtKeyword(int32_t aChar, nsCSSToken& aToken)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-10-26 23:22:40 +00:00
|
|
|
aToken.mIdent.SetLength(0);
|
|
|
|
aToken.mType = eCSSToken_AtKeyword;
|
2011-05-03 20:19:19 +00:00
|
|
|
if (!GatherIdent(0, aToken.mIdent)) {
|
|
|
|
aToken.mType = eCSSToken_Symbol;
|
|
|
|
aToken.mSymbol = PRUnichar('@');
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
nsCSSScanner::ParseNumber(int32_t c, nsCSSToken& aToken)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2009-07-10 01:44:20 +00:00
|
|
|
NS_PRECONDITION(c == '.' || c == '+' || c == '-' || IsDigit(c),
|
|
|
|
"Why did we get called?");
|
2008-06-03 03:17:35 +00:00
|
|
|
aToken.mHasSign = (c == '+' || c == '-');
|
2009-07-10 01:44:20 +00:00
|
|
|
|
|
|
|
// Our sign.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t sign = c == '-' ? -1 : 1;
|
2009-07-10 01:44:20 +00:00
|
|
|
// Absolute value of the integer part of the mantissa. This is a double so
|
|
|
|
// we don't run into overflow issues for consumers that only care about our
|
2012-08-22 15:56:38 +00:00
|
|
|
// floating-point value while still being able to express the full int32_t
|
2009-07-10 01:44:20 +00:00
|
|
|
// range for consumers who want integers.
|
|
|
|
double intPart = 0;
|
|
|
|
// Fractional part of the mantissa. This is a double so that when we convert
|
|
|
|
// to float at the end we'll end up rounding to nearest float instead of
|
|
|
|
// truncating down (as we would if fracPart were a float and we just
|
|
|
|
// effectively lost the last several digits).
|
|
|
|
double fracPart = 0;
|
|
|
|
// Absolute value of the power of 10 that we should multiply by (only
|
|
|
|
// relevant for numbers in scientific notation). Has to be a signed integer,
|
|
|
|
// because multiplication of signed by unsigned converts the unsigned to
|
|
|
|
// signed, so if we plan to actually multiply by expSign...
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t exponent = 0;
|
2009-07-10 01:44:20 +00:00
|
|
|
// Sign of the exponent.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t expSign = 1;
|
2009-07-23 01:35:07 +00:00
|
|
|
|
|
|
|
if (aToken.mHasSign) {
|
|
|
|
NS_ASSERTION(c != '.', "How did that happen?");
|
|
|
|
c = Read();
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool gotDot = (c == '.');
|
2009-07-23 01:35:07 +00:00
|
|
|
|
|
|
|
if (!gotDot) {
|
|
|
|
// Parse the integer part of the mantisssa
|
|
|
|
NS_ASSERTION(IsDigit(c), "Why did we get called?");
|
|
|
|
do {
|
2009-08-20 21:52:47 +00:00
|
|
|
intPart = 10*intPart + DecimalDigitValue(c);
|
2009-07-23 01:35:07 +00:00
|
|
|
c = Read();
|
|
|
|
// The IsDigit check will do the right thing even if Read() returns < 0
|
|
|
|
} while (IsDigit(c));
|
|
|
|
|
|
|
|
gotDot = (c == '.') && IsDigit(Peek());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gotDot) {
|
|
|
|
// Parse the fractional part of the mantissa.
|
2008-09-10 04:38:14 +00:00
|
|
|
c = Read();
|
2009-07-23 01:35:07 +00:00
|
|
|
NS_ASSERTION(IsDigit(c), "How did we get here?");
|
|
|
|
// Power of ten by which we need to divide our next digit
|
|
|
|
float divisor = 10;
|
|
|
|
do {
|
2009-08-20 21:52:47 +00:00
|
|
|
fracPart += DecimalDigitValue(c) / divisor;
|
2009-07-23 01:35:07 +00:00
|
|
|
divisor *= 10;
|
|
|
|
c = Read();
|
|
|
|
// The IsDigit check will do the right thing even if Read() returns < 0
|
|
|
|
} while (IsDigit(c));
|
|
|
|
}
|
2009-07-10 03:36:57 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool gotE = false;
|
2009-07-23 01:35:07 +00:00
|
|
|
if (IsSVGMode() && (c == 'e' || c == 'E')) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t nextChar = Peek();
|
|
|
|
int32_t expSignChar = 0;
|
2009-07-23 01:35:07 +00:00
|
|
|
if (nextChar == '-' || nextChar == '+') {
|
|
|
|
expSignChar = Read();
|
|
|
|
nextChar = Peek();
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2009-07-23 01:35:07 +00:00
|
|
|
if (IsDigit(nextChar)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
gotE = true;
|
2009-07-23 01:35:07 +00:00
|
|
|
if (expSignChar == '-') {
|
|
|
|
expSign = -1;
|
2009-07-10 03:36:57 +00:00
|
|
|
}
|
2009-07-23 01:35:07 +00:00
|
|
|
|
|
|
|
c = Read();
|
|
|
|
NS_ASSERTION(IsDigit(c), "Peek() must have lied");
|
|
|
|
do {
|
2009-08-20 21:52:47 +00:00
|
|
|
exponent = 10*exponent + DecimalDigitValue(c);
|
2009-07-23 01:35:07 +00:00
|
|
|
c = Read();
|
|
|
|
// The IsDigit check will do the right thing even if Read() returns < 0
|
|
|
|
} while (IsDigit(c));
|
2009-07-10 01:44:20 +00:00
|
|
|
} else {
|
2009-07-23 01:35:07 +00:00
|
|
|
if (expSignChar) {
|
|
|
|
Pushback(expSignChar);
|
|
|
|
}
|
2009-07-10 01:44:20 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSTokenType type = eCSSToken_Number;
|
|
|
|
|
2008-06-03 03:17:35 +00:00
|
|
|
// Set mIntegerValid for all cases (except %, below) because we need
|
|
|
|
// it for the "2n" in :nth-child(2n).
|
2011-10-17 14:59:28 +00:00
|
|
|
aToken.mIntegerValid = false;
|
2009-07-10 01:44:20 +00:00
|
|
|
|
|
|
|
// Time to reassemble our number.
|
|
|
|
float value = float(sign * (intPart + fracPart));
|
|
|
|
if (gotE) {
|
|
|
|
// pow(), not powf(), because at least wince doesn't have the latter.
|
|
|
|
// And explicitly cast everything to doubles to avoid issues with
|
|
|
|
// overloaded pow() on Windows.
|
|
|
|
value *= pow(10.0, double(expSign * exponent));
|
|
|
|
} else if (!gotDot) {
|
2010-10-18 02:36:26 +00:00
|
|
|
// Clamp values outside of integer range.
|
|
|
|
if (sign > 0) {
|
2012-08-22 15:56:38 +00:00
|
|
|
aToken.mInteger = int32_t(NS_MIN(intPart, double(PR_INT32_MAX)));
|
2010-10-18 02:36:26 +00:00
|
|
|
} else {
|
2012-08-22 15:56:38 +00:00
|
|
|
aToken.mInteger = int32_t(NS_MAX(-intPart, double(PR_INT32_MIN)));
|
2009-07-10 01:44:20 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
aToken.mIntegerValid = true;
|
2008-06-03 03:17:35 +00:00
|
|
|
}
|
2009-07-10 01:44:20 +00:00
|
|
|
|
|
|
|
nsString& ident = aToken.mIdent;
|
|
|
|
ident.Truncate();
|
2008-06-03 03:17:35 +00:00
|
|
|
|
|
|
|
// Look at character that terminated the number
|
1998-04-13 20:24:54 +00:00
|
|
|
if (c >= 0) {
|
2008-09-10 04:38:14 +00:00
|
|
|
if (StartsIdent(c, Peek())) {
|
2011-05-03 20:19:19 +00:00
|
|
|
if (GatherIdent(c, ident)) {
|
|
|
|
type = eCSSToken_Dimension;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
} else if ('%' == c) {
|
|
|
|
type = eCSSToken_Percentage;
|
|
|
|
value = value / 100.0f;
|
2011-10-17 14:59:28 +00:00
|
|
|
aToken.mIntegerValid = false;
|
1998-04-13 20:24:54 +00:00
|
|
|
} else {
|
|
|
|
// Put back character that stopped numeric scan
|
2007-08-21 18:29:50 +00:00
|
|
|
Pushback(c);
|
1999-02-11 06:42:02 +00:00
|
|
|
}
|
|
|
|
}
|
1998-10-26 23:22:40 +00:00
|
|
|
aToken.mNumber = value;
|
|
|
|
aToken.mType = type;
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2008-09-10 04:38:14 +00:00
|
|
|
nsCSSScanner::SkipCComment()
|
2003-01-13 07:19:49 +00:00
|
|
|
{
|
|
|
|
for (;;) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t ch = Read();
|
2003-01-13 07:19:49 +00:00
|
|
|
if (ch < 0) break;
|
|
|
|
if (ch == '*') {
|
2008-09-10 04:38:14 +00:00
|
|
|
if (LookAhead('/')) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2003-01-13 07:19:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-12 18:44:14 +00:00
|
|
|
REPORT_UNEXPECTED_EOF(PECommentEOF);
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2003-01-13 07:19:49 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
nsCSSScanner::ParseString(int32_t aStop, nsCSSToken& aToken)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2005-03-18 06:56:56 +00:00
|
|
|
aToken.mIdent.SetLength(0);
|
|
|
|
aToken.mType = eCSSToken_String;
|
|
|
|
aToken.mSymbol = PRUnichar(aStop); // remember how it's quoted
|
1998-04-13 20:24:54 +00:00
|
|
|
for (;;) {
|
2008-02-22 01:37:04 +00:00
|
|
|
// If nothing in pushback, first try to get as much as possible in one go
|
2011-05-18 17:33:16 +00:00
|
|
|
if (!mPushbackCount && mOffset < mCount) {
|
2008-02-22 01:37:04 +00:00
|
|
|
// See how much we can consume and append in one go
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t n = mOffset;
|
2008-02-22 01:37:04 +00:00
|
|
|
// Count number of characters that can be processed
|
|
|
|
for (;n < mCount; ++n) {
|
|
|
|
PRUnichar nextChar = mReadPointer[n];
|
2011-05-19 22:44:14 +00:00
|
|
|
if ((nextChar == aStop) || (nextChar == '\\') ||
|
2008-02-22 01:37:04 +00:00
|
|
|
(nextChar == '\n') || (nextChar == '\r') || (nextChar == '\f')) {
|
|
|
|
break;
|
|
|
|
}
|
2005-03-18 06:56:56 +00:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
2011-05-19 22:44:14 +00:00
|
|
|
++mColNumber;
|
2005-03-18 06:56:56 +00:00
|
|
|
#endif
|
2008-02-22 01:37:04 +00:00
|
|
|
}
|
|
|
|
// Add to the token what we have so far
|
|
|
|
if (n > mOffset) {
|
|
|
|
aToken.mIdent.Append(&mReadPointer[mOffset], n - mOffset);
|
|
|
|
mOffset = n;
|
|
|
|
}
|
1999-02-07 21:47:48 +00:00
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t ch = Read();
|
2008-02-22 01:37:04 +00:00
|
|
|
if (ch < 0 || ch == aStop) {
|
|
|
|
break;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2008-02-22 01:37:04 +00:00
|
|
|
if (ch == '\n') {
|
2011-03-11 17:29:44 +00:00
|
|
|
aToken.mType = eCSSToken_Bad_String;
|
2008-02-22 01:37:04 +00:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
|
|
|
ReportUnexpectedToken(aToken, "SEUnterminatedString");
|
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-05-19 22:44:14 +00:00
|
|
|
if (ch == '\\') {
|
2011-10-17 14:59:28 +00:00
|
|
|
if (!ParseAndAppendEscape(aToken.mIdent, true)) {
|
2011-05-03 20:19:19 +00:00
|
|
|
aToken.mType = eCSSToken_Bad_String;
|
|
|
|
Pushback(ch);
|
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
|
|
|
// For strings, the only case where ParseAndAppendEscape will
|
|
|
|
// return false is when there's a backslash to start an escape
|
|
|
|
// immediately followed by end-of-stream. In that case, the
|
|
|
|
// correct tokenization is badstring *followed* by a DELIM for
|
|
|
|
// the backslash, but as far as the author is concerned, it
|
|
|
|
// works pretty much the same as an unterminated string, so we
|
|
|
|
// use the same error message.
|
|
|
|
ReportUnexpectedToken(aToken, "SEUnterminatedString");
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
2008-02-22 01:37:04 +00:00
|
|
|
} else {
|
2005-11-17 15:17:00 +00:00
|
|
|
aToken.mIdent.Append(ch);
|
1999-02-07 21:47:48 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
2009-08-20 21:52:47 +00:00
|
|
|
|
|
|
|
// UNICODE-RANGE tokens match the regular expression
|
|
|
|
//
|
|
|
|
// u\+[0-9a-f?]{1,6}(-[0-9a-f]{1,6})?
|
|
|
|
//
|
|
|
|
// However, some such tokens are "invalid". There are three valid forms:
|
|
|
|
//
|
|
|
|
// u+[0-9a-f]{x} 1 <= x <= 6
|
|
|
|
// u+[0-9a-f]{x}\?{y} 1 <= x+y <= 6
|
|
|
|
// u+[0-9a-f]{x}-[0-9a-f]{y} 1 <= x <= 6, 1 <= y <= 6
|
|
|
|
//
|
|
|
|
// All unicode-range tokens have their text recorded in mIdent; valid ones
|
|
|
|
// are also decoded into mInteger and mInteger2, and mIntegerValid is set.
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
nsCSSScanner::ParseURange(int32_t aChar, nsCSSToken& aResult)
|
2009-08-20 21:52:47 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t intro2 = Read();
|
|
|
|
int32_t ch = Peek();
|
2009-08-20 21:52:47 +00:00
|
|
|
|
|
|
|
// We should only ever be called if these things are true.
|
|
|
|
NS_ASSERTION(aChar == 'u' || aChar == 'U',
|
|
|
|
"unicode-range called with improper introducer (U)");
|
|
|
|
NS_ASSERTION(intro2 == '+',
|
|
|
|
"unicode-range called with improper introducer (+)");
|
|
|
|
|
|
|
|
// If the character immediately after the '+' is not a hex digit or
|
|
|
|
// '?', this is not really a unicode-range token; push everything
|
|
|
|
// back and scan the U as an ident.
|
|
|
|
if (!IsHexDigit(ch) && ch != '?') {
|
|
|
|
Pushback(intro2);
|
|
|
|
Pushback(aChar);
|
|
|
|
return ParseIdent(aChar, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult.mIdent.Truncate();
|
|
|
|
aResult.mIdent.Append(aChar);
|
|
|
|
aResult.mIdent.Append(intro2);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool valid = true;
|
|
|
|
bool haveQues = false;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t low = 0;
|
|
|
|
uint32_t high = 0;
|
2009-08-20 21:52:47 +00:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
ch = Read();
|
|
|
|
i++;
|
|
|
|
if (i == 7 || !(IsHexDigit(ch) || ch == '?')) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult.mIdent.Append(ch);
|
|
|
|
if (IsHexDigit(ch)) {
|
|
|
|
if (haveQues) {
|
2011-10-17 14:59:28 +00:00
|
|
|
valid = false; // all question marks should be at the end
|
2009-08-20 21:52:47 +00:00
|
|
|
}
|
|
|
|
low = low*16 + HexDigitValue(ch);
|
|
|
|
high = high*16 + HexDigitValue(ch);
|
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
haveQues = true;
|
2009-08-20 21:52:47 +00:00
|
|
|
low = low*16 + 0x0;
|
|
|
|
high = high*16 + 0xF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ch == '-' && IsHexDigit(Peek())) {
|
|
|
|
if (haveQues) {
|
2011-10-17 14:59:28 +00:00
|
|
|
valid = false;
|
2009-08-20 21:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aResult.mIdent.Append(ch);
|
|
|
|
high = 0;
|
|
|
|
i = 0;
|
|
|
|
for (;;) {
|
|
|
|
ch = Read();
|
|
|
|
i++;
|
|
|
|
if (i == 7 || !IsHexDigit(ch)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aResult.mIdent.Append(ch);
|
|
|
|
high = high*16 + HexDigitValue(ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Pushback(ch);
|
|
|
|
|
|
|
|
aResult.mInteger = low;
|
|
|
|
aResult.mInteger2 = high;
|
|
|
|
aResult.mIntegerValid = valid;
|
|
|
|
aResult.mType = eCSSToken_URange;
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-08-20 21:52:47 +00:00
|
|
|
}
|