decodeIRCv3String

Decodes an IRCv3 tag string, replacing some characters.

IRCv3 tags need to be free of spaces, so by necessity they're encoded into \s. Likewise; since tags are separated by semicolons, semicolons in tag string are encoded into \:, and literal backslashes \\.

pure @safe nothrow
decodeIRCv3String
(
const string line
)

Parameters

line string

Original line to decode.

Return Value

Type: auto

A decoded string without \s in it.

Examples

string encoded = `This\sline\sis\sencoded\:\swith\s\\s`;
string decoded = decodeIRCv3String(encoded);
assert(decoded == r"This line is encoded; with \s");
immutable s1 = decodeIRCv3String(`kameloso\sjust\ssubscribed\swith\sa\s` ~
    `$4.99\ssub.\skameloso\ssubscribed\sfor\s40\smonths\sin\sa\srow!`);
assert((s1 == "kameloso just subscribed with a $4.99 sub. " ~
    "kameloso subscribed for 40 months in a row!"), s1);

immutable s2 = decodeIRCv3String(`stop\sspamming\scaps,\sautomated\sby\sNightbot`);
assert((s2 == "stop spamming caps, automated by Nightbot"), s2);

immutable s3 = decodeIRCv3String(`\:__\:`);
assert((s3 == ";__;"), s3);

immutable s4 = decodeIRCv3String(`\\o/ \\o\\ /o/ ~o~`);
assert((s4 == `\o/ \o\ /o/ ~o~`), s4);

immutable s5 = decodeIRCv3String(`This\sis\sa\stest\`);
assert((s5 == "This is a test"), s5);

immutable s6 = decodeIRCv3String(`9\sraiders\sfrom\sVHSGlitch\shave\sjoined\n!`);
assert((s6 == "9 raiders from VHSGlitch have joined\n!"), s6);

{
    enum before = `\s\s\s`;
    immutable after = decodeIRCv3String(before);
    assert((after == "   "), after);
    assert(before !is after);
}
{
    enum before = `foo bar`;
    immutable after = decodeIRCv3String(before);
    assert((after == "foo bar"), after);
    assert(before is after);
}
{
    enum before = `This\sline\sis\sencoded\:\swith\s\\s`;
    immutable after = decodeIRCv3String(before);
    assert((after == r"This line is encoded; with \s"), after);
}