|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace UCD\Unicode\Character; |
|
4
|
|
|
|
|
5
|
|
|
use UCD\Unicode\Character; |
|
6
|
|
|
use UCD\Unicode\Codepoint; |
|
7
|
|
|
use UCD\Unicode\Codepoint\Range; |
|
8
|
|
|
use UCD\Unicode\CodepointAssigned; |
|
9
|
|
|
use UCD\Unicode\Collection\TraversableBackedCollection; |
|
10
|
|
|
use UCD\Unicode\NonCharacter; |
|
11
|
|
|
use UCD\Unicode\Surrogate; |
|
12
|
|
|
|
|
13
|
|
|
class Collection extends TraversableBackedCollection |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @return Codepoint\Collection|Codepoint[] |
|
17
|
|
|
*/ |
|
18
|
|
|
public function extractCodepoints() |
|
19
|
|
|
{ |
|
20
|
|
|
return new Codepoint\Collection( |
|
21
|
|
|
$this->yieldCodepoints() |
|
22
|
|
|
); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @return \Generator |
|
27
|
|
|
*/ |
|
28
|
|
|
private function yieldCodepoints() |
|
29
|
|
|
{ |
|
30
|
|
|
/** @var CodepointAssigned $character */ |
|
31
|
|
|
foreach ($this as $character) { |
|
32
|
|
|
yield $character->getCodepoint(); |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return static|Character[] |
|
38
|
|
|
*/ |
|
39
|
|
|
public function onlyCharacters() |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->filterWith(function (CodepointAssigned $assigned) { |
|
42
|
|
|
return $assigned instanceof Character; |
|
43
|
|
|
}); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return static|NonCharacter[] |
|
48
|
|
|
*/ |
|
49
|
|
|
public function onlyNonCharacters() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->filterWith(function (CodepointAssigned $assigned) { |
|
52
|
|
|
return $assigned instanceof NonCharacter; |
|
53
|
|
|
}); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return static|Surrogate[] |
|
58
|
|
|
*/ |
|
59
|
|
|
public function onlySurrogates() |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->filterWith(function (CodepointAssigned $assigned) { |
|
62
|
|
|
return $assigned instanceof Surrogate; |
|
63
|
|
|
}); |
|
64
|
|
|
} |
|
65
|
|
|
} |