Skip to content

Commit 510b017

Browse files
committed
Add XML parsing
1 parent bda8674 commit 510b017

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,39 @@ composer require cybercog/php-unicode
2323
### Instantiate CodePoint object
2424

2525
```php
26-
$codePoint = CodePoint::ofCharacter('A');
26+
$codePoint = \Cog\Unicode\CodePoint::ofCharacter('ÿ');
2727

28-
$codePoint = CodePoint::ofDecimal(65);
28+
$codePoint = \Cog\Unicode\CodePoint::ofDecimal(255);
2929

30-
$codePoint = CodePoint::ofHexadecimal('U+0041');
30+
$codePoint = \Cog\Unicode\CodePoint::ofHexadecimal('U+00FF');
31+
32+
$codePoint = \Cog\Unicode\CodePoint::ofHtmlEntity('ÿ');
33+
34+
$codePoint = \Cog\Unicode\CodePoint::ofXmlEntity('ÿ');
3135
```
3236

3337
### Represent code points in any format
3438

3539
```php
36-
$codePoint = CodePoint::ofCharacter('A');
40+
$codePoint = \Cog\Unicode\CodePoint::ofCharacter('ÿ');
41+
42+
echo $codePoint->toCharacter(); // (string) "ÿ"
43+
44+
echo $codePoint->toDecimal(); // (int) 255
45+
46+
echo $codePoint->toHexadecimal(); // (string) "U+00FF"
3747

38-
echo $codePoint->toCharacter(); // (string) "A"
48+
echo $codePoint->toHtmlEntity(); // (string) "ÿ"
3949

40-
echo $codePoint->toDecimal(); // (int) 65
50+
echo $codePoint->toXmlEntity(); // (string) "ÿ"
51+
```
52+
53+
### Instantiate CompositeCharacter object
54+
55+
```php
56+
$compositeCharacter = \Cog\Unicode\CompositeCharacter::ofCharacters('👨‍👩‍👧‍👦');
4157

42-
echo $codePoint->toHexadecimal(); // (string) "U+0041"
58+
$compositeCharacter->toCharacters(); // (string) "👨‍👩‍👧‍👦"
4359
```
4460

4561
## License

test/Unit/CompositeCharacterTest.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,20 @@
99

1010
final class CompositeCharacterTest extends TestCase
1111
{
12-
/** @dataProvider provideUnicodeMap */
13-
public function testItCanInstantiateOfCharacters(
12+
/** @dataProvider provideUnicodeMapSimple */
13+
public function testItCanInstantiateOfCharactersWithSingleCharacter(
14+
string $characters
15+
): void {
16+
$compositeCharacter = CompositeCharacter::ofCharacters($characters);
17+
18+
$this->assertSame(
19+
$characters,
20+
$compositeCharacter->toCharacters(),
21+
);
22+
}
23+
24+
/** @dataProvider provideUnicodeMapComposite */
25+
public function testItCanInstantiateOfCharactersWithManyCharacters(
1426
string $characters
1527
): void {
1628
$compositeCharacter = CompositeCharacter::ofCharacters($characters);
@@ -30,7 +42,7 @@ public function testItCannotInstantiateOfCharactersWithEmptyString(): void
3042
CompositeCharacter::ofCharacters($characters);
3143
}
3244

33-
public static function provideUnicodeMap(): array
45+
public static function provideUnicodeMapSimple(): array
3446
{
3547
return [
3648
["\x00"],
@@ -44,4 +56,11 @@ public static function provideUnicodeMap(): array
4456
[''],
4557
];
4658
}
59+
60+
public static function provideUnicodeMapComposite(): array
61+
{
62+
return [
63+
['👨‍👩‍👧‍👦'],
64+
];
65+
}
4766
}

0 commit comments

Comments
 (0)