1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2008-2011 Andreas Heigl<[email protected]> |
4
|
|
|
* |
5
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
6
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
7
|
|
|
* in the Software without restriction, including without limitation the rights |
8
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
9
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
10
|
|
|
* furnished to do so, subject to the following conditions: |
11
|
|
|
* |
12
|
|
|
* The above copyright notice and this permission notice shall be included in |
13
|
|
|
* all copies or substantial portions of the Software. |
14
|
|
|
* |
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
18
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
20
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
21
|
|
|
* THE SOFTWARE. |
22
|
|
|
* |
23
|
|
|
* @category Hyphenation |
24
|
|
|
* @package Org_Heigl_Hyphenator |
25
|
|
|
* @subpackage Tokenizer |
26
|
|
|
* @author Andreas Heigl <[email protected]> |
27
|
|
|
* @copyright 2008-2011 Andreas Heigl<[email protected]> |
28
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT-License |
29
|
|
|
* @version 2.0.1 |
30
|
|
|
* @link http://github.com/heiglandreas/Hyphenator |
31
|
|
|
* @since 04.11.2011 |
32
|
|
|
*/ |
33
|
|
|
|
34
|
|
|
namespace Org\Heigl\Hyphenator\Tokenizer; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* This Class describes a default Token |
38
|
|
|
* |
39
|
|
|
* @category Hyphenation |
40
|
|
|
* @package Org_Heigl_Hyphenator |
41
|
|
|
* @subpackage Tokenizer |
42
|
|
|
* @author Andreas Heigl <[email protected]> |
43
|
|
|
* @copyright 2008-2011 Andreas Heigl<[email protected]> |
44
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT-License |
45
|
|
|
* @version 2.0.1 |
46
|
|
|
* @link http://github.com/heiglandreas/Hyphenator |
47
|
|
|
* @since 04.11.2011 |
48
|
|
|
*/ |
49
|
|
|
class Token |
50
|
|
|
{ |
51
|
|
|
/** |
52
|
|
|
* The content of the token. |
53
|
|
|
* |
54
|
|
|
* @var string $content |
55
|
|
|
*/ |
56
|
|
|
protected $content = ''; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* The filtered content of the token. |
60
|
|
|
* |
61
|
|
|
* @var string $filteredContent |
62
|
|
|
*/ |
63
|
|
|
protected $filteredContent = ''; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* The hyphenated token. |
67
|
|
|
* |
68
|
|
|
* @var array $hyphenatedContent |
69
|
|
|
*/ |
70
|
|
|
protected $hyphenatedContent = array(); |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* The hyphenation patterns for this token. |
74
|
|
|
* |
75
|
|
|
* @var array $pattern |
76
|
|
|
*/ |
77
|
|
|
protected $pattern = array(); |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Create the Token |
81
|
|
|
* |
82
|
|
|
* @param string $content The content to be stored in the token. |
83
|
|
|
*/ |
84
|
|
|
public function __construct($content) |
85
|
|
|
{ |
86
|
|
|
$this->content = $content; |
87
|
|
|
$this->hyphenatedContent = array( $content ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Get the tokens content |
92
|
|
|
* |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function get() |
96
|
|
|
{ |
97
|
|
|
return $this->content; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Set the tokens hyphenated content |
102
|
|
|
* |
103
|
|
|
* @param array $hyphenatedContent all possible hyphenations |
104
|
|
|
* |
105
|
|
|
* @return Token |
106
|
|
|
*/ |
107
|
|
|
public function setHyphenatedContent(array $hyphenatedContent) |
108
|
|
|
{ |
109
|
|
|
$this->hyphenatedContent = $hyphenatedContent; |
110
|
|
|
|
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Get the hyphenated content |
116
|
|
|
* |
117
|
|
|
* @return array |
118
|
|
|
*/ |
119
|
|
|
public function getHyphenatedContent() |
120
|
|
|
{ |
121
|
|
|
return $this->hyphenatedContent; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Get the type of this token |
126
|
|
|
* |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
public function getType() |
130
|
|
|
{ |
131
|
|
|
return get_class($this); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Get the already filtered content of the token. |
136
|
|
|
* |
137
|
|
|
* @return string |
138
|
|
|
*/ |
139
|
|
|
public function getFilteredContent() |
140
|
|
|
{ |
141
|
|
|
if (! $this->filteredContent) { |
142
|
|
|
return $this->content; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return $this->filteredContent; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Set the filtered content |
150
|
|
|
* |
151
|
|
|
* @param string $content The Filtered Content |
152
|
|
|
* |
153
|
|
|
* @return Token |
154
|
|
|
*/ |
155
|
|
|
public function setFilteredContent($content) |
156
|
|
|
{ |
157
|
|
|
$this->filteredContent = $content; |
158
|
|
|
|
159
|
|
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Get the length of the contained (unhyphenated) token |
164
|
|
|
* |
165
|
|
|
* @return int |
166
|
|
|
*/ |
167
|
|
|
public function length() |
168
|
|
|
{ |
169
|
|
|
return mb_strlen($this->content); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|