64 if ($this->BYTEORDER == 0) {
66 $input=unpack(
'V', $this->STREAM->read(4));
67 return array_shift($input);
70 $input=unpack(
'N', $this->STREAM->read(4));
71 return array_shift($input);
76 return $this->STREAM->read($bytes);
86 if ($this->BYTEORDER == 0) {
88 return unpack(
'V'.$count, $this->STREAM->read(4 * $count));
91 return unpack(
'N'.$count, $this->STREAM->read(4 * $count));
103 if (! $Reader || isset($Reader->error) ) {
104 $this->short_circuit =
true;
111 $MAGIC1 =
"\x95\x04\x12\xde";
112 $MAGIC2 =
"\xde\x12\x04\x95";
114 $this->STREAM = $Reader;
115 $magic = $this->
read(4);
116 if ($magic == $MAGIC1) {
117 $this->BYTEORDER = 1;
118 }
elseif ($magic == $MAGIC2) {
119 $this->BYTEORDER = 0;
128 $this->total = $this->
readint();
129 $this->originals = $this->
readint();
130 $this->translations = $this->
readint();
141 if (is_array($this->cache_translations) &&
142 is_array($this->table_originals) &&
143 is_array($this->table_translations))
147 $this->STREAM->seekto($this->originals);
148 $this->table_originals = $this->
readintarray($this->total * 2);
149 $this->STREAM->seekto($this->translations);
150 $this->table_translations = $this->
readintarray($this->total * 2);
152 if ($this->enable_cache) {
153 $this->cache_translations = array ();
156 $this->STREAM->seekto($this->table_originals[
$i * 2 + 2]);
157 $original = $this->STREAM->read($this->table_originals[
$i * 2 + 1]);
158 $this->STREAM->seekto($this->table_translations[
$i * 2 + 2]);
159 $translation = $this->STREAM->read($this->table_translations[
$i * 2 + 1]);
160 $this->cache_translations[$original] = $translation;
173 $length = $this->table_originals[$num * 2 + 1];
174 $offset = $this->table_originals[$num * 2 + 2];
177 $this->STREAM->seekto($offset);
178 $data = $this->STREAM->read($length);
179 return (
string)
$data;
190 $length = $this->table_translations[$num * 2 + 1];
191 $offset = $this->table_translations[$num * 2 + 2];
194 $this->STREAM->seekto($offset);
195 $data = $this->STREAM->read($length);
196 return (
string)
$data;
209 if ((
$start == -1) or ($end == -1)) {
214 if (abs(
$start - $end) <= 1) {
221 }
else if (
$start > $end) {
226 $half = (int)((
$start + $end) / 2);
248 if ($this->short_circuit)
252 if ($this->enable_cache) {
254 if (array_key_exists($string, $this->cache_translations))
255 return $this->cache_translations[$string];
276 $expr = preg_replace(
'@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@',
'', $expr);
282 for (
$i = 0;
$i < strlen($expr);
$i++) {
293 $res .= str_repeat(
')',
$p) .
';';
315 if (! is_string($this->pluralheader)) {
316 if ($this->enable_cache) {
317 $header = $this->cache_translations[
""];
321 if (eregi(
"plural-forms: ([^\n]*)\n", $header, $regs))
324 $expr =
"nplurals=2; plural=n == 1 ? 0 : 1;";
340 $string = str_replace(
'nplurals',
"\$total",$string);
341 $string = str_replace(
"n",$n,$string);
342 $string = str_replace(
'plural',
"\$plural",$string);
362 if ($this->short_circuit) {
373 $key = $single.chr(0).$plural;
376 if ($this->enable_cache) {
377 if (! array_key_exists($key, $this->cache_translations)) {
378 return ($number != 1) ? $plural : $single;
380 $result = $this->cache_translations[$key];
381 $list = explode(chr(0),
$result);
382 return $list[$select];
387 return ($number != 1) ? $plural : $single;
390 $list = explode(chr(0),
$result);
391 return $list[$select];