unsinglequoted

Removes paired preceding and trailing single quotes around a line. Assumes ASCII.

Does not decode the string and may thus give weird results on weird inputs.

@safe pragma(inline, true) pure nothrow @nogc
unsinglequoted
(
return scope string line
)

Parameters

line string

The (potentially) single-quoted string.

Return Value

Type: auto

A slice of the line argument that excludes the single-quotes.

Examples

string quoted = `'This is single-quoted'`;
string unquotedLine = quoted.unsinglequoted;
assert((unquotedLine == "This is single-quoted"), unquotedLine);
assert(`'Lorem ipsum sit amet'`.unsinglequoted == "Lorem ipsum sit amet");
assert(`''''Lorem ipsum sit amet''''`.unsinglequoted == "Lorem ipsum sit amet");
// Unbalanced quotes are left untouched
assert(`'Lorem ipsum sit amet`.unsinglequoted == `'Lorem ipsum sit amet`);
assert(`'Lorem \'`.unsinglequoted == `'Lorem \'`);
assert("'Lorem \\'".unsinglequoted == "'Lorem \\'");
assert(`'`.unsinglequoted == `'`);

Meta