strippedRight

Returns a slice of the passed string with any trailing whitespace and/or linebreaks sliced off. Overload that implicitly strips " \n\r\t".

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

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

Parameters

line string

Line to strip the right side of.

Return Value

Type: auto

The passed line without any trailing whitespace or linebreaks.

Examples

static if (!is(typeof("blah".strippedRight) == string))
{
    enum message = "`lu.string.strippedRight` should return a mutable string";
    static assert(0, message);
}

{
    immutable trailing = "abc  ";
    immutable stripped = trailing.strippedRight;
    assert((stripped == "abc"), stripped);
}
{
    immutable trailing = "  ";
    immutable stripped = trailing.strippedRight;
    assert((stripped == ""), stripped);
}
{
    immutable empty = "";
    immutable stripped = empty.strippedRight;
    assert((stripped == ""), stripped);
}
{
    immutable noTrailing = "abc";
    immutable stripped = noTrailing.strippedRight;
    assert((stripped == "abc"), stripped);
}
{
    immutable linebreak = "abc\r\n  \r\n";
    immutable stripped = linebreak.strippedRight;
    assert((stripped == "abc"), stripped);
}

Meta