Skip to content

Commit 57b42ba

Browse files
authored
Merge pull request MyIntervals#144 from raxbg/unicode_range
Unicode range
2 parents acc248c + e24df96 commit 57b42ba

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lib/Sabberworm/CSS/Value/Value.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public static function parsePrimitiveValue(ParserState $oParserState) {
9292
$oValue = self::parseMicrosoftFilter($oParserState);
9393
} else if ($oParserState->comes("[")) {
9494
$oValue = LineName::parse($oParserState);
95+
} else if ($oParserState->comes("U+")) {
96+
$oValue = self::parseUnicodeRangeValue($oParserState);
9597
} else {
9698
$oValue = self::parseIdentifierOrFunction($oParserState);
9799
}
@@ -104,6 +106,17 @@ private static function parseMicrosoftFilter(ParserState $oParserState) {
104106
$aArguments = Value::parseValue($oParserState, array(',', '='));
105107
return new CSSFunction($sFunction, $aArguments, ',', $oParserState->currentLine());
106108
}
109+
110+
private static function parseUnicodeRangeValue(ParserState $oParserState) {
111+
$iCodepointMaxLenth = 6; // Code points outside BMP can use up to six digits
112+
$sRange = "";
113+
$oParserState->consume("U+");
114+
do {
115+
if ($oParserState->comes('-')) $iCodepointMaxLenth = 13; // Max length is 2 six digit code points + the dash(-) between them
116+
$sRange .= $oParserState->consume(1);
117+
} while (strlen($sRange) < $iCodepointMaxLenth && preg_match("/[A-Fa-f0-9\?-]/", $oParserState->peek()));
118+
return "U+{$sRange}";
119+
}
107120

108121
/**
109122
* @return int

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ function testUnicodeParsing() {
126126
}
127127
}
128128

129+
function testUnicodeRangeParsing() {
130+
$oDoc = $this->parsedStructureForFile('unicode-range');
131+
$sExpected = "@font-face {unicode-range: U+0100-024F,U+0259,U+1E??-2EFF,U+202F;}";
132+
$this->assertSame($sExpected, $oDoc->render());
133+
}
134+
129135
function testSpecificity() {
130136
$oDoc = $this->parsedStructureForFile('specificity');
131137
$oDeclarationBlock = $oDoc->getAllDeclarationBlocks();

tests/files/unicode-range.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@font-face {
2+
unicode-range: U+0100-024F, U+0259, U+1E??-2EFF, U+202F;
3+
}

0 commit comments

Comments
 (0)