33
44namespace OneJS . CustomStyleSheets {
55 public static class CSSSpec {
6- private static readonly Regex rgx =
7- new Regex (
8- "(?<id>#[-]?\\ w[\\ w-]*)|(?<class>\\ .[\\ w-]+)|(?<pseudoclass>:[\\ w-]+(\\ ((?<param>.+)\\ ))?)|(?<type>[^\\ -]\\ w+)|(?<wildcard>\\ *)|\\ s+" ,
9- RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
10- private const int typeSelectorWeight = 1 ;
11- private const int classSelectorWeight = 10 ;
12- private const int idSelectorWeight = 100 ;
13-
146 public static int GetSelectorSpecificity ( string selector ) {
15- int selectorSpecificity = 0 ;
7+ int result = 0 ;
168 StyleSelectorPart [ ] parts ;
17- if ( CSSSpec . ParseSelector ( selector , out parts ) )
18- selectorSpecificity = CSSSpec . GetSelectorSpecificity ( parts ) ;
19- return selectorSpecificity ;
9+ bool flag = CSSSpec . ParseSelector ( selector , out parts ) ;
10+ if ( flag ) {
11+ result = CSSSpec . GetSelectorSpecificity ( parts ) ;
12+ }
13+ return result ;
2014 }
2115
16+ // Token: 0x06003A6B RID: 14955 RVA: 0x000E4930 File Offset: 0x000E2B30
2217 public static int GetSelectorSpecificity ( StyleSelectorPart [ ] parts ) {
23- int selectorSpecificity = 1 ;
24- for ( int index = 0 ; index < parts . Length ; ++ index ) {
25- switch ( parts [ index ] . type ) {
18+ int num = 1 ;
19+ for ( int i = 0 ; i < parts . Length ; i ++ ) {
20+ switch ( parts [ i ] . type ) {
2621 case StyleSelectorType . Type :
27- ++ selectorSpecificity ;
22+ num ++ ;
2823 break ;
2924 case StyleSelectorType . Class :
3025 case StyleSelectorType . PseudoClass :
31- selectorSpecificity += 10 ;
26+ num += 10 ;
3227 break ;
3328 case StyleSelectorType . RecursivePseudoClass :
3429 throw new ArgumentException ( "Recursive pseudo classes are not supported" ) ;
3530 case StyleSelectorType . ID :
36- selectorSpecificity += 100 ;
31+ num += 100 ;
3732 break ;
3833 }
3934 }
40- return selectorSpecificity ;
35+ return num ;
36+ }
37+
38+ // Token: 0x06003A6C RID: 14956 RVA: 0x000E49AC File Offset: 0x000E2BAC
39+ public static bool ValidateSelector ( string selector ) {
40+ return CSSSpec . rgx . Matches ( selector ) . Count > 0 ;
4141 }
4242
43+ // Token: 0x06003A6D RID: 14957 RVA: 0x000E49D4 File Offset: 0x000E2BD4
4344 public static bool ParseSelector ( string selector , out StyleSelectorPart [ ] parts ) {
4445 MatchCollection matchCollection = CSSSpec . rgx . Matches ( selector ) ;
4546 int count = matchCollection . Count ;
46- if ( count < 1 ) {
47- parts = ( StyleSelectorPart [ ] ) null ;
48- return false ;
49- }
50- parts = new StyleSelectorPart [ count ] ;
51- for ( int i = 0 ; i < count ; ++ i ) {
52- Match match = matchCollection [ i ] ;
53- StyleSelectorType styleSelectorType = StyleSelectorType . Unknown ;
54- string str1 = string . Empty ;
55- if ( ! string . IsNullOrEmpty ( match . Groups [ "wildcard" ] . Value ) ) {
56- str1 = "*" ;
57- styleSelectorType = StyleSelectorType . Wildcard ;
58- } else if ( ! string . IsNullOrEmpty ( match . Groups [ "id" ] . Value ) ) {
59- str1 = match . Groups [ "id" ] . Value . Substring ( 1 ) ;
60- styleSelectorType = StyleSelectorType . ID ;
61- } else if ( ! string . IsNullOrEmpty ( match . Groups [ "class" ] . Value ) ) {
62- str1 = match . Groups [ "class" ] . Value . Substring ( 1 ) ;
63- styleSelectorType = StyleSelectorType . Class ;
64- } else if ( ! string . IsNullOrEmpty ( match . Groups [ "pseudoclass" ] . Value ) ) {
65- string str2 = match . Groups [ "param" ] . Value ;
66- if ( ! string . IsNullOrEmpty ( str2 ) ) {
67- str1 = str2 ;
68- styleSelectorType = StyleSelectorType . RecursivePseudoClass ;
47+ bool flag = count < 1 ;
48+ bool result ;
49+ if ( flag ) {
50+ parts = null ;
51+ result = false ;
52+ } else {
53+ parts = new StyleSelectorPart [ count ] ;
54+ for ( int i = 0 ; i < count ; i ++ ) {
55+ Match match = matchCollection [ i ] ;
56+ StyleSelectorType type = StyleSelectorType . Unknown ;
57+ string value = string . Empty ;
58+ bool flag2 = ! string . IsNullOrEmpty ( match . Groups [ "wildcard" ] . Value ) ;
59+ if ( flag2 ) {
60+ value = "*" ;
61+ type = StyleSelectorType . Wildcard ;
6962 } else {
70- str1 = match . Groups [ "pseudoclass" ] . Value . Substring ( 1 ) ;
71- styleSelectorType = StyleSelectorType . PseudoClass ;
63+ bool flag3 = ! string . IsNullOrEmpty ( match . Groups [ "id" ] . Value ) ;
64+ if ( flag3 ) {
65+ value = match . Groups [ "id" ] . Value . Substring ( 1 ) ;
66+ type = StyleSelectorType . ID ;
67+ } else {
68+ bool flag4 = ! string . IsNullOrEmpty ( match . Groups [ "class" ] . Value ) ;
69+ if ( flag4 ) {
70+ value = match . Groups [ "class" ] . Value . Substring ( 1 ) ;
71+ type = StyleSelectorType . Class ;
72+ } else {
73+ bool flag5 = ! string . IsNullOrEmpty ( match . Groups [ "pseudoclass" ] . Value ) ;
74+ if ( flag5 ) {
75+ string value2 = match . Groups [ "param" ] . Value ;
76+ bool flag6 = ! string . IsNullOrEmpty ( value2 ) ;
77+ if ( flag6 ) {
78+ value = value2 ;
79+ type = StyleSelectorType . RecursivePseudoClass ;
80+ } else {
81+ value = match . Groups [ "pseudoclass" ] . Value . Substring ( 1 ) ;
82+ type = StyleSelectorType . PseudoClass ;
83+ }
84+ } else {
85+ bool flag7 = ! string . IsNullOrEmpty ( match . Groups [ "type" ] . Value ) ;
86+ if ( flag7 ) {
87+ value = match . Groups [ "type" ] . Value ;
88+ type = StyleSelectorType . Type ;
89+ }
90+ }
91+ }
92+ }
7293 }
73- } else if ( ! string . IsNullOrEmpty ( match . Groups [ "type" ] . Value ) ) {
74- str1 = match . Groups [ "type" ] . Value ;
75- styleSelectorType = StyleSelectorType . Type ;
94+ parts [ i ] = new StyleSelectorPart {
95+ type = type ,
96+ value = value
97+ } ;
7698 }
77- parts [ i ] = new StyleSelectorPart ( ) {
78- type = styleSelectorType ,
79- value = str1
80- } ;
99+ result = true ;
81100 }
82- return true ;
101+ return result ;
83102 }
103+
104+ // Token: 0x04001D3E RID: 7486
105+ private static readonly Regex rgx = new Regex ( "(?<id>#[-]?\\ w[\\ w-]*)|(?<class>\\ .[\\ w-]+)|(?<pseudoclass>:[\\ w-]+(\\ ((?<param>.+)\\ ))?)|(?<type>([^\\ -]\\ w+|\\ w+))|(?<wildcard>\\ *)|\\ s+" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
106+
107+ // Token: 0x04001D3F RID: 7487
108+ private const int typeSelectorWeight = 1 ;
109+
110+ // Token: 0x04001D40 RID: 7488
111+ private const int classSelectorWeight = 10 ;
112+
113+ // Token: 0x04001D41 RID: 7489
114+ private const int idSelectorWeight = 100 ;
84115 }
85116}
0 commit comments