From 06e2fceedff563a656c4b5b5abfe5c99a214fa75 Mon Sep 17 00:00:00 2001 From: CK Tan Date: Sun, 11 Apr 2021 15:18:32 -0700 Subject: [PATCH] speed up parse --- toml.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/toml.c b/toml.c index e89bade..9eeb6e8 100644 --- a/toml.c +++ b/toml.c @@ -1680,9 +1680,9 @@ static int scan_string(context_t* ctx, char* p, int lineno, int dotisspecial) } if ('\"' == *p) { - char* tsq = strstr(p, "\'\'\'"); int hexreq = 0; /* #hex required */ int escape = 0; + int sqcnt = 0; /* count single-quote */ for (p++; *p; p++) { if (escape) { escape = 0; @@ -1699,15 +1699,15 @@ static int scan_string(context_t* ctx, char* p, int lineno, int dotisspecial) if (*p == '\\') { escape = 1; continue; } if (*p == '\n') break; if (*p == '"') break; + if (*p == '\'' && ++sqcnt == 3) { + return e_syntax(ctx, lineno, "triple-s-quote inside string lit"); + } + sqcnt = 0; } if (*p != '"') { return e_syntax(ctx, lineno, "unterminated quote"); } - if (tsq && tsq < p) { - return e_syntax(ctx, lineno, "triple-s-quote inside string lit"); - } - set_token(ctx, STRING, lineno, orig, p + 1 - orig); return 0; }