@@ -38,26 +38,21 @@ public static function parse(ParserState $oParserState, $bIsColorComponent = fal
38
38
}
39
39
40
40
$ sUnit = null ;
41
- $ sParsedUnit = null ;
42
41
$ aSizeUnits = self ::getSizeUnits ();
43
-
44
42
$ iMaxSizeUnitLength = max (array_keys ($ aSizeUnits ));
43
+
45
44
if ( preg_match ( '/^[a-zA-Z0-9%]+/ ' , $ oParserState ->peek ($ iMaxSizeUnitLength ), $ matches ) ) {
46
- $ sParsedUnit = $ matches [0 ];
47
- }
45
+ $ sUnit = strtolower ( $ matches [0 ]) ;
46
+ $ iUnitLength = strlen ( $ sUnit );
48
47
49
- foreach ($ aSizeUnits as $ iLength => $ aValues ) {
50
- $ sKey = strtolower ($ oParserState ->peek ($ iLength ));
51
- if (array_key_exists ($ sKey , $ aValues )) {
52
- if (strtolower ($ sParsedUnit ) !== $ sKey ) {
53
- throw new UnexpectedTokenException ('Unit ' , $ sParsedUnit , 'identifier ' , $ oParserState ->currentLine ());
54
- }
55
- if (($ sUnit = $ aValues [$ sKey ]) !== null ) {
56
- $ oParserState ->consume ($ iLength );
57
- break ;
58
- }
48
+ if (isset ($ aSizeUnits [$ iUnitLength ][$ sUnit ])) {
49
+ $ sUnit = $ aSizeUnits [$ iUnitLength ][$ sUnit ];
50
+ $ oParserState ->consume ($ iUnitLength );
51
+ } else {
52
+ throw new UnexpectedTokenException ('Unit ' , $ sUnit , 'identifier ' , $ oParserState ->currentLine ());
59
53
}
60
54
}
55
+
61
56
return new Size (floatval ($ sSize ), $ sUnit , $ bIsColorComponent , $ oParserState ->currentLine ());
62
57
}
63
58
0 commit comments