77 */
88class Selector {
99
10- const
11- NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX = '/
12- (\.[\w]+) # classes
13- |
14- \[(\w+) # attributes
15- |
16- (\:( # pseudo classes
17- link|visited|active
18- |hover|focus
19- |lang
20- |target
21- |enabled|disabled|checked|indeterminate
22- |root
23- |nth-child|nth-last-child|nth-of-type|nth-last-of-type
24- |first-child|last-child|first-of-type|last-of-type
25- |only-child|only-of-type
26- |empty|contains
27- ))
28- /ix ' ,
29- ELEMENTS_AND_PSEUDO_ELEMENTS_RX = '/
30- ((^|[\s\+\>\~]+)[\w]+ # elements
31- |
32- \:{1,2}( # pseudo-elements
33- after|before
34- |first-letter|first-line
35- |selection
36- )
37- )/ix ' ;
10+ //Regexes for specificity calculations
11+ const NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX = '/
12+ (\.[\w]+) # classes
13+ |
14+ \[(\w+) # attributes
15+ |
16+ (\:( # pseudo classes
17+ link|visited|active
18+ |hover|focus
19+ |lang
20+ |target
21+ |enabled|disabled|checked|indeterminate
22+ |root
23+ |nth-child|nth-last-child|nth-of-type|nth-last-of-type
24+ |first-child|last-child|first-of-type|last-of-type
25+ |only-child|only-of-type
26+ |empty|contains
27+ ))
28+ /ix ' ;
29+
30+ const ELEMENTS_AND_PSEUDO_ELEMENTS_RX = '/
31+ ((^|[\s\+\>\~]+)[\w]+ # elements
32+ |
33+ \:{1,2}( # pseudo-elements
34+ after|before|first-letter|first-line|selection
35+ ))
36+ /ix ' ;
3837
3938 private $ sSelector ;
4039 private $ iSpecificity ;
@@ -63,7 +62,7 @@ public function getSpecificity() {
6362 if ($ this ->iSpecificity === null ) {
6463 $ a = 0 ;
6564 /// @todo should exclude \# as well as "#"
66- $ aMatches ;
65+ $ aMatches = null ;
6766 $ b = substr_count ($ this ->sSelector , '# ' );
6867 $ c = preg_match_all (self ::NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX , $ this ->sSelector , $ aMatches );
6968 $ d = preg_match_all (self ::ELEMENTS_AND_PSEUDO_ELEMENTS_RX , $ this ->sSelector , $ aMatches );
@@ -72,4 +71,4 @@ public function getSpecificity() {
7271 return $ this ->iSpecificity ;
7372 }
7473
75- }
74+ }
0 commit comments