A bencode parser copy/pasted from squint itself into the squint playground
It returns the parsed bit but also the unprocessed remainder of the string
https://squint-cljs.github.io/squint/?src=KG5zIHNxdWludC5yZXBsLm5yZXBsLmJlbmNvZGUKICAiQmVuY29kZSBzdXBwb3J0LCB0YWtlbiBmcm9tIGh0dHBzOi8vZ2l0aHViLmNvbS9kamJsdWUvbnJlcGwtY2xqcy9ibG9iL21hc3Rlci9zcmMvbnJlcGwvYmVuY29kZS5jbGpzIikKCihkZWZuLSBpbmRleC1vZiBbcyBjXQogIChsZXQgW2kgKC5pbmRleE9mIHMgYyldCiAgICAoaWYgKDwgaSAwKSAodGhyb3cgKGpzL0Vycm9yLiAib3V0IG9mIGlucHV0IikpIGkpKSkKCihkZWZuLSBzbGljZQogIChbYnVmZmVyIHN0YXJ0XQogICAoaWYgKDwgKC4tbGVuZ3RoIGJ1ZmZlcikgc3RhcnQpCiAgICAgKHRocm93IChqcy9FcnJvci4gIm91dCBvZiBpbnB1dCIpKQogICAgICguc2xpY2UgYnVmZmVyIHN0YXJ0KSkpCiAgKFtidWZmZXIgc3RhcnQgZW5kXQogICAoaWYgKD4gZW5kICguLWxlbmd0aCBidWZmZXIpKQogICAgICh0aHJvdyAoanMvRXJyb3IuICJvdXQgb2YgaW5wdXQiKSkKICAgICAoLnNsaWNlIGJ1ZmZlciBzdGFydCBlbmQpKSkpCgooZGVmbi0gZGVjb2RlLXJlY3VyIFtkYXRhIG9wdHNdCiAgKGNhc2UgKHN0ciAoc2xpY2UgZGF0YSAwIDEpKQogICAgImkiCiAgICAobGV0IFtkYXRhIChzbGljZSBkYXRhIDEpCiAgICAgICAgICBpIChpbmRleC1vZiBkYXRhICJlIildCiAgICAgIFsoanMvcGFyc2VJbnQgKHNsaWNlIGRhdGEgMCBpKSkKICAgICAgIChzbGljZSBkYXRhIChpbmMgaSkpXSkKICAgICJsIgogICAgKGxldCBbZGF0YSAoc2xpY2UgZGF0YSAxKV0KICAgICAgKGxvb3AgW2RhdGEgZGF0YSB2ICh0cmFuc2llbnQgW10pXQogICAgICAgIChpZiAoPSAoc3RyIChzbGljZSBkYXRhIDAgMSkpICJlIikKICAgICAgICAgIFsocGVyc2lzdGVudCEgdikgKHNsaWNlIGRhdGEgMSldCiAgICAgICAgICAobGV0IFtbdmFsdWUgZGF0YV0gKGRlY29kZS1yZWN1ciBkYXRhIG9wdHMpXQogICAgICAgICAgICAocmVjdXIgZGF0YSAoY29uaiEgdiB2YWx1ZSkpKSkpKQogICAgImQiCiAgICAobGV0IFtkYXRhIChzbGljZSBkYXRhIDEpCiAgICAgICAgICB7OmtleXMgW2tleXdvcmRpemUta2V5c119IG9wdHNdCiAgICAgIChsb29wIFtkYXRhIGRhdGEgbSAodHJhbnNpZW50IHt9KV0KICAgICAgICAoaWYgKD0gKHN0ciAoc2xpY2UgZGF0YSAwIDEpKSAiZSIpCiAgICAgICAgICBbKHBlcnNpc3RlbnQhIG0pIChzbGljZSBkYXRhIDEpXQogICAgICAgICAgKGxldCBbW2sgZGF0YV0gKGRlY29kZS1yZWN1ciBkYXRhIG9wdHMpCiAgICAgICAgICAgICAgICBbdiBkYXRhXSAoZGVjb2RlLXJlY3VyIGRhdGEgb3B0cykKICAgICAgICAgICAgICAgIGsgKGlmIGtleXdvcmRpemUta2V5cyAoa2V5d29yZCBrKSBrKV0KICAgICAgICAgICAgKHJlY3VyIGRhdGEgKGFzc29jISBtIGsgdikpKSkpKQogICAgKGxldCBbaSAoaW5kZXgtb2YgZGF0YSAiOiIpCiAgICAgICAgICBuIChqcy9wYXJzZUludCAoc2xpY2UgZGF0YSAwIGkpKQogICAgICAgICAgZGF0YSAoc2xpY2UgZGF0YSAoaW5jIGkpKV0KICAgICAgWyhzdHIgKHNsaWNlIGRhdGEgMCBuKSkgKHNsaWNlIGRhdGEgbildKSkpCgooZGVmbiBkZWNvZGUgW2RhdGEgJiBvcHRzXQogICh0cnkKICAgIChkZWNvZGUtcmVjdXIgZGF0YSBvcHRzKQogICAgKGNhdGNoIGpzL0Vycm9y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ICAgICAgIChzdHIgKGVuY29kZSBrKSAoZW5jb2RlIHYpKSkpCiAgICAgICAgICAgICAgICAgIChhcHBseSBzdHIpKQogICAgICAgICAiZSIpKSkKCihkZWZuIHdyaXRlLWJlbmNvZGUgW2RhdGFdCiAgKGVuY29kZSBkYXRhKSkKCihkZWNvZGUgImQyOm9wODpkZXNjcmliZWUxMjMiKQ%3D%3D&repl=true
#clojure #squintcljs