Function isStringLiteral

Checks if a string literal input has correct start/end sequences (quotes) to be any kind of D string literal.

bool isStringLiteral (
  const(char)[] literal,
  out char stringCloseChar,
  out bool hasPostfix,
  out bool parseEscapes,
  out int prefixLength
);

bool isStringLiteral (
  const(char)[] literal
);

Bugs

doesn't check for validity of token strings.

Standards

https://dlang.org/spec/lex.html#string_literals

Example

assert(isStringLiteral(`"hello"`));
assert(isStringLiteral(`"hello world!"`));
assert(isStringLiteral(`r"hello world!"c`));
assert(isStringLiteral(`r"hello world!"d`));
assert(isStringLiteral(`q{cool}`));
assert(isStringLiteral(`q{cool\}`));
assert(isStringLiteral(`"\\"`));
assert(!isStringLiteral(`"\\\"`));
assert(isStringLiteral(`"\\\\"`));
assert(isStringLiteral(`"a\\\\"`));
assert(isStringLiteral(`""`));
assert(isStringLiteral(`q""`));
assert(isStringLiteral(`x""`));
assert(!isStringLiteral(``));
assert(!isStringLiteral(`"`));
assert(!isStringLiteral(`w""`));
assert(!isStringLiteral(`hello"`));
assert(!isStringLiteral(`"hello`));
assert(!isStringLiteral(`"hello world`));
assert(!isStringLiteral(`hello world`));
assert(!isStringLiteral(`r"`));
assert(!isStringLiteral(`rr"ok"`));
assert(!isStringLiteral(`x"`));
assert(!isStringLiteral(`x" `));
assert(!isStringLiteral(`qqqq`));