Splitter Test written. Doesn't pass.
[order_line_extra.git] / hincludes / lib / haxe / Unserializer.class.php
1 <?php
2
3 class haxe_Unserializer {
4         public function __construct($buf) {
5                 if(!php_Boot::$skip_constructor) {
6                 $this->buf = $buf;
7                 $this->length = strlen($buf);
8                 $this->pos = 0;
9                 $this->scache = new _hx_array(array());
10                 $this->cache = new _hx_array(array());
11                 $r = haxe_Unserializer::$DEFAULT_RESOLVER;
12                 if($r === null) {
13                         $r = _hx_qtype("Type");
14                         haxe_Unserializer::$DEFAULT_RESOLVER = $r;
15                 }
16                 $this->setResolver($r);
17         }}
18         public function unserialize() {
19                 switch(ord(substr($this->buf,$this->pos++,1))) {
20                 case 110:{
21                         return null;
22                 }break;
23                 case 116:{
24                         return true;
25                 }break;
26                 case 102:{
27                         return false;
28                 }break;
29                 case 122:{
30                         return 0;
31                 }break;
32                 case 105:{
33                         return $this->readDigits();
34                 }break;
35                 case 100:{
36                         $p1 = $this->pos;
37                         while(true) {
38                                 $c = ord(substr($this->buf,$this->pos,1));
39                                 if($c >= 43 && $c < 58 || $c === 101 || $c === 69) {
40                                         $this->pos++;
41                                 } else {
42                                         break;
43                                 }
44                                 unset($c);
45                         }
46                         return Std::parseFloat(_hx_substr($this->buf, $p1, $this->pos - $p1));
47                 }break;
48                 case 121:{
49                         $len = $this->readDigits();
50                         if(ord(substr($this->buf,$this->pos++,1)) !== 58 || $this->length - $this->pos < $len) {
51                                 throw new HException("Invalid string length");
52                         }
53                         $s = _hx_substr($this->buf, $this->pos, $len);
54                         $this->pos += $len;
55                         $s = urldecode($s);
56                         $this->scache->push($s);
57                         return $s;
58                 }break;
59                 case 107:{
60                         return Math::$NaN;
61                 }break;
62                 case 109:{
63                         return Math::$NEGATIVE_INFINITY;
64                 }break;
65                 case 112:{
66                         return Math::$POSITIVE_INFINITY;
67                 }break;
68                 case 97:{
69                         $buf = $this->buf;
70                         $a = new _hx_array(array());
71                         $this->cache->push($a);
72                         while(true) {
73                                 $c = ord(substr($this->buf,$this->pos,1));
74                                 if($c === 104) {
75                                         $this->pos++;
76                                         break;
77                                 }
78                                 if($c === 117) {
79                                         $this->pos++;
80                                         $n = $this->readDigits();
81                                         $a[$a->length + $n - 1] = null;
82                                         unset($n);
83                                 } else {
84                                         $a->push($this->unserialize());
85                                 }
86                                 unset($c);
87                         }
88                         return $a;
89                 }break;
90                 case 111:{
91                         $o = _hx_anonymous(array());
92                         $this->cache->push($o);
93                         $this->unserializeObject($o);
94                         return $o;
95                 }break;
96                 case 114:{
97                         $n = $this->readDigits();
98                         if($n < 0 || $n >= $this->cache->length) {
99                                 throw new HException("Invalid reference");
100                         }
101                         return $this->cache[$n];
102                 }break;
103                 case 82:{
104                         $n = $this->readDigits();
105                         if($n < 0 || $n >= $this->scache->length) {
106                                 throw new HException("Invalid string reference");
107                         }
108                         return $this->scache[$n];
109                 }break;
110                 case 120:{
111                         throw new HException($this->unserialize());
112                 }break;
113                 case 99:{
114                         $name = $this->unserialize();
115                         $cl = $this->resolver->resolveClass($name);
116                         if($cl === null) {
117                                 throw new HException("Class not found " . $name);
118                         }
119                         $o = Type::createEmptyInstance($cl);
120                         $this->cache->push($o);
121                         $this->unserializeObject($o);
122                         return $o;
123                 }break;
124                 case 119:{
125                         $name = $this->unserialize();
126                         $edecl = $this->resolver->resolveEnum($name);
127                         if($edecl === null) {
128                                 throw new HException("Enum not found " . $name);
129                         }
130                         $e = $this->unserializeEnum($edecl, $this->unserialize());
131                         $this->cache->push($e);
132                         return $e;
133                 }break;
134                 case 106:{
135                         $name = $this->unserialize();
136                         $edecl = $this->resolver->resolveEnum($name);
137                         if($edecl === null) {
138                                 throw new HException("Enum not found " . $name);
139                         }
140                         $this->pos++;
141                         $index = $this->readDigits();
142                         $tag = _hx_array_get(Type::getEnumConstructs($edecl), $index);
143                         if($tag === null) {
144                                 throw new HException("Unknown enum index " . $name . "@" . _hx_string_rec($index, ""));
145                         }
146                         $e = $this->unserializeEnum($edecl, $tag);
147                         $this->cache->push($e);
148                         return $e;
149                 }break;
150                 case 108:{
151                         $l = new HList();
152                         $this->cache->push($l);
153                         $buf = $this->buf;
154                         while(ord(substr($this->buf,$this->pos,1)) !== 104) {
155                                 $l->add($this->unserialize());
156                         }
157                         $this->pos++;
158                         return $l;
159                 }break;
160                 case 98:{
161                         $h = new Hash();
162                         $this->cache->push($h);
163                         $buf = $this->buf;
164                         while(ord(substr($this->buf,$this->pos,1)) !== 104) {
165                                 $s = $this->unserialize();
166                                 $h->set($s, $this->unserialize());
167                                 unset($s);
168                         }
169                         $this->pos++;
170                         return $h;
171                 }break;
172                 case 113:{
173                         $h = new IntHash();
174                         $this->cache->push($h);
175                         $buf = $this->buf;
176                         $c = ord(substr($this->buf,$this->pos++,1));
177                         while($c === 58) {
178                                 $i = $this->readDigits();
179                                 $h->set($i, $this->unserialize());
180                                 $c = ord(substr($this->buf,$this->pos++,1));
181                                 unset($i);
182                         }
183                         if($c !== 104) {
184                                 throw new HException("Invalid IntHash format");
185                         }
186                         return $h;
187                 }break;
188                 case 118:{
189                         $d = Date::fromString(_hx_substr($this->buf, $this->pos, 19));
190                         $this->cache->push($d);
191                         $this->pos += 19;
192                         return $d;
193                 }break;
194                 case 115:{
195                         $len = $this->readDigits();
196                         $buf = $this->buf;
197                         if(ord(substr($this->buf,$this->pos++,1)) !== 58 || $this->length - $this->pos < $len) {
198                                 throw new HException("Invalid bytes length");
199                         }
200                         $codes = haxe_Unserializer::$CODES;
201                         if($codes === null) {
202                                 $codes = haxe_Unserializer::initCodes();
203                                 haxe_Unserializer::$CODES = $codes;
204                         }
205                         $i = $this->pos;
206                         $rest = $len & 3;
207                         $size = ($len >> 2) * 3 + (haxe_Unserializer_0($this, $buf, $codes, $i, $len, $rest));
208                         $max = $i + ($len - $rest);
209                         $bytes = haxe_io_Bytes::alloc($size);
210                         $bpos = 0;
211                         while($i < $max) {
212                                 $c1 = $codes[ord(substr($buf,$i++,1))];
213                                 $c2 = $codes[ord(substr($buf,$i++,1))];
214                                 $bytes->b[$bpos++] = chr($c1 << 2 | $c2 >> 4);
215                                 $c3 = $codes[ord(substr($buf,$i++,1))];
216                                 $bytes->b[$bpos++] = chr($c2 << 4 | $c3 >> 2);
217                                 $c4 = $codes[ord(substr($buf,$i++,1))];
218                                 $bytes->b[$bpos++] = chr($c3 << 6 | $c4);
219                                 unset($c4,$c3,$c2,$c1);
220                         }
221                         if($rest >= 2) {
222                                 $c1 = $codes[ord(substr($buf,$i++,1))];
223                                 $c2 = $codes[ord(substr($buf,$i++,1))];
224                                 $bytes->b[$bpos++] = chr($c1 << 2 | $c2 >> 4);
225                                 if($rest === 3) {
226                                         $c3 = $codes[ord(substr($buf,$i++,1))];
227                                         $bytes->b[$bpos++] = chr($c2 << 4 | $c3 >> 2);
228                                 }
229                         }
230                         $this->pos += $len;
231                         $this->cache->push($bytes);
232                         return $bytes;
233                 }break;
234                 case 67:{
235                         $name = $this->unserialize();
236                         $cl = $this->resolver->resolveClass($name);
237                         if($cl === null) {
238                                 throw new HException("Class not found " . $name);
239                         }
240                         $o = Type::createEmptyInstance($cl);
241                         $this->cache->push($o);
242                         $o->hxUnserialize($this);
243                         if(ord(substr($this->buf,$this->pos++,1)) !== 103) {
244                                 throw new HException("Invalid custom data");
245                         }
246                         return $o;
247                 }break;
248                 default:{
249                 }break;
250                 }
251                 $this->pos--;
252                 throw new HException("Invalid char " . _hx_char_at($this->buf, $this->pos) . " at position " . _hx_string_rec($this->pos, ""));
253         }
254         public function unserializeEnum($edecl, $tag) {
255                 if(ord(substr($this->buf,$this->pos++,1)) !== 58) {
256                         throw new HException("Invalid enum format");
257                 }
258                 $nargs = $this->readDigits();
259                 if($nargs === 0) {
260                         return Type::createEnum($edecl, $tag, null);
261                 }
262                 $args = new _hx_array(array());
263                 while($nargs-- > 0) {
264                         $args->push($this->unserialize());
265                 }
266                 return Type::createEnum($edecl, $tag, $args);
267         }
268         public function unserializeObject($o) {
269                 while(true) {
270                         if($this->pos >= $this->length) {
271                                 throw new HException("Invalid object");
272                         }
273                         if(ord(substr($this->buf,$this->pos,1)) === 103) {
274                                 break;
275                         }
276                         $k = $this->unserialize();
277                         if(!Std::is($k, _hx_qtype("String"))) {
278                                 throw new HException("Invalid object key");
279                         }
280                         $v = $this->unserialize();
281                         $o->{$k} = $v;
282                         unset($v,$k);
283                 }
284                 $this->pos++;
285         }
286         public function readDigits() {
287                 $k = 0;
288                 $s = false;
289                 $fpos = $this->pos;
290                 while(true) {
291                         $c = ord(substr($this->buf,$this->pos,1));
292                         if(($c === 0)) {
293                                 break;
294                         }
295                         if($c === 45) {
296                                 if($this->pos !== $fpos) {
297                                         break;
298                                 }
299                                 $s = true;
300                                 $this->pos++;
301                                 continue;
302                         }
303                         if($c < 48 || $c > 57) {
304                                 break;
305                         }
306                         $k = $k * 10 + ($c - 48);
307                         $this->pos++;
308                         unset($c);
309                 }
310                 if($s) {
311                         $k *= -1;
312                 }
313                 return $k;
314         }
315         public function get($p) {
316                 return ord(substr($this->buf,$p,1));
317         }
318         public function getResolver() {
319                 return $this->resolver;
320         }
321         public function setResolver($r) {
322                 if($r === null) {
323                         $this->resolver = _hx_anonymous(array("resolveClass" => array(new _hx_lambda(array(&$r), "haxe_Unserializer_1"), 'execute'), "resolveEnum" => array(new _hx_lambda(array(&$r), "haxe_Unserializer_2"), 'execute')));
324                 } else {
325                         $this->resolver = $r;
326                 }
327         }
328         public $resolver;
329         public $scache;
330         public $cache;
331         public $length;
332         public $pos;
333         public $buf;
334         public function __call($m, $a) {
335                 if(isset($this->$m) && is_callable($this->$m))
336                         return call_user_func_array($this->$m, $a);
337                 else if(isset($this->»dynamics[$m]) && is_callable($this->»dynamics[$m]))
338                         return call_user_func_array($this->»dynamics[$m], $a);
339                 else if('toString' == $m)
340                         return $this->__toString();
341                 else
342                         throw new HException('Unable to call «'.$m.'»');
343         }
344         static $DEFAULT_RESOLVER;
345         static $BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%:";
346         static $CODES = null;
347         static function initCodes() {
348                 $codes = new _hx_array(array());
349                 {
350                         $_g1 = 0; $_g = strlen(haxe_Unserializer::$BASE64);
351                         while($_g1 < $_g) {
352                                 $i = $_g1++;
353                                 $codes[ord(substr(haxe_Unserializer::$BASE64,$i,1))] = $i;
354                                 unset($i);
355                         }
356                 }
357                 return $codes;
358         }
359         static function run($v) {
360                 return _hx_deref(new haxe_Unserializer($v))->unserialize();
361         }
362         function __toString() { return 'haxe.Unserializer'; }
363 }
364 haxe_Unserializer::$DEFAULT_RESOLVER = _hx_qtype("Type");
365 function haxe_Unserializer_0(&$»this, &$buf, &$codes, &$i, &$len, &$rest) {
366         if($rest >= 2) {
367                 return $rest - 1;
368         } else {
369                 return 0;
370         }
371 }
372 function haxe_Unserializer_1(&$r, $_) {
373         {
374                 return null;
375         }
376 }
377 function haxe_Unserializer_2(&$r, $_) {
378         {
379                 return null;
380         }
381 }