481482483484485486487488489490491492493494495496497498499
}
/** Decode torrent string
* @param string data to decode
* @return string decoded string
*/
static private function decode_string ( & $data ) {
if ( self::char( $data ) === '0' && substr( $data, 1, 1 ) != ':' )
self::set_error( new Exception( 'Invalid string length, leading zero' ) );
if ( ! $colon = @strpos( $data, ':' ) )
return self::set_error( new Exception( 'Invalid string length, colon not found' ) );
$length = intval( substr( $data, 0, $colon ) );
if ( $length + $colon + 1 > strlen( $data ) )
return self::set_error( new Exception( 'Invalid string, input too short for string length' ) );
$string = substr( $data, $colon + 1, $length );
$data = substr( $data, $colon + $length + 1 );
return $string;
}
/** Decode torrent integer
* @param string data to decode