]> git.sesse.net Git - cubemap/commitdiff
Support quoted spaces in configuration files.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 5 May 2021 17:03:24 +0000 (19:03 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 5 May 2021 17:04:18 +0000 (19:04 +0200)
parse.cpp

index 3f373c43cb72d1633bd2daea655cd1c73a152b91..9c7fd10b2f0c87a4f01e1e6112d683c07ccd3e18 100644 (file)
--- a/parse.cpp
+++ b/parse.cpp
@@ -13,8 +13,23 @@ vector<string> split_tokens(const string &line)
        vector<string> 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);
                        }