Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/Sabberworm/CSS/Value/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/Sabberworm/CSS/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions tests/files/unicode-range.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@font-face {
unicode-range: U+0100-024F, U+0259, U+1E??-2EFF, U+202F;
}