From fd565f441589cf76ffda99db51fd383c33ab6f62 Mon Sep 17 00:00:00 2001 From: Mayeul Cantan Date: Fri, 22 Jan 2021 12:45:27 +0100 Subject: [PATCH] parser: support single quotation marks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/emersion/kanshi/pull/96 Includes a simplification suggested by: Co-authored-by: Érico Nogueira Rolim <34201958+ericonr@users.noreply.github.com> --- parser.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/parser.c b/parser.c index 0902a34..5b774d9 100644 --- a/parser.c +++ b/parser.c @@ -70,7 +70,7 @@ static bool parser_append_tok_ch(struct kanshi_parser *parser, char ch) { return true; } -static bool parser_read_quoted(struct kanshi_parser *parser) { +static bool parser_read_quoted(struct kanshi_parser *parser, char quote_char) { while (1) { int ch = parser_read_char(parser); if (ch < 0) { @@ -80,7 +80,7 @@ static bool parser_read_quoted(struct kanshi_parser *parser) { return false; } - if (ch == '"') { + if (ch == quote_char) { parser->tok_str[parser->tok_str_len] = '\0'; return true; } @@ -158,10 +158,10 @@ static bool parser_next_token(struct kanshi_parser *parser) { return true; } else if (isspace(ch)) { continue; - } else if (ch == '"') { + } else if (ch == '"' || ch == '\'') { parser->tok_type = KANSHI_TOKEN_STR; parser->tok_str_len = 0; - return parser_read_quoted(parser); + return parser_read_quoted(parser, ch); } else if (ch == '#') { parser_ignore_line(parser); parser->tok_type = KANSHI_TOKEN_NEWLINE;