@@ -92,7 +92,7 @@ private function parseAtRule() {
9292 }
9393 }
9494
95- private function parseIdentifier () {
95+ private function parseIdentifier ($ bAllowFunctions = true ) {
9696 $ sResult = $ this ->parseCharacter (true );
9797 if ($ sResult === null ) {
9898 throw new Exception ("Identifier expected, got {$ this ->peek (5 )}" );
@@ -101,6 +101,11 @@ private function parseIdentifier() {
101101 while (($ sCharacter = $ this ->parseCharacter (true )) !== null ) {
102102 $ sResult .= $ sCharacter ;
103103 }
104+ if ($ bAllowFunctions && $ this ->comes ('( ' )) {
105+ $ this ->consume ('( ' );
106+ $ sResult = new CSSFunction ($ sResult , $ this ->parseValue ());
107+ $ this ->consume (') ' );
108+ }
104109 return $ sResult ;
105110 }
106111
@@ -297,13 +302,13 @@ private function parseColorValue() {
297302 $ aColor = array ();
298303 if ($ this ->comes ('# ' )) {
299304 $ this ->consume ('# ' );
300- $ sValue = $ this ->parseIdentifier ();
305+ $ sValue = $ this ->parseIdentifier (false );
301306 if (mb_strlen ($ sValue , $ this ->sCharset ) === 3 ) {
302307 $ sValue = $ sValue [0 ].$ sValue [0 ].$ sValue [1 ].$ sValue [1 ].$ sValue [2 ].$ sValue [2 ];
303308 }
304309 $ aColor = array ('r ' => new CSSSize (intval ($ sValue [0 ].$ sValue [1 ], 16 )), 'g ' => new CSSSize (intval ($ sValue [2 ].$ sValue [3 ], 16 )), 'b ' => new CSSSize (intval ($ sValue [4 ].$ sValue [5 ], 16 )));
305310 } else {
306- $ sColorMode = $ this ->parseIdentifier ();
311+ $ sColorMode = $ this ->parseIdentifier (false );
307312 $ this ->consumeWhiteSpace ();
308313 $ this ->consume ('( ' );
309314 $ iLength = mb_strlen ($ sColorMode , $ this ->sCharset );
@@ -1034,3 +1039,26 @@ public function __toString() {
10341039 return "$ oValue1/ $ oValue2 " ;
10351040 }
10361041}
1042+
1043+ class CSSFunction extends CSSValue {
1044+ private $ sName ;
1045+ private $ aContents ;
1046+
1047+ public function __construct ($ sName , $ aContents ) {
1048+ $ this ->sName = $ sName ;
1049+ $ this ->aContents = $ aContents ;
1050+ }
1051+
1052+ public function getName () {
1053+ return $ this ->sName ;
1054+ }
1055+
1056+ public function getContents () {
1057+ return $ this ->aContents ;
1058+ }
1059+
1060+ public function __toString () {
1061+ $ sContents = implode (', ' , $ this ->aContents );
1062+ return "{$ this ->sName }( {$ sContents }) " ;
1063+ }
1064+ }
0 commit comments