diff options
| author | Alexander Gavrilov | 2012-09-24 19:13:33 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-09-24 19:13:33 +0400 |
| commit | 627f0368306273e21abe35d938d8fd7d43583553 (patch) | |
| tree | 987420539d2713a61e5ddeaf27130c5e5fa75139 /library | |
| parent | 8e2515881128557739c7657c08c2597b131850ef (diff) | |
| download | dfhack-627f0368306273e21abe35d938d8fd7d43583553.tar.gz dfhack-627f0368306273e21abe35d938d8fd7d43583553.tar.bz2 dfhack-627f0368306273e21abe35d938d8fd7d43583553.tar.xz | |
Implement a special command parsing mode with one verbatim argument.
Intended for script expressions, e.g. rb_eval.
Diffstat (limited to 'library')
| -rw-r--r-- | library/Core.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/library/Core.cpp b/library/Core.cpp index 735359a7..8a8d39e0 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -126,8 +126,34 @@ struct Core::Private void Core::cheap_tokenise(string const& input, vector<string> &output) { string *cur = NULL; + size_t i = 0; - for (size_t i = 0; i < input.size(); i++) { + // Check the first non-space character + while (i < input.size() && isspace(input[i])) i++; + + // Special verbatim argument mode? + if (i < input.size() && input[i] == ':') + { + // Read the command + std::string cmd; + i++; + while (i < input.size() && !isspace(input[i])) + cmd.push_back(input[i++]); + if (!cmd.empty()) + output.push_back(cmd); + + // Find the argument + while (i < input.size() && isspace(input[i])) i++; + + if (i < input.size()) + output.push_back(input.substr(i)); + + return; + } + + // Otherwise, parse in the regular quoted mode + for (; i < input.size(); i++) + { unsigned char c = input[i]; if (isspace(c)) { cur = NULL; |
