unquoted

Removes paired preceding and trailing double quotes, unquoting a word. Assumes ASCII.

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

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

Parameters

line string

The (potentially) quoted string.

Return Value

Type: auto

A slice of the line argument that excludes the quotes.

Examples

string quoted = `"This is a quote"`;
string unquotedLine = quoted.unquoted;
assert((unquotedLine == "This is a quote"), unquotedLine);
assert(`"Lorem ipsum sit amet"`.unquoted == "Lorem ipsum sit amet");
assert(`"""""Lorem ipsum sit amet"""""`.unquoted == "Lorem ipsum sit amet");
// Unbalanced quotes are left untouched
assert(`"Lorem ipsum sit amet`.unquoted == `"Lorem ipsum sit amet`);
assert(`"Lorem \"`.unquoted == `"Lorem \"`);
assert("\"Lorem \\\"".unquoted == "\"Lorem \\\"");
assert(`"\"`.unquoted == `"\"`);