#pragma once
#include "CSSPrimitiveValue.h"
#include <wtf/text/StringView.h>
namespace WebCore {
enum CSSParserTokenType {
IdentToken = 0,
FunctionToken,
AtKeywordToken,
HashToken,
UrlToken,
BadUrlToken,
DelimiterToken,
NumberToken,
PercentageToken,
DimensionToken,
IncludeMatchToken,
DashMatchToken,
PrefixMatchToken,
SuffixMatchToken,
SubstringMatchToken,
ColumnToken,
UnicodeRangeToken,
WhitespaceToken,
CDOToken,
CDCToken,
ColonToken,
SemicolonToken,
CommaToken,
LeftParenthesisToken,
RightParenthesisToken,
LeftBracketToken,
RightBracketToken,
LeftBraceToken,
RightBraceToken,
StringToken,
BadStringToken,
EOFToken,
CommentToken,
};
enum NumericSign {
NoSign,
PlusSign,
MinusSign,
};
enum NumericValueType {
IntegerValueType,
NumberValueType,
};
enum HashTokenType {
HashTokenId,
HashTokenUnrestricted,
};
class CSSParserToken {
WTF_MAKE_FAST_ALLOCATED;
public:
enum BlockType {
NotBlock,
BlockStart,
BlockEnd,
};
CSSParserToken(CSSParserTokenType, BlockType = NotBlock);
CSSParserToken(CSSParserTokenType, StringView, BlockType = NotBlock);
CSSParserToken(CSSParserTokenType, UChar); CSSParserToken(CSSParserTokenType, double, NumericValueType, NumericSign); CSSParserToken(CSSParserTokenType, UChar32, UChar32);
CSSParserToken(HashTokenType, StringView);
bool operator==(const CSSParserToken& other) const;
bool operator!=(const CSSParserToken& other) const { return !(*this == other); }
void convertToDimensionWithUnit(StringView);
void convertToPercentage();
CSSParserTokenType type() const { return static_cast<CSSParserTokenType>(m_type); }
StringView value() const
{
if (m_valueIs8Bit)
return StringView(static_cast<const LChar*>(m_valueDataCharRaw), m_valueLength);
return StringView(static_cast<const UChar*>(m_valueDataCharRaw), m_valueLength);
}
UChar delimiter() const;
NumericSign numericSign() const;
NumericValueType numericValueType() const;
double numericValue() const;
HashTokenType getHashTokenType() const { ASSERT(m_type == HashToken); return m_hashTokenType; }
BlockType getBlockType() const { return static_cast<BlockType>(m_blockType); }
CSSPrimitiveValue::UnitType unitType() const { return static_cast<CSSPrimitiveValue::UnitType>(m_unit); }
UChar32 unicodeRangeStart() const { ASSERT(m_type == UnicodeRangeToken); return m_unicodeRange.start; }
UChar32 unicodeRangeEnd() const { ASSERT(m_type == UnicodeRangeToken); return m_unicodeRange.end; }
CSSValueID id() const;
CSSValueID functionId() const;
bool hasStringBacking() const;
CSSPropertyID parseAsCSSPropertyID() const;
void serialize(StringBuilder&) const;
CSSParserToken copyWithUpdatedString(const StringView&) const;
private:
void initValueFromStringView(StringView string)
{
m_valueLength = string.length();
m_valueIs8Bit = string.is8Bit();
m_valueDataCharRaw = m_valueIs8Bit ? const_cast<void*>(static_cast<const void*>(string.characters8())) : const_cast<void*>(static_cast<const void*>(string.characters16()));
}
unsigned m_type : 6; unsigned m_blockType : 2; unsigned m_numericValueType : 1; unsigned m_numericSign : 2; unsigned m_unit : 7;
bool valueDataCharRawEqual(const CSSParserToken& other) const;
bool m_valueIs8Bit : 1;
unsigned m_valueLength;
void* m_valueDataCharRaw;
union {
UChar m_delimiter;
HashTokenType m_hashTokenType;
double m_numericValue;
mutable int m_id;
struct {
UChar32 start;
UChar32 end;
} m_unicodeRange;
};
};
}