50 self::_initializeMaps();
62 $this->_charset = $charset;
63 $this->_charReader = null;
73 $this->_charReaderFactory = $factory;
83 if (!isset($this->_charReader)) {
84 $this->_charReader = $this->_charReaderFactory
85 ->getReaderFor($this->_charset);
88 $startLength = $this->_charReader->getInitialByteSize();
89 while (
false !== $bytes = $os->
read($startLength)) {
91 for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
92 $c[] = self::$_byteMap[$bytes[$i]];
95 $need = $this->_charReader
96 ->validateByteSequence($c, $size);
98 false !== $bytes = $os->
read($need)) {
99 for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
100 $c[] = self::$_byteMap[$bytes[$i]];
103 $this->_array[] = $c;
117 $this->
write($string);
130 if ($this->_offset == $this->_array_size) {
137 for ($i = $this->_offset; $i < $end; ++$i) {
138 if (!isset($this->_array[$i])) {
141 $arrays[] = $this->_array[$i];
145 foreach ($arrays as $array) {
146 $chars .= implode(
'', array_map(
'chr', $array));
162 if ($this->_offset == $this->_array_size) {
167 for ($i = $this->_offset; $i < $end; ++$i) {
168 if (!isset($this->_array[$i])) {
171 $arrays[] = $this->_array[$i];
175 return call_user_func_array(
'array_merge', $arrays);
185 if (!isset($this->_charReader)) {
186 $this->_charReader = $this->_charReaderFactory->getReaderFor(
190 $startLength = $this->_charReader->getInitialByteSize();
192 $fp = fopen(
'php://memory',
'w+b');
195 fseek($fp, 0, SEEK_SET);
204 if ($buf_len - $buf_pos < $startLength) {
205 $buf = array_splice($buffer, $buf_pos);
208 $buffer = array_merge($buf, $new);
209 $buf_len = count($buffer);
215 if ($buf_len - $buf_pos > 0) {
217 for ($i = 0; $i < $startLength && isset($buffer[$buf_pos]); ++$i) {
219 $bytes[] = $buffer[$buf_pos++];
221 $need = $this->_charReader->validateByteSequence(
224 if ($buf_len - $buf_pos < $need) {
228 $buffer = array_merge($buffer, $new);
229 $buf_len = count($buffer);
232 for ($i = 0; $i < $need && isset($buffer[$buf_pos]); ++$i) {
233 $bytes[] = $buffer[$buf_pos++];
236 $this->_array[] = $bytes;
239 }
while ($has_datas);
251 if ($charOffset > $this->_array_size) {
253 }
elseif ($charOffset < 0) {
256 $this->_offset = $charOffset;
265 $this->_array = array();
266 $this->_array_size = 0;
271 if (!feof($fp) && ($bytes = fread($fp, $len)) !==
false) {
273 for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
274 $buf[] = self::$_byteMap[$bytes[$i]];
285 if (!isset(self::$_charMap)) {
286 self::$_charMap = array();
287 for ($byte = 0; $byte < 256; ++$byte) {
288 self::$_charMap[$byte] = chr($byte);
290 self::$_byteMap = array_flip(self::$_charMap);