@@ -87,7 +87,7 @@ private function parseAtRule() {
87
87
$ this ->consume ('@ ' );
88
88
$ sIdentifier = $ this ->parseIdentifier ();
89
89
$ this ->consumeWhiteSpace ();
90
- if ($ sIdentifier === 'import ' ) {
90
+ if ($ this -> streql ( $ sIdentifier, 'import ' ) ) {
91
91
$ oLocation = $ this ->parseURLValue ();
92
92
$ this ->consumeWhiteSpace ();
93
93
$ sMediaQuery = null ;
@@ -96,7 +96,7 @@ private function parseAtRule() {
96
96
}
97
97
$ this ->consume ('; ' );
98
98
return new Import ($ oLocation , $ sMediaQuery );
99
- } else if ($ sIdentifier === 'charset ' ) {
99
+ } else if ($ this -> streql ( $ sIdentifier, 'charset ' ) ) {
100
100
$ sCharset = $ this ->parseStringValue ();
101
101
$ this ->consumeWhiteSpace ();
102
102
$ this ->consume ('; ' );
@@ -110,7 +110,7 @@ private function parseAtRule() {
110
110
$ this ->consumeWhiteSpace ();
111
111
$ this ->parseList ($ oResult );
112
112
return $ oResult ;
113
- } else if ($ sIdentifier === 'namespace ' ) {
113
+ } else if ($ this -> streql ( $ sIdentifier, 'namespace ' ) ) {
114
114
$ sPrefix = null ;
115
115
$ mUrl = $ this ->parsePrimitiveValue ();
116
116
if (!$ this ->comes ('; ' )) {
@@ -148,7 +148,7 @@ private function parseAtRule() {
148
148
}
149
149
}
150
150
151
- private function parseIdentifier ($ bAllowFunctions = true ) {
151
+ private function parseIdentifier ($ bAllowFunctions = true , $ bIgnoreCase = true ) {
152
152
$ sResult = $ this ->parseCharacter (true );
153
153
if ($ sResult === null ) {
154
154
throw new UnexpectedTokenException ($ sResult , $ this ->peek (5 ), 'identifier ' );
@@ -157,6 +157,9 @@ private function parseIdentifier($bAllowFunctions = true) {
157
157
while (($ sCharacter = $ this ->parseCharacter (true )) !== null ) {
158
158
$ sResult .= $ sCharacter ;
159
159
}
160
+ if ($ bIgnoreCase ) {
161
+ $ sResult = $ this ->strtolower ($ sResult );
162
+ }
160
163
if ($ bAllowFunctions && $ this ->comes ('( ' )) {
161
164
$ this ->consume ('( ' );
162
165
$ aArguments = $ this ->parseValue (array ('= ' , ' ' , ', ' ));
@@ -287,10 +290,7 @@ private function parseRule() {
287
290
if ($ this ->comes ('! ' )) {
288
291
$ this ->consume ('! ' );
289
292
$ this ->consumeWhiteSpace ();
290
- $ sImportantMarker = $ this ->consume (strlen ('important ' ));
291
- if (mb_convert_case ($ sImportantMarker , MB_CASE_LOWER , $ this ->sCharset ) !== 'important ' ) {
292
- throw new \Exception ("! was followed by “ " . $ sImportantMarker . "”. Expected “important” " );
293
- }
293
+ $ this ->consume ('important ' );
294
294
$ oRule ->setIsImportant (true );
295
295
}
296
296
while ($ this ->comes ('; ' )) {
@@ -366,7 +366,7 @@ private function parsePrimitiveValue() {
366
366
} else if ($ this ->comes ("' " ) || $ this ->comes ('" ' )) {
367
367
$ oValue = $ this ->parseStringValue ();
368
368
} else {
369
- $ oValue = $ this ->parseIdentifier ();
369
+ $ oValue = $ this ->parseIdentifier (true , false );
370
370
}
371
371
$ this ->consumeWhiteSpace ();
372
372
return $ oValue ;
@@ -385,22 +385,14 @@ private function parseNumericValue($bForColor = false) {
385
385
}
386
386
}
387
387
$ fSize = floatval ($ sSize );
388
-
389
388
$ sUnit = null ;
390
- $ units = array (
391
- '% ' , 'em ' , 'ex ' , 'px ' , 'deg ' , 's ' , 'cm ' , 'pt ' , 'in ' , 'pc ' , 'cm ' ,
392
- 'mm ' ,
393
- // These are non "size" values, but they are still numeric
394
- 'deg ' , 'grad ' , 'rad ' , 'turns ' , 's ' , 'ms ' , 'Hz ' , 'kHz '
395
- );
396
-
397
- foreach ($ units as $ val ) {
398
- if ($ this ->comes ($ val )) {
399
- $ sUnit = $ this ->consume ($ val );
389
+ foreach (explode ('/ ' , Size::ABSOLUTE_SIZE_UNITS .'/ ' .Size::RELATIVE_SIZE_UNITS .'/ ' .Size::NON_SIZE_UNITS ) as $ sDefinedUnit ) {
390
+ if ($ this ->comes ($ sDefinedUnit , 0 , true )) {
391
+ $ sUnit = $ sDefinedUnit ;
392
+ $ this ->consume ($ sDefinedUnit );
400
393
break ;
401
394
}
402
395
}
403
-
404
396
return new Size ($ fSize , $ sUnit , $ bForColor );
405
397
}
406
398
@@ -450,15 +442,16 @@ private function parseURLValue() {
450
442
/**
451
443
* Tests an identifier for a given value. Since identifiers are all keywords, they can be vendor-prefixed. We need to check for these versions too.
452
444
*/
453
- private static function identifierIs ($ sIdentifier , $ sMatch ) {
454
- return preg_match ("/^(- \\w+-)? $ sMatch$/ " , $ sIdentifier ) === 1 ;
445
+ private static function identifierIs ($ sIdentifier , $ sMatch, $ bCaseInsensitive = true ) {
446
+ return preg_match ("/^(- \\w+-)? $ sMatch$/ " .( $ bCaseInsensitive ? ' i ' : '' ) , $ sIdentifier ) === 1 ;
455
447
}
456
448
457
- private function comes ($ sString , $ iOffset = 0 ) {
449
+ private function comes ($ sString , $ iOffset = 0 , $ bCaseInsensitive = true ) {
458
450
if ($ this ->isEnd ()) {
459
451
return false ;
460
452
}
461
- return $ this ->peek ($ sString , $ iOffset ) == $ sString ;
453
+ $ sPeek = $ this ->peek ($ sString , $ iOffset );
454
+ return $ this ->streql ($ sPeek , $ sString , $ bCaseInsensitive );
462
455
}
463
456
464
457
private function peek ($ iLength = 1 , $ iOffset = 0 ) {
@@ -482,7 +475,7 @@ private function peek($iLength = 1, $iOffset = 0) {
482
475
private function consume ($ mValue = 1 ) {
483
476
if (is_string ($ mValue )) {
484
477
$ iLength = $ this ->strlen ($ mValue );
485
- if ($ this ->substr ($ this ->sText , $ this ->iCurrentPosition , $ iLength ) !== $ mValue ) {
478
+ if (! $ this ->streql ( $ this -> substr ($ this ->sText , $ this ->iCurrentPosition , $ iLength ), $ mValue) ) {
486
479
throw new UnexpectedTokenException ($ mValue , $ this ->peek (max ($ iLength , 5 )));
487
480
}
488
481
$ this ->iCurrentPosition += $ this ->strlen ($ mValue );
@@ -530,7 +523,7 @@ private function consumeUntil($aEnd, $bIncludeEnd = false) {
530
523
$ aEnd = is_array ($ aEnd ) ? $ aEnd : array ($ aEnd );
531
524
$ iEndPos = null ;
532
525
foreach ($ aEnd as $ sEnd ) {
533
- $ iCurrentEndPos = $ this ->strpos ($ this ->sText , $ sEnd , $ this ->iCurrentPosition , $ this -> sCharset );
526
+ $ iCurrentEndPos = $ this ->strpos ($ this ->sText , $ sEnd , $ this ->iCurrentPosition );
534
527
if ($ iCurrentEndPos === false ) {
535
528
continue ;
536
529
}
@@ -548,27 +541,43 @@ private function inputLeft() {
548
541
return $ this ->substr ($ this ->sText , $ this ->iCurrentPosition , -1 );
549
542
}
550
543
551
- private function substr ($ string , $ start , $ length ) {
544
+ private function substr ($ sString , $ iStart , $ iLength ) {
552
545
if ($ this ->oParserSettings ->bMultibyteSupport ) {
553
- return mb_substr ($ string , $ start , $ length , $ this ->sCharset );
546
+ return mb_substr ($ sString , $ iStart , $ iLength , $ this ->sCharset );
547
+ } else {
548
+ return substr ($ sString , $ iStart , $ iLength );
549
+ }
550
+ }
551
+
552
+ private function strlen ($ sString ) {
553
+ if ($ this ->oParserSettings ->bMultibyteSupport ) {
554
+ return mb_strlen ($ sString , $ this ->sCharset );
555
+ } else {
556
+ return strlen ($ sString );
557
+ }
558
+ }
559
+
560
+ private function streql ($ sString1 , $ sString2 , $ bCaseInsensitive = true ) {
561
+ if ($ bCaseInsensitive ) {
562
+ return $ this ->strtolower ($ sString1 ) === $ this ->strtolower ($ sString2 );
554
563
} else {
555
- return substr ( $ string , $ start , $ length ) ;
564
+ return $ sString1 === $ sString2 ;
556
565
}
557
566
}
558
567
559
- private function strlen ( $ text ) {
568
+ private function strtolower ( $ sString ) {
560
569
if ($ this ->oParserSettings ->bMultibyteSupport ) {
561
- return mb_strlen ( $ text , $ this ->sCharset );
570
+ return mb_strtolower ( $ sString , $ this ->sCharset );
562
571
} else {
563
- return strlen ( $ text );
572
+ return strtolower ( $ sString );
564
573
}
565
574
}
566
575
567
- private function strpos ($ text , $ needle , $ offset , $ charset ) {
576
+ private function strpos ($ sString , $ sNeedle , $ iOffset ) {
568
577
if ($ this ->oParserSettings ->bMultibyteSupport ) {
569
- return mb_strpos ($ text , $ needle , $ offset , $ charset );
578
+ return mb_strpos ($ sString , $ sNeedle , $ iOffset , $ this -> sCharset );
570
579
} else {
571
- return strpos ($ text , $ needle , $ offset );
580
+ return strpos ($ sString , $ sNeedle , $ iOffset );
572
581
}
573
582
}
574
583
0 commit comments