MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ParseCommandString

Function ParseCommandString

src/strgen/strgen_base.cpp:329–369  ·  view source on GitHub ↗

returns cmd == nullptr on eof */

Source from the content-addressed store, hash-verified

327
328/* returns cmd == nullptr on eof */
329static ParsedCommandString ParseCommandString(StringConsumer &consumer)
330{
331 ParsedCommandString result;
332
333 /* Scan to the next command, exit if there's no next command. */
334 consumer.SkipUntilChar('{', StringConsumer::KEEP_SEPARATOR);
335 if (!consumer.ReadCharIf('{')) return {};
336
337 if (auto argno = consumer.TryReadIntegerBase<uint32_t>(10); argno.has_value()) {
338 result.argno = argno;
339 if (!consumer.ReadCharIf(':')) StrgenFatal("missing arg #");
340 }
341
342 /* parse command name */
343 auto command = consumer.ReadUntilCharIn("} =.");
344 result.cmd = FindCmd(command);
345 if (result.cmd == nullptr) {
346 StrgenError("Undefined command '{}'", command);
347 return {};
348 }
349
350 /* parse case */
351 if (consumer.ReadCharIf('.')) {
352 if (!result.cmd->flags.Test(CmdFlag::Case)) {
353 StrgenFatal("Command '{}' can't have a case", result.cmd->cmd);
354 }
355
356 auto casep = consumer.ReadUntilCharIn("} ");
357 result.casei = ResolveCaseName(casep);
358 }
359
360 /* parse params */
361 result.param = consumer.ReadUntilChar('}', StringConsumer::KEEP_SEPARATOR);
362
363 if (!consumer.ReadCharIf('}')) {
364 StrgenError("Missing }} from command '{}'", result.cmd->cmd);
365 return {};
366 }
367
368 return result;
369}
370
371/**
372 * Prepare reading.

Callers 3

VersionMethod · 0.85
ExtractCommandStringFunction · 0.85
PutCommandStringFunction · 0.85

Calls 7

FindCmdFunction · 0.85
ResolveCaseNameFunction · 0.85
SkipUntilCharMethod · 0.80
ReadCharIfMethod · 0.80
ReadUntilCharInMethod · 0.80
TestMethod · 0.80
ReadUntilCharMethod · 0.80

Tested by

no test coverage detected