MCPcopy Create free account
hub / github.com/CloudCompare/CloudCompare / Parse

Method Parse

qCC/ccCommandLineParser.cpp:83–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83int ccCommandLineParser::Parse(const QStringList& arguments, ccPluginInterfaceList& plugins)
84{
85 if (arguments.size() < 2)
86 {
87 assert(false);
88 return EXIT_SUCCESS;
89 }
90
91 //load arguments
92 QScopedPointer<ccCommandLineParser> parser(new ccCommandLineParser);
93
94 parser->registerBuiltInCommands();
95
96 ccConsole::SetRefreshCycle(200);
97
98 // 'massage' the arguments to properly handle single quotes
99 {
100 bool insideSingleQuoteSection = false;
101 QString buffer;
102 static const QChar SingleQuote{ '\'' };
103 for (int currentArgIndex = 1; currentArgIndex < arguments.size(); ++currentArgIndex) // start from 1, as the first argument is always the executable file
104 {
105 QString arg = arguments[currentArgIndex];
106 // argument starts with a single quote
107 if (!insideSingleQuoteSection && arg.startsWith(SingleQuote))
108 {
109 if (arg.endsWith(SingleQuote))
110 {
111 // nothing to do, non-truncated argument
112 }
113 else
114 {
115 // we'll collect the next pieces to get the full argument
116 insideSingleQuoteSection = true;
117 buffer = arg.mid(1); // remove the single quote
118 }
119 }
120 else if (insideSingleQuoteSection)
121 {
122 buffer += QChar(' ') + arg; // append the current argument to the previous one(s)
123 if (arg.endsWith(SingleQuote))
124 {
125 insideSingleQuoteSection = false;
126 arg = buffer.left(buffer.length() - 1); // remove the single quote
127 }
128 }
129
130 if (!insideSingleQuoteSection)
131 {
132 parser->arguments().append(arg);
133 }
134 }
135
136 if (insideSingleQuoteSection)
137 {
138 // the single quote section was not closed...
139 parser->warning("Probably malformed command (missing closing simple quote)");
140 // ...still, we'll try to proceed

Callers

nothing calls this directly

Calls 14

InitFunction · 0.85
lengthMethod · 0.80
warningMethod · 0.80
toggleSilentModeMethod · 0.80
silentModeMethod · 0.80
showMethod · 0.80
cleanupMethod · 0.80
sizeMethod · 0.45
appendMethod · 0.45
resetMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected