public function Parse(&$BEncodedString, &$Offset) { if ($BEncodedString[$Offset] == 'l') { $Offset += 1; $Value = null; while ((substr($BEncodedString, $Offset, 1) === 'e') === false) { $TmpOffset = $Offset; switch (true) { case $BEncodedString[$Offset] === 'd': try { $Value = new BEncodedDictionary(); $Value->Parse($BEncodedString, $TmpOffset); } catch (BEncodingParserException $e) { throw new BEncodingParserException(__CLASS__ . ' expected BEncodedDictionary at offset ' . $Offset, $BEncodedString, $Offset, $e); } $Offset = $TmpOffset; break; case $BEncodedString[$Offset] === 'l': try { $Value = new BEncodedList(); $Value->Parse($BEncodedString, $TmpOffset); } catch (BEncodingParserException $e) { throw new BEncodingParserException(__CLASS__ . ' expected BEncodedList at offset ' . $Offset, $BEncodedString, $Offset, $e); } $Offset = $TmpOffset; break; case $BEncodedString[$Offset] === 'i': try { $Value = new BEncodedInteger(); $Value->Parse($BEncodedString, $TmpOffset); } catch (BEncodingParserException $e) { throw new BEncodingParserException(__CLASS__ . ' expected BEncodedInteger at offset ' . $Offset, $BEncodedString, $Offset, $e); } $Offset = $TmpOffset; break; case is_numeric($BEncodedString[$Offset]): try { $Value = new BEncodedString(); $Value->Parse($BEncodedString, $TmpOffset); } catch (BEncodingParserException $e) { throw new BEncodingParserException(__CLASS__ . ' expected BEncodedString at offset ' . $Offset, $BEncodedString, $Offset, $e); } $Offset = $TmpOffset; break; default: throw new Exception(__CLASS__ . ' encountered unexpected token: "' . $BEncodedString[$Offset]); } $this[] = $Value; } } else { throw new BEncodingParserException(__CLASS__ . ' encountered unrecognised encoding', $BEncodedString, $Offset); } $Offset += 1; }