deduplicateBadges

Deduplicates a badge in a comma-separated list of badges.

Note: This only removes one duplicate badge, if present. It can trivially be made recursive.

version(TwitchSupport)
private pure @safe nothrow
void
deduplicateBadges
(
ref string badges
,
const string badge
)

Parameters

badges string

A reference to the comma-separated string of badges to deduplicate in place.

badge string

The badge to deduplicate.

Examples

{
    string badges = "subscriber/14,subscriber/12,bits/30000";
    deduplicateBadges(badges, "subscriber/");
    assert((badges == "subscriber/14,bits/30000"), badges);
}
{
    string badges = "subscriber/1,subscriber/0";
    deduplicateBadges(badges, "subscriber/");
    assert((badges == "subscriber/1"), badges);
}
{
    string badges = "vip/1,subscriber/19,subscriber/17,partner/1";
    deduplicateBadges(badges, "subscriber/");
    assert((badges == "vip/1,subscriber/19,partner/1"), badges);
}
{
    string badges = "subscriber/28,broadcaster/1,subscriber/12,partner/1";
    deduplicateBadges(badges, "subscriber/");
    assert((badges == "subscriber/28,broadcaster/1,partner/1"), badges);
}
{
    string badges;
    deduplicateBadges(badges, string.init);
    assert(!badges.length, badges);
}