diff --git a/lib/Sabberworm/CSS/Value/Value.php b/lib/Sabberworm/CSS/Value/Value.php index ae361dd7..fccc26bb 100644 --- a/lib/Sabberworm/CSS/Value/Value.php +++ b/lib/Sabberworm/CSS/Value/Value.php @@ -92,6 +92,8 @@ public static function parsePrimitiveValue(ParserState $oParserState) { $oValue = self::parseMicrosoftFilter($oParserState); } else if ($oParserState->comes("[")) { $oValue = LineName::parse($oParserState); + } else if ($oParserState->comes("U+")) { + $oValue = self::parseUnicodeRangeValue($oParserState); } else { $oValue = self::parseIdentifierOrFunction($oParserState); } @@ -104,6 +106,17 @@ private static function parseMicrosoftFilter(ParserState $oParserState) { $aArguments = Value::parseValue($oParserState, array(',', '=')); return new CSSFunction($sFunction, $aArguments, ',', $oParserState->currentLine()); } + + private static function parseUnicodeRangeValue(ParserState $oParserState) { + $iCodepointMaxLenth = 6; // Code points outside BMP can use up to six digits + $sRange = ""; + $oParserState->consume("U+"); + do { + if ($oParserState->comes('-')) $iCodepointMaxLenth = 13; // Max length is 2 six digit code points + the dash(-) between them + $sRange .= $oParserState->consume(1); + } while (strlen($sRange) < $iCodepointMaxLenth && preg_match("/[A-Fa-f0-9\?-]/", $oParserState->peek())); + return "U+{$sRange}"; + } /** * @return int diff --git a/tests/Sabberworm/CSS/ParserTest.php b/tests/Sabberworm/CSS/ParserTest.php index 0922b11e..6486c434 100644 --- a/tests/Sabberworm/CSS/ParserTest.php +++ b/tests/Sabberworm/CSS/ParserTest.php @@ -126,6 +126,12 @@ function testUnicodeParsing() { } } + function testUnicodeRangeParsing() { + $oDoc = $this->parsedStructureForFile('unicode-range'); + $sExpected = "@font-face {unicode-range: U+0100-024F,U+0259,U+1E??-2EFF,U+202F;}"; + $this->assertSame($sExpected, $oDoc->render()); + } + function testSpecificity() { $oDoc = $this->parsedStructureForFile('specificity'); $oDeclarationBlock = $oDoc->getAllDeclarationBlocks(); diff --git a/tests/files/unicode-range.css b/tests/files/unicode-range.css new file mode 100644 index 00000000..d5e152a0 --- /dev/null +++ b/tests/files/unicode-range.css @@ -0,0 +1,3 @@ +@font-face { + unicode-range: U+0100-024F, U+0259, U+1E??-2EFF, U+202F; +}