1
- namespace AngleSharp . Css . Parser
1
+ namespace AngleSharp . Css . Parser
2
2
{
3
3
using AngleSharp . Css . Parser . Tokens ;
4
+ using AngleSharp . Text ;
4
5
using System ;
5
6
6
7
/// <summary>
7
8
/// Extensions to be used exclusively by the tokenizer.
8
9
/// </summary>
9
10
static class CssTokenExtensions
10
11
{
12
+ public static Boolean IsPotentiallyNested ( this CssToken token )
13
+ {
14
+ if ( token . Is ( CssTokenType . Hash , CssTokenType . Colon , CssTokenType . SquareBracketOpen ) )
15
+ {
16
+ return true ;
17
+ }
18
+ else if ( token . Type == CssTokenType . Delim && token . Data . Length == 1 )
19
+ {
20
+ return token . Data [ 0 ] switch
21
+ {
22
+ Symbols . Asterisk or Symbols . Plus or Symbols . Dollar or Symbols . Dot or Symbols . Tilde or Symbols . GreaterThan or Symbols . Ampersand => true ,
23
+ _ => false ,
24
+ } ;
25
+ }
26
+
27
+ return false ;
28
+ }
29
+
11
30
/// <summary>
12
31
/// Checks if the provided token is either of the first or the second
13
32
/// type of token.
@@ -22,6 +41,39 @@ public static Boolean Is(this CssToken token, CssTokenType a, CssTokenType b)
22
41
return type == a || type == b ;
23
42
}
24
43
44
+ /// <summary>
45
+ /// Checks if the provided token is one of the list of tokens.
46
+ /// </summary>
47
+ /// <param name="token">The token to examine.</param>
48
+ /// <param name="a">The 1st type to match.</param>
49
+ /// <param name="b">The 2nd type to match.</param>
50
+ /// <param name="c">The 3rd type to match.</param>
51
+ /// <returns>Result of the examination.</returns>
52
+ public static Boolean Is ( this CssToken token , CssTokenType a , CssTokenType b , CssTokenType c )
53
+ {
54
+ var type = token . Type ;
55
+ return type == a || type == b || type == c ;
56
+ }
57
+
58
+ /// <summary>
59
+ /// Checks if the provided token is one of the list of tokens.
60
+ /// </summary>
61
+ /// <param name="token">The token to examine.</param>
62
+ /// <param name="a">The 1st type to match.</param>
63
+ /// <param name="b">The 2nd type to match.</param>
64
+ /// <param name="c">The 3rd type to match.</param>
65
+ /// <param name="d">The 4th type to match.</param>
66
+ /// <param name="e">The 5th type to match.</param>
67
+ /// <param name="f">The 6th type to match.</param>
68
+ /// <param name="g">The 7th type to match.</param>
69
+ /// <param name="h">The 8th type to match.</param>
70
+ /// <returns>Result of the examination.</returns>
71
+ public static Boolean Is ( this CssToken token , CssTokenType a , CssTokenType b , CssTokenType c , CssTokenType d , CssTokenType e , CssTokenType f , CssTokenType g , CssTokenType h )
72
+ {
73
+ var type = token . Type ;
74
+ return type == a || type == b || type == c || type == d || type == e || type == f || type == g || type == h ;
75
+ }
76
+
25
77
/// <summary>
26
78
/// Checks if the provided token is neither of the first nor the second
27
79
/// type of token.
0 commit comments