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 bda8674 commit 510b017
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,39 @@ composer require cybercog/php-unicode
### Instantiate CodePoint object

```php
$codePoint = CodePoint::ofCharacter('A');
$codePoint = \Cog\Unicode\CodePoint::ofCharacter('ΓΏ');

$codePoint = CodePoint::ofDecimal(65);
$codePoint = \Cog\Unicode\CodePoint::ofDecimal(255);

$codePoint = CodePoint::ofHexadecimal('U+0041');
$codePoint = \Cog\Unicode\CodePoint::ofHexadecimal('U+00FF');

$codePoint = \Cog\Unicode\CodePoint::ofHtmlEntity('ÿ');

$codePoint = \Cog\Unicode\CodePoint::ofXmlEntity('ÿ');
```

### Represent code points in any format

```php
$codePoint = CodePoint::ofCharacter('A');
$codePoint = \Cog\Unicode\CodePoint::ofCharacter('ΓΏ');

echo $codePoint->toCharacter(); // (string) "ΓΏ"

echo $codePoint->toDecimal(); // (int) 255

echo $codePoint->toHexadecimal(); // (string) "U+00FF"

echo $codePoint->toCharacter(); // (string) "A"
echo $codePoint->toHtmlEntity(); // (string) "ÿ"

echo $codePoint->toDecimal(); // (int) 65
echo $codePoint->toXmlEntity(); // (string) "ÿ"
```

### Instantiate CompositeCharacter object

```php
$compositeCharacter = \Cog\Unicode\CompositeCharacter::ofCharacters('πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦');

echo $codePoint->toHexadecimal(); // (string) "U+0041"
$compositeCharacter->toCharacters(); // (string) "πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦"
```

## License
Expand Down
25 changes: 22 additions & 3 deletions test/Unit/CompositeCharacterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@

final class CompositeCharacterTest extends TestCase
{
/** @dataProvider provideUnicodeMap */
public function testItCanInstantiateOfCharacters(
/** @dataProvider provideUnicodeMapSimple */
public function testItCanInstantiateOfCharactersWithSingleCharacter(
string $characters
): void {
$compositeCharacter = CompositeCharacter::ofCharacters($characters);

$this->assertSame(
$characters,
$compositeCharacter->toCharacters(),
);
}

/** @dataProvider provideUnicodeMapComposite */
public function testItCanInstantiateOfCharactersWithManyCharacters(
string $characters
): void {
$compositeCharacter = CompositeCharacter::ofCharacters($characters);
Expand All @@ -30,7 +42,7 @@ public function testItCannotInstantiateOfCharactersWithEmptyString(): void
CompositeCharacter::ofCharacters($characters);
}

public static function provideUnicodeMap(): array
public static function provideUnicodeMapSimple(): array
{
return [
["\x00"],
Expand All @@ -44,4 +56,11 @@ public static function provideUnicodeMap(): array
['οΏ½'],
];
}

public static function provideUnicodeMapComposite(): array
{
return [
['πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦'],
];
}
}

0 comments on commit 510b017

Please sign in to comment.