Exemplo n.º 1
0
 private function readJSONString($peek = false, $start = 0)
 {
     if (!\hacklib_cast_as_boolean($peek)) {
         $start = 0;
     }
     $this->expectChar("\"", $peek, $start);
     $count = \hacklib_cast_as_boolean($peek) ? 1 : 0;
     $sb = new StringBuffer();
     $reading = true;
     while (\hacklib_cast_as_boolean($reading)) {
         $c = $this->bufTrans->peek(1, $start + $count);
         switch ($c) {
             case "\"":
                 $reading = false;
                 break;
             case "\\":
                 $count++;
                 $c = $this->bufTrans->peek(1, $start + $count);
                 switch ($c) {
                     case "\\":
                         $count++;
                         $sb->append("\\");
                         break;
                     case "\"":
                         $count++;
                         $sb->append("\"");
                         break;
                     case "b":
                         $count++;
                         $sb->append(chr(0x8));
                         break;
                     case "/":
                         $count++;
                         $sb->append("/");
                         break;
                     case "f":
                         $count++;
                         $sb->append("\f");
                         break;
                     case "n":
                         $count++;
                         $sb->append("\n");
                         break;
                     case "r":
                         $count++;
                         $sb->append("\r");
                         break;
                     case "t":
                         $count++;
                         $sb->append("\t");
                         break;
                     case "u":
                         $count++;
                         $this->expectChar("0", true, $start + $count);
                         $this->expectChar("0", true, $start + $count + 1);
                         $count += 2;
                         $sb->append(hex2bin($this->bufTrans->peek(2, $start + $count)));
                         $count += 2;
                         break;
                     default:
                         throw new TProtocolException("TSimpleJSONProtocol: Expected Control Character, found 0x" . bin2hex($c));
                 }
                 break;
             default:
                 $count++;
                 $sb->append($c);
                 break;
         }
     }
     if (!\hacklib_cast_as_boolean($peek)) {
         $this->trans_->readAll($count);
     }
     $this->expectChar("\"", $peek, $start + $count);
     return \HH\Pair::hacklib_new($sb->detach(), $count + 1);
 }