From d34b94a858c08d64eddfb9c115719fd9129be933 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 5 May 2021 19:03:24 +0200 Subject: [PATCH 1/1] Support quoted spaces in configuration files. --- parse.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/parse.cpp b/parse.cpp index 3f373c4..9c7fd10 100644 --- a/parse.cpp +++ b/parse.cpp @@ -13,8 +13,23 @@ vector split_tokens(const string &line) vector ret; string current_token; + bool in_quote = false; + for (size_t i = 0; i < line.size(); ++i) { - if (isspace(line[i])) { + // Handle all escaped characters. + if (line[i] == '\\' && i < line.size() - 1) { + current_token.push_back(line[++i]); + continue; + } + + // Handle start and end quote. + if (line[i] == '"') { + in_quote = !in_quote; + continue; + } + + // Handle break. + if (isspace(line[i]) && !in_quote) { if (!current_token.empty()) { ret.push_back(current_token); } -- 2.39.2