コード例 #1
0
ファイル: Bcode.php プロジェクト: KasaiDot/TorrentCaching
 /**
  * Info
  * @param type $s
  * @return type
  */
 static function bdec($s)
 {
     if (preg_match('/^(\\d+):/', $s, $m)) {
         $l = $m[1];
         $pl = strlen($l) + 1;
         $v = substr($s, $pl, $l);
         $ss = substr($s, 0, $pl + $l);
         if (strlen($v) != $l) {
             return;
         }
         return array("type" => "string", "value" => $v, "strlen" => strlen($ss), "string" => $ss);
     }
     if (preg_match('/^i(-{0,1}\\d+)e/', $s, $m)) {
         $v = $m[1];
         $ss = "i" . $v . "e";
         if ($v === "-0") {
             return;
         }
         if ($v[0] == "0" && strlen($v) != 1) {
             return;
         }
         return array("type" => "integer", "value" => $v, "strlen" => strlen($ss), "string" => $ss);
     }
     switch ($s[0]) {
         case "l":
             return Bcode::bdec_list($s);
         case "d":
             return Bcode::bdec_dict($s);
         default:
             return;
     }
 }