strippedRight

Returns a slice of the passed string with any trailing passed characters. Implementation template capable of handling both individual characters and string of tokens to strip.

Duplicates std.string.stripRight, which we can no longer trust not to assert on unexpected input.

  1. auto strippedRight(string line)
  2. auto strippedRight(Line line, Chaff chaff)
    @safe pure nothrow @nogc
    strippedRight
    (
    Line
    Chaff
    )
    (
    return scope Line line
    ,
    const scope Chaff chaff
    )

Parameters

line Line

Line to strip the right side of.

chaff Chaff

Character or string of characters to strip away.

Return Value

Type: auto

The passed line without any trailing passed characters.

Examples

{
    immutable trailing = "abc,";
    immutable stripped = trailing.strippedRight(',');
    assert((stripped == "abc"), stripped);
}
{
    immutable trailing = "abc!!!";
    immutable stripped = trailing.strippedRight('!');
    assert((stripped == "abc"), stripped);
}
{
    immutable trailing = "abc";
    immutable stripped = trailing.strippedRight(' ');
    assert((stripped == "abc"), stripped);
}
{
    immutable trailing = "";
    immutable stripped = trailing.strippedRight(' ');
    assert(!stripped.length, stripped);
}
{
    immutable trailing = "abc,!.-";
    immutable stripped = trailing.strippedRight("-.!,");
    assert((stripped == "abc"), stripped);
}
{
    immutable trailing = "abc!!!";
    immutable stripped = trailing.strippedRight("!");
    assert((stripped == "abc"), stripped);
}
{
    immutable trailing = "abc";
    immutable stripped = trailing.strippedRight(" ABC");
    assert((stripped == "abc"), stripped);
}
{
    immutable trailing = "";
    immutable stripped = trailing.strippedRight(" ");
    assert(!stripped.length, stripped);
}