MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / parseCommandString

Function parseCommandString

radiantcore/commandsystem/CommandSystem.cpp:284–333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

282using StatementVec = std::vector<local::Statement>;
283
284StatementVec parseCommandString(const std::string& input)
285{
286 StatementVec statements;
287
288 // Instantiate a CommandTokeniser to analyse the given input string
289 CommandTokeniser tokeniser(input);
290
291 if (!tokeniser.hasMoreTokens()) return statements;
292
293 local::Statement curStatement;
294 while (tokeniser.hasMoreTokens())
295 {
296 // Inspect the next token
297 std::string token = tokeniser.nextToken();
298
299 if (token.empty()) {
300 continue; // skip empty tokens
301 }
302 else if (token == ";") {
303 // Finish the current statement
304 if (!curStatement.command.empty()) {
305 // Add the non-empty statement to our list
306 statements.push_back(curStatement);
307 }
308
309 // Clear the statement
310 curStatement = local::Statement();
311 continue;
312 }
313 // Token is not a semicolon
314 else if (curStatement.command.empty()) {
315 // The statement is still without command name, take this one
316 curStatement.command = token;
317 continue;
318 }
319 else {
320 // Non-empty token, command name is already known, so
321 // this must be an argument
322 curStatement.args.push_back(token);
323 }
324 }
325
326 // Check if we have an unfinished statement
327 if (!curStatement.command.empty()) {
328 // Add the non-empty statement to our list
329 statements.push_back(curStatement);
330 }
331
332 return statements;
333}
334
335bool CommandSystem::canExecute(const std::string& input) const
336{

Callers 1

executeMethod · 0.85

Calls 5

StatementClass · 0.70
hasMoreTokensMethod · 0.45
nextTokenMethod · 0.45
emptyMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected