stripped

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

It merely calls both strippedLeft and strippedRight. As such it duplicates std.string.strip, which we can no longer trust not to assert on unexpected input.

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

Parameters

line Line

Line to strip both the right and left side of.

chaff Chaff

Character or string of characters to strip away.

Return Value

Type: auto

The passed line, stripped of surrounding passed characters.

Examples

{
    immutable line = "   abc   ";
    immutable stripped_ = line.stripped(' ');
    assert((stripped_ == "abc"), stripped_);
}
{
    immutable line = "!!!";
    immutable stripped_ = line.stripped('!');
    assert((stripped_ == ""), stripped_);
}
{
    immutable line = "";
    immutable stripped_ = line.stripped('_');
    assert((stripped_ == ""), stripped_);
}
{
    immutable line = "abc";
    immutable stripped_ = line.stripped('\t');
    assert((stripped_ == "abc"), stripped_);
}
{
    immutable line = " \r\n  abc\r\n\r\n  ";
    immutable stripped_ = line.stripped(' ');
    assert((stripped_ == "\r\n  abc\r\n\r\n"), stripped_);
}
{
    immutable line = "   abc   ";
    immutable stripped_ = line.stripped(" \t");
    assert((stripped_ == "abc"), stripped_);
}
{
    immutable line = "!,!!";
    immutable stripped_ = line.stripped("!,");
    assert((stripped_ == ""), stripped_);
}
{
    immutable line = "";
    immutable stripped_ = line.stripped("_");
    assert((stripped_ == ""), stripped_);
}
{
    immutable line = "abc";
    immutable stripped_ = line.stripped("\t\r\n");
    assert((stripped_ == "abc"), stripped_);
}
{
    immutable line = " \r\n  abc\r\n\r\n  ";
    immutable stripped_ = line.stripped(" _");
    assert((stripped_ == "\r\n  abc\r\n\r\n"), stripped_);
}

Meta