CssParserExtensions
Extensions to be used exclusively by the parser or the tokenizer.
using AngleSharp.Css;
using AngleSharp.Css.DocumentFunctions;
using AngleSharp.Extensions;
using System;
using System.Diagnostics;
namespace AngleSharp.Parser.Css
{
[DebuggerStepThrough]
internal static class CssParserExtensions
{
public static int GetCode(this CssParseError code)
{
return (int)code;
}
public static bool Is(this CssToken token, CssTokenType a, CssTokenType b)
{
CssTokenType type = token.Type;
if (type != a)
return type == b;
return true;
}
public static bool IsNot(this CssToken token, CssTokenType a, CssTokenType b)
{
CssTokenType type = token.Type;
if (type != a)
return type != b;
return false;
}
public static bool IsNot(this CssToken token, CssTokenType a, CssTokenType b, CssTokenType c)
{
CssTokenType type = token.Type;
if (type != a && type != b)
return type != c;
return false;
}
public static bool IsMatchToken(this CssToken token)
{
CssTokenType type = token.Type;
if (type != CssTokenType.IncludeMatch && type != CssTokenType.DashMatch && type != CssTokenType.PrefixMatch && type != CssTokenType.SubstringMatch && type != CssTokenType.SuffixMatch)
return type == CssTokenType.NotMatch;
return true;
}
public static IDocumentFunction ToDocumentFunction(this CssToken token)
{
switch (token.Type) {
case CssTokenType.Url:
return new UrlFunction(token.Data);
case CssTokenType.UrlPrefix:
return new UrlPrefixFunction(token.Data);
case CssTokenType.Domain:
return new DomainFunction(token.Data);
case CssTokenType.Function:
if (string.Compare(token.Data, FunctionNames.Regexp, StringComparison.OrdinalIgnoreCase) == 0) {
string text = ((CssFunctionToken)token).ToCssString();
if (text != null)
return new RegexpFunction(text);
}
break;
}
return null;
}
}
}