I wrote this mainly because someone asked how to do this in PHP. Turns out there is nothing in like the venerable URI module in all of PHP-dom (how pathetic is that for a language as web-centric as it?).
First, I tried writing this with mostly string functions, but that was too painful, so I switched to doing it using regexes, even though they’re piss-poorly supported. After a while, my eyes glazed over, so I resorted to writing and debugging the code in Perl first, and then compiling it down to
machine code .
I thought I’d post this byproduct here for posterity, in case someone needs it in some circumstance.
Tests included, but I’m pretty sure they’re not extensive enough to be 100% confident in the code. Proceed at your discretion.