Skip to content

Commit

Permalink
Add XML parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev committed Oct 14, 2023
1 parent 0a37ac2 commit ed5c4b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
5 changes: 1 addition & 4 deletions src/CodePoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ public function toHtmlEntity(): string

public function toXmlEntity(): string
{
return htmlentities(
$this->toCharacter(),
ENT_XML1 | ENT_QUOTES | ENT_SUBSTITUTE,
);
return '&#x' . dechex($this->decimal) . ';';
}
}
28 changes: 16 additions & 12 deletions test/Unit/CodePointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ public function testItCanInstantiateOfXmlEntity(
string $htmlEntity,
string $xmlEntity
): void {
if ($xmlEntity === '�') {
$this->markTestSkipped('XML does not have NULL value');
}

$codePoint = CodePoint::ofXmlEntity($xmlEntity);

$this->assertSame(
Expand Down Expand Up @@ -253,18 +257,18 @@ public function testItCannotInstantiateOfXmlEntityWithMoreThanOneCharacter(): vo
public static function provideUnicodeMap(): array
{
return [
["\x00", 0, 'U+0000', "\x00", "\x00"],
['􏿿', 1114111, 'U+10FFFF', '􏿿', '􏿿'],
[' ', 32, 'U+0020', ' ', ' '],
['A', 65, 'U+0041', 'A', 'A'],
[' ', 160, 'U+00A0', ' ', ' '],
['ÿ', 255, 'U+00FF', 'ÿ', 'ÿ'],
['Ā', 256, 'U+0100', 'Ā', 'Ā'],
['ſ', 383, 'U+017F', 'ſ', 'ſ'],
['€', 8364, 'U+20AC', '€', ''],
['⚙', 9881, 'U+2699', '⚙', ''],
['👨', 128104, 'U+1F468', '👨', '👨'],
['�', 65533, 'U+FFFD', '�', ''],
["\x00", 0, 'U+0000', "\x00", '�'],
['􏿿', 1114111, 'U+10FFFF', '􏿿', ''],
[' ', 32, 'U+0020', ' ', ' '],
['A', 65, 'U+0041', 'A', 'A'],
[' ', 160, 'U+00A0', ' ', ' '],
['ÿ', 255, 'U+00FF', 'ÿ', 'ÿ'],
['Ā', 256, 'U+0100', 'Ā', 'Ā'],
['ſ', 383, 'U+017F', 'ſ', 'ſ'],
['€', 8364, 'U+20AC', '€', '€'],
['⚙', 9881, 'U+2699', '⚙', '⚙'],
['👨', 128104, 'U+1F468', '👨', '👨'],
['�', 65533, 'U+FFFD', '�', '�'],
];
}
}

0 comments on commit ed5c4b3

Please sign in to comment.