Torrent::decode_string PHP Method

decode_string() private static method

Decode torrent string
private static decode_string ( &$data ) : string
return string decoded string
    private static 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;
    }