private static function decode_dictionary(&$data)
{
$dictionary = array();
$previous = null;
while (($char = self::char($data)) != 'e') {
if ($char === false) {
return self::set_error(new Exception('Unterminated dictionary'));
}
if (!ctype_digit($char)) {
return self::set_error(new Exception('Invalid dictionary key'));
}
$key = self::decode_string($data);
if (isset($dictionary[$key])) {
return self::set_error(new Exception('Duplicate dictionary key'));
}
if ($key < $previous) {
self::set_error(new Exception('Missorted dictionary key'));
}
$dictionary[$key] = self::decode_data($data);
$previous = $key;
}
$data = substr($data, 1);
return $dictionary;
}