1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace UCD\Infrastructure\Repository\CharacterRepository\XMLRepository\ElementParser\Properties; |
4
|
|
|
|
5
|
|
|
use UCD\Unicode\Character\Properties\LetterCase\Mapping; |
6
|
|
|
use UCD\Unicode\Character\Properties\LetterCase; |
7
|
|
|
use UCD\Unicode\Character\Properties\LetterCase\Mappings; |
8
|
|
|
use UCD\Unicode\Codepoint; |
9
|
|
|
|
10
|
|
|
class LetterCaseParser extends BaseParser |
11
|
|
|
{ |
12
|
|
|
const ATTR_LOWERCASE_MAPPING = 'lc'; |
13
|
|
|
const ATTR_SIMPLE_LOWERCASE_MAPPING = 'slc'; |
14
|
|
|
const ATTR_UPPERCASE_MAPPING = 'uc'; |
15
|
|
|
const ATTR_SIMPLE_UPPERCASE_MAPPING = 'suc'; |
16
|
|
|
const ATTR_TITLECASE_MAPPING = 'tc'; |
17
|
|
|
const ATTR_SIMPLE_TITLECASE_MAPPING = 'stc'; |
18
|
|
|
const ATTR_FOLDING_MAPPING = 'cf'; |
19
|
|
|
const ATTR_SIMPLE_FOLDING_MAPPING = 'scf'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @return LetterCase |
23
|
|
|
*/ |
24
|
|
|
protected function parse() |
25
|
|
|
{ |
26
|
|
|
$mappings = $this->parseMappings(); |
27
|
|
|
|
28
|
|
|
return new LetterCase($mappings); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return Mappings |
33
|
|
|
*/ |
34
|
|
|
private function parseMappings() |
35
|
|
|
{ |
36
|
|
|
return new Mappings( |
37
|
|
|
$this->parseLowercaseMapping(), |
38
|
|
|
$this->parseUppercaseMapping(), |
39
|
|
|
$this->parseTitlecaseMapping(), |
40
|
|
|
$this->parseFoldingMapping() |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return Mapping |
46
|
|
|
*/ |
47
|
|
|
private function parseLowercaseMapping() |
48
|
|
|
{ |
49
|
|
|
return new Mapping( |
50
|
|
|
$this->parseSimpleMapping(self::ATTR_SIMPLE_LOWERCASE_MAPPING), |
51
|
|
|
$this->parseMapping(self::ATTR_LOWERCASE_MAPPING) |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return Mapping |
57
|
|
|
*/ |
58
|
|
|
private function parseUppercaseMapping() |
59
|
|
|
{ |
60
|
|
|
return new Mapping( |
61
|
|
|
$this->parseSimpleMapping(self::ATTR_SIMPLE_UPPERCASE_MAPPING), |
62
|
|
|
$this->parseMapping(self::ATTR_UPPERCASE_MAPPING) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return Mapping |
68
|
|
|
*/ |
69
|
|
|
private function parseTitlecaseMapping() |
70
|
|
|
{ |
71
|
|
|
return new Mapping( |
72
|
|
|
$this->parseSimpleMapping(self::ATTR_SIMPLE_TITLECASE_MAPPING), |
73
|
|
|
$this->parseMapping(self::ATTR_TITLECASE_MAPPING) |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return Mapping |
79
|
|
|
*/ |
80
|
|
|
private function parseFoldingMapping() |
81
|
|
|
{ |
82
|
|
|
return new Mapping( |
83
|
|
|
$this->parseSimpleMapping(self::ATTR_SIMPLE_FOLDING_MAPPING), |
84
|
|
|
$this->parseMapping(self::ATTR_FOLDING_MAPPING) |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param string $attribute |
90
|
|
|
* @return Codepoint[] |
91
|
|
|
*/ |
92
|
|
|
private function parseMapping($attribute) |
93
|
|
|
{ |
94
|
|
|
$list = $this->parsePlaceholders( |
95
|
|
|
$this->getAttribute($attribute), |
96
|
|
|
$this->codepoint |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
return $this->parseCodepointList($list); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param string $attribute |
105
|
|
|
* @return Codepoint |
106
|
|
|
*/ |
107
|
|
|
private function parseSimpleMapping($attribute) |
108
|
|
|
{ |
109
|
|
|
$codepoint = $this->parsePlaceholders( |
110
|
|
|
$this->getAttribute($attribute), |
111
|
|
|
$this->codepoint |
112
|
|
|
); |
113
|
|
|
|
114
|
|
|
return Codepoint::fromHex($codepoint); |
115
|
|
|
} |
116
|
|
|
} |