|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace UCD\Infrastructure\Repository\CharacterRepository\XMLRepository\ElementParser\Properties; |
|
4
|
|
|
|
|
5
|
|
|
use UCD\Unicode\Character\Properties\Normalization; |
|
6
|
|
|
use UCD\Unicode\Character\Properties\Normalization\Combining; |
|
7
|
|
|
use UCD\Unicode\Character\Properties\Normalization\Decomposition; |
|
8
|
|
|
use UCD\Unicode\Character\Properties\Normalization\Decomposition\Assigned; |
|
9
|
|
|
use UCD\Unicode\Character\Properties\Normalization\Decomposition\Nil; |
|
10
|
|
|
use UCD\Unicode\Character\Properties\Normalization\DecompositionType; |
|
11
|
|
|
|
|
12
|
|
|
class NormalizationParser extends BaseParser |
|
13
|
|
|
{ |
|
14
|
|
|
const ATTR_CANONICAL_COMBINING_CLASS = 'ccc'; |
|
15
|
|
|
const ATTR_DECOMPOSITION_TYPE = 'dt'; |
|
16
|
|
|
const ATTR_DECOMPOSITION_MAPPING = 'dm'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @return Normalization |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function parse() |
|
22
|
|
|
{ |
|
23
|
|
|
$combining = $this->parseCombiningClass(); |
|
24
|
|
|
$decomposition = $this->parseDecomposition(); |
|
25
|
|
|
|
|
26
|
|
|
return new Normalization($combining, $decomposition); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @return Decomposition |
|
31
|
|
|
*/ |
|
32
|
|
|
private function parseDecomposition() |
|
33
|
|
|
{ |
|
34
|
|
|
$decompositionType = $this->parseDecompositionType(); |
|
35
|
|
|
$mapping = $this->getAttribute(self::ATTR_DECOMPOSITION_MAPPING); |
|
36
|
|
|
$placeholders = $this->parsePlaceholders($mapping, $this->codepoint); |
|
37
|
|
|
$decompositionMap = $this->parseCodepointList($placeholders); |
|
38
|
|
|
$count = count($decompositionMap); |
|
39
|
|
|
$isNil = $count === 0 || ($count === 1 && $decompositionMap[0]->equals($this->codepoint)); |
|
40
|
|
|
|
|
41
|
|
|
if ($isNil) { |
|
42
|
|
|
return new Nil($decompositionType); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return new Assigned($decompositionType, $decompositionMap); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return DecompositionType |
|
50
|
|
|
*/ |
|
51
|
|
|
private function parseDecompositionType() |
|
52
|
|
|
{ |
|
53
|
|
|
return new DecompositionType($this->getAttribute(self::ATTR_DECOMPOSITION_TYPE)); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return Combining |
|
58
|
|
|
*/ |
|
59
|
|
|
private function parseCombiningClass() |
|
60
|
|
|
{ |
|
61
|
|
|
return new Combining((int)$this->getAttribute(self::ATTR_CANONICAL_COMBINING_CLASS)); |
|
62
|
|
|
} |
|
63
|
|
|
} |