isStringLiteral

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

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

Bugs

doesn't check for validity of token strings.

Examples

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`));

Meta