MCPcopy Create free account
hub / github.com/ZDoom/Raze / BuildString

Function BuildString

source/common/console/c_dispatch.cpp:516–559  ·  view source on GitHub ↗

Given an argument vector, reconstitute the command line it could have been produced from.

Source from the content-addressed store, hash-verified

514
515// Given an argument vector, reconstitute the command line it could have been produced from.
516FString BuildString (int argc, FString *argv)
517{
518 if (argc == 1)
519 {
520 return *argv;
521 }
522 else
523 {
524 FString buf;
525 int arg;
526
527 for (arg = 0; arg < argc; arg++)
528 {
529 if (argv[arg][0] == '\0')
530 { // It's an empty argument, we need to convert it to '""'
531 buf << "\"\" ";
532 }
533 else if (strchr(argv[arg].GetChars(), '"'))
534 { // If it contains one or more quotes, we need to escape them.
535 buf << '"';
536 ptrdiff_t substr_start = 0, quotepos;
537 while ((quotepos = argv[arg].IndexOf('"', substr_start)) >= 0)
538 {
539 if (substr_start < quotepos)
540 {
541 buf << argv[arg].Mid(substr_start, quotepos - substr_start);
542 }
543 buf << "\\\"";
544 substr_start = quotepos + 1;
545 }
546 buf << argv[arg].Mid(substr_start) << "\" ";
547 }
548 else if (strchr(argv[arg].GetChars(), ' '))
549 { // If it contains a space, it needs to be quoted.
550 buf << '"' << argv[arg] << "\" ";
551 }
552 else
553 {
554 buf << argv[arg] << ' ';
555 }
556 }
557 return buf;
558 }
559}
560
561//===========================================================================
562//

Callers 1

C_ParseCmdLineParamsFunction · 0.85

Calls 3

MidMethod · 0.80
GetCharsMethod · 0.45
IndexOfMethod · 0.45

Tested by

no test coverage detected