Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qcommandlineparser.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | - | |||||||||||||||||||
10 | extern void __attribute__((visibility("default"))) qt_call_post_routines(); | - | ||||||||||||||||||
11 | - | |||||||||||||||||||
12 | typedef QHash<QString, int> NameHash_t; | - | ||||||||||||||||||
13 | - | |||||||||||||||||||
14 | class QCommandLineParserPrivate | - | ||||||||||||||||||
15 | { | - | ||||||||||||||||||
16 | public: | - | ||||||||||||||||||
17 | inline QCommandLineParserPrivate() | - | ||||||||||||||||||
18 | : singleDashWordOptionMode(QCommandLineParser::ParseAsCompactedShortOptions), | - | ||||||||||||||||||
19 | optionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsOptions), | - | ||||||||||||||||||
20 | builtinVersionOption(false), | - | ||||||||||||||||||
21 | builtinHelpOption(false), | - | ||||||||||||||||||
22 | needsParsing(true) | - | ||||||||||||||||||
23 | { } executed 41 times by 1 test: end of block Executed by:
| 41 | ||||||||||||||||||
24 | - | |||||||||||||||||||
25 | bool parse(const QStringList &args); | - | ||||||||||||||||||
26 | void checkParsed(const char *method); | - | ||||||||||||||||||
27 | QStringList aliases(const QString &name) const; | - | ||||||||||||||||||
28 | QString helpText() const; | - | ||||||||||||||||||
29 | bool registerFoundOption(const QString &optionName); | - | ||||||||||||||||||
30 | bool parseOptionValue(const QString &optionName, const QString &argument, | - | ||||||||||||||||||
31 | QStringList::const_iterator *argumentIterator, | - | ||||||||||||||||||
32 | QStringList::const_iterator argsEnd); | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | - | |||||||||||||||||||
35 | QString errorText; | - | ||||||||||||||||||
36 | - | |||||||||||||||||||
37 | - | |||||||||||||||||||
38 | QList<QCommandLineOption> commandLineOptionList; | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | - | |||||||||||||||||||
41 | NameHash_t nameHash; | - | ||||||||||||||||||
42 | - | |||||||||||||||||||
43 | - | |||||||||||||||||||
44 | QHash<int, QStringList> optionValuesHash; | - | ||||||||||||||||||
45 | - | |||||||||||||||||||
46 | - | |||||||||||||||||||
47 | QStringList optionNames; | - | ||||||||||||||||||
48 | - | |||||||||||||||||||
49 | - | |||||||||||||||||||
50 | QStringList positionalArgumentList; | - | ||||||||||||||||||
51 | - | |||||||||||||||||||
52 | - | |||||||||||||||||||
53 | QStringList unknownOptionNames; | - | ||||||||||||||||||
54 | - | |||||||||||||||||||
55 | - | |||||||||||||||||||
56 | QString description; | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | - | |||||||||||||||||||
59 | struct PositionalArgumentDefinition | - | ||||||||||||||||||
60 | { | - | ||||||||||||||||||
61 | QString name; | - | ||||||||||||||||||
62 | QString description; | - | ||||||||||||||||||
63 | QString syntax; | - | ||||||||||||||||||
64 | }; | - | ||||||||||||||||||
65 | QVector<PositionalArgumentDefinition> positionalArgumentDefinitions; | - | ||||||||||||||||||
66 | - | |||||||||||||||||||
67 | - | |||||||||||||||||||
68 | QCommandLineParser::SingleDashWordOptionMode singleDashWordOptionMode; | - | ||||||||||||||||||
69 | - | |||||||||||||||||||
70 | - | |||||||||||||||||||
71 | QCommandLineParser::OptionsAfterPositionalArgumentsMode optionsAfterPositionalArgumentsMode; | - | ||||||||||||||||||
72 | - | |||||||||||||||||||
73 | - | |||||||||||||||||||
74 | bool builtinVersionOption; | - | ||||||||||||||||||
75 | - | |||||||||||||||||||
76 | - | |||||||||||||||||||
77 | bool builtinHelpOption; | - | ||||||||||||||||||
78 | - | |||||||||||||||||||
79 | - | |||||||||||||||||||
80 | bool needsParsing; | - | ||||||||||||||||||
81 | }; | - | ||||||||||||||||||
82 | template<> class QTypeInfo<QCommandLineParserPrivate::PositionalArgumentDefinition > { public: enum { isComplex = (((Q_MOVABLE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_MOVABLE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_MOVABLE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QCommandLineParserPrivate::PositionalArgumentDefinition)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QCommandLineParserPrivate::PositionalArgumentDefinition >::value, isDummy = (((Q_MOVABLE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QCommandLineParserPrivate::PositionalArgumentDefinition) }; static inline const char *name() { return "QCommandLineParserPrivate::PositionalArgumentDefinition"; } }; | - | ||||||||||||||||||
83 | - | |||||||||||||||||||
84 | QStringList QCommandLineParserPrivate::aliases(const QString &optionName) const | - | ||||||||||||||||||
85 | { | - | ||||||||||||||||||
86 | const NameHash_t::const_iterator it = nameHash.constFind(optionName); | - | ||||||||||||||||||
87 | if (it == nameHash.cend()
| 2-27 | ||||||||||||||||||
88 | QMessageLogger(__FILE__, 127, __PRETTY_FUNCTION__).warning("QCommandLineParser: option not defined: \"%s\"", QString(optionName).toLocal8Bit().constData()); | - | ||||||||||||||||||
89 | return executed 2 times by 1 test: QStringList();return QStringList(); Executed by:
executed 2 times by 1 test: return QStringList(); Executed by:
| 2 | ||||||||||||||||||
90 | } | - | ||||||||||||||||||
91 | return executed 27 times by 1 test: commandLineOptionList.at(*it).names();return commandLineOptionList.at(*it).names(); Executed by:
executed 27 times by 1 test: return commandLineOptionList.at(*it).names(); Executed by:
| 27 | ||||||||||||||||||
92 | } | - | ||||||||||||||||||
93 | QCommandLineParser::QCommandLineParser() | - | ||||||||||||||||||
94 | : d(new QCommandLineParserPrivate) | - | ||||||||||||||||||
95 | { | - | ||||||||||||||||||
96 | } executed 41 times by 1 test: end of block Executed by:
| 41 | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | - | |||||||||||||||||||
99 | - | |||||||||||||||||||
100 | - | |||||||||||||||||||
101 | QCommandLineParser::~QCommandLineParser() | - | ||||||||||||||||||
102 | { | - | ||||||||||||||||||
103 | delete d; | - | ||||||||||||||||||
104 | } executed 41 times by 1 test: end of block Executed by:
| 41 | ||||||||||||||||||
105 | void QCommandLineParser::setSingleDashWordOptionMode(QCommandLineParser::SingleDashWordOptionMode singleDashWordOptionMode) | - | ||||||||||||||||||
106 | { | - | ||||||||||||||||||
107 | d->singleDashWordOptionMode = singleDashWordOptionMode; | - | ||||||||||||||||||
108 | } executed 28 times by 1 test: end of block Executed by:
| 28 | ||||||||||||||||||
109 | void QCommandLineParser::setOptionsAfterPositionalArgumentsMode(QCommandLineParser::OptionsAfterPositionalArgumentsMode parsingMode) | - | ||||||||||||||||||
110 | { | - | ||||||||||||||||||
111 | d->optionsAfterPositionalArgumentsMode = parsingMode; | - | ||||||||||||||||||
112 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
113 | bool QCommandLineParser::addOption(const QCommandLineOption &option) | - | ||||||||||||||||||
114 | { | - | ||||||||||||||||||
115 | QStringList optionNames = option.names(); | - | ||||||||||||||||||
116 | - | |||||||||||||||||||
117 | if (!optionNames.isEmpty()
| 1-75 | ||||||||||||||||||
118 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(optionNames)>::type> _container_((optionNames)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QString &name = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
119 | if (d->nameHash.contains(name)
| 0-105 | ||||||||||||||||||
120 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||
121 | } executed 105 times by 1 test: end of block Executed by:
| 105 | ||||||||||||||||||
122 | - | |||||||||||||||||||
123 | d->commandLineOptionList.append(option); | - | ||||||||||||||||||
124 | - | |||||||||||||||||||
125 | const int offset = d->commandLineOptionList.size() - 1; | - | ||||||||||||||||||
126 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(optionNames)>::type> _container_((optionNames)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QString &name = *_container_.i; _container_.control; _container_.control = 0) | - | ||||||||||||||||||
127 | d->nameHash.insert(name, offset); executed 105 times by 1 test: d->nameHash.insert(name, offset); Executed by:
| 105 | ||||||||||||||||||
128 | - | |||||||||||||||||||
129 | return executed 75 times by 1 test: true;return true; Executed by:
executed 75 times by 1 test: return true; Executed by:
| 75 | ||||||||||||||||||
130 | } | - | ||||||||||||||||||
131 | - | |||||||||||||||||||
132 | return executed 1 time by 1 test: false;return false; Executed by:
executed 1 time by 1 test: return false; Executed by:
| 1 | ||||||||||||||||||
133 | } | - | ||||||||||||||||||
134 | bool QCommandLineParser::addOptions(const QList<QCommandLineOption> &options) | - | ||||||||||||||||||
135 | { | - | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | bool result = true; | - | ||||||||||||||||||
138 | for (QList<QCommandLineOption>::const_iterator it = options.begin(), end = options.end(); it != end
| 1-3 | ||||||||||||||||||
139 | result &= addOption(*it); executed 3 times by 1 test: result &= addOption(*it); Executed by:
| 3 | ||||||||||||||||||
140 | return executed 1 time by 1 test: result;return result; Executed by:
executed 1 time by 1 test: return result; Executed by:
| 1 | ||||||||||||||||||
141 | } | - | ||||||||||||||||||
142 | QCommandLineOption QCommandLineParser::addVersionOption() | - | ||||||||||||||||||
143 | { | - | ||||||||||||||||||
144 | QCommandLineOption opt(QStringList() << ([]() -> QString { enum { Size = sizeof(u"" "v")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "v" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return never executed: qstring_literal_temp;return qstring_literal_temp; never executed: }()) << ([]() -> QString { enum { Size = sizeof(u"" "version")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "version" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); returnreturn qstring_literal_temp; never executed: qstring_literal_temp;return qstring_literal_temp; never executed: }()), tr("Displays version information."));return qstring_literal_temp; | 0 | ||||||||||||||||||
145 | addOption(opt); | - | ||||||||||||||||||
146 | d->builtinVersionOption = true; | - | ||||||||||||||||||
147 | return never executed: opt;return opt; never executed: return opt; | 0 | ||||||||||||||||||
148 | } | - | ||||||||||||||||||
149 | QCommandLineOption QCommandLineParser::addHelpOption() | - | ||||||||||||||||||
150 | { | - | ||||||||||||||||||
151 | QCommandLineOption opt(QStringList() | - | ||||||||||||||||||
152 | - | |||||||||||||||||||
153 | - | |||||||||||||||||||
154 | - | |||||||||||||||||||
155 | << ([]() -> QString { enum { Size = sizeof(u"" "h")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "h" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return never executed: qstring_literal_temp;return qstring_literal_temp; never executed: }())return qstring_literal_temp; | 0 | ||||||||||||||||||
156 | << ([]() -> QString { enum { Size = sizeof(u"" "help")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "help" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return never executed: qstring_literal_temp;return qstring_literal_temp; never executed: }()), tr("Displays this help."));return qstring_literal_temp; | 0 | ||||||||||||||||||
157 | addOption(opt); | - | ||||||||||||||||||
158 | d->builtinHelpOption = true; | - | ||||||||||||||||||
159 | return never executed: opt;return opt; never executed: return opt; | 0 | ||||||||||||||||||
160 | } | - | ||||||||||||||||||
161 | - | |||||||||||||||||||
162 | - | |||||||||||||||||||
163 | - | |||||||||||||||||||
164 | - | |||||||||||||||||||
165 | void QCommandLineParser::setApplicationDescription(const QString &description) | - | ||||||||||||||||||
166 | { | - | ||||||||||||||||||
167 | d->description = description; | - | ||||||||||||||||||
168 | } never executed: end of block | 0 | ||||||||||||||||||
169 | - | |||||||||||||||||||
170 | - | |||||||||||||||||||
171 | - | |||||||||||||||||||
172 | - | |||||||||||||||||||
173 | QString QCommandLineParser::applicationDescription() const | - | ||||||||||||||||||
174 | { | - | ||||||||||||||||||
175 | return never executed: d->description;return d->description; never executed: return d->description; | 0 | ||||||||||||||||||
176 | } | - | ||||||||||||||||||
177 | void QCommandLineParser::addPositionalArgument(const QString &name, const QString &description, const QString &syntax) | - | ||||||||||||||||||
178 | { | - | ||||||||||||||||||
179 | QCommandLineParserPrivate::PositionalArgumentDefinition arg; | - | ||||||||||||||||||
180 | arg.name = name; | - | ||||||||||||||||||
181 | arg.description = description; | - | ||||||||||||||||||
182 | arg.syntax = syntax.isEmpty()
| 0 | ||||||||||||||||||
183 | d->positionalArgumentDefinitions.append(arg); | - | ||||||||||||||||||
184 | } never executed: end of block | 0 | ||||||||||||||||||
185 | void QCommandLineParser::clearPositionalArguments() | - | ||||||||||||||||||
186 | { | - | ||||||||||||||||||
187 | d->positionalArgumentDefinitions.clear(); | - | ||||||||||||||||||
188 | } never executed: end of block | 0 | ||||||||||||||||||
189 | bool QCommandLineParser::parse(const QStringList &arguments) | - | ||||||||||||||||||
190 | { | - | ||||||||||||||||||
191 | return executed 50 times by 1 test: d->parse(arguments);return d->parse(arguments); Executed by:
executed 50 times by 1 test: return d->parse(arguments); Executed by:
| 50 | ||||||||||||||||||
192 | } | - | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | - | |||||||||||||||||||
195 | - | |||||||||||||||||||
196 | - | |||||||||||||||||||
197 | - | |||||||||||||||||||
198 | QString QCommandLineParser::errorText() const | - | ||||||||||||||||||
199 | { | - | ||||||||||||||||||
200 | if (!d->errorText.isEmpty()
| 3 | ||||||||||||||||||
201 | return executed 3 times by 1 test: d->errorText;return d->errorText; Executed by:
executed 3 times by 1 test: return d->errorText; Executed by:
| 3 | ||||||||||||||||||
202 | if (d->unknownOptionNames.count() == 1
| 1-2 | ||||||||||||||||||
203 | return executed 2 times by 1 test: tr("Unknown option '%1'.").arg(d->unknownOptionNames.first());return tr("Unknown option '%1'.").arg(d->unknownOptionNames.first()); Executed by:
executed 2 times by 1 test: return tr("Unknown option '%1'.").arg(d->unknownOptionNames.first()); Executed by:
| 2 | ||||||||||||||||||
204 | if (d->unknownOptionNames.count() > 1
| 0-1 | ||||||||||||||||||
205 | return executed 1 time by 1 test: tr("Unknown options: %1.").arg(d->unknownOptionNames.join(([]() -> QString { enum { Size = sizeof(u"" ", ")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" ", " }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); returnreturn tr("Unknown options: %1.").arg(d->unknownOptionNames.join(([]() -> QString { enum { Size = sizeof(u"" ", ")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" ", " }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()))); Executed by:
executed 1 time by 1 test: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 1 time by 1 test: }())));return qstring_literal_temp; Executed by:
executed 1 time by 1 test: return tr("Unknown options: %1.").arg(d->unknownOptionNames.join(([]() -> QString { enum { Size = sizeof(u"" ", ")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" ", " }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()))); Executed by:
| 1 | ||||||||||||||||||
206 | return never executed: QString();return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
207 | } | - | ||||||||||||||||||
208 | - | |||||||||||||||||||
209 | enum MessageType { UsageMessage, ErrorMessage }; | - | ||||||||||||||||||
210 | static void showParserMessage(const QString &message, MessageType type) | - | ||||||||||||||||||
211 | { | - | ||||||||||||||||||
212 | fputs(QString(message).toLocal8Bit().constData(), type == UsageMessage ? stdout : stderr); | - | ||||||||||||||||||
213 | } never executed: end of block | 0 | ||||||||||||||||||
214 | void QCommandLineParser::process(const QStringList &arguments) | - | ||||||||||||||||||
215 | { | - | ||||||||||||||||||
216 | if (!d->parse(arguments)
| 0 | ||||||||||||||||||
217 | showParserMessage(errorText() + QLatin1Char('\n'), ErrorMessage); | - | ||||||||||||||||||
218 | qt_call_post_routines(); | - | ||||||||||||||||||
219 | :: never executed: exit(1);::exit(1); never executed: ::exit(1); | 0 | ||||||||||||||||||
220 | } | - | ||||||||||||||||||
221 | - | |||||||||||||||||||
222 | if (d->builtinVersionOption
| 0 | ||||||||||||||||||
223 | showVersion(); never executed: showVersion(); | 0 | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | if (d->builtinHelpOption
| 0 | ||||||||||||||||||
226 | showHelp(0); never executed: showHelp(0); | 0 | ||||||||||||||||||
227 | } never executed: end of block | 0 | ||||||||||||||||||
228 | - | |||||||||||||||||||
229 | - | |||||||||||||||||||
230 | - | |||||||||||||||||||
231 | - | |||||||||||||||||||
232 | - | |||||||||||||||||||
233 | - | |||||||||||||||||||
234 | void QCommandLineParser::process(const QCoreApplication &app) | - | ||||||||||||||||||
235 | { | - | ||||||||||||||||||
236 | - | |||||||||||||||||||
237 | (void)app;; | - | ||||||||||||||||||
238 | process(QCoreApplication::arguments()); | - | ||||||||||||||||||
239 | } never executed: end of block | 0 | ||||||||||||||||||
240 | - | |||||||||||||||||||
241 | void QCommandLineParserPrivate::checkParsed(const char *method) | - | ||||||||||||||||||
242 | { | - | ||||||||||||||||||
243 | if (needsParsing
| 2-260 | ||||||||||||||||||
244 | QMessageLogger(__FILE__, 611, __PRETTY_FUNCTION__).warning("QCommandLineParser: call process() or parse() before %s", method); executed 2 times by 1 test: QMessageLogger(__FILE__, 611, __PRETTY_FUNCTION__).warning("QCommandLineParser: call process() or parse() before %s", method); Executed by:
| 2 | ||||||||||||||||||
245 | } executed 262 times by 1 test: end of block Executed by:
| 262 | ||||||||||||||||||
246 | - | |||||||||||||||||||
247 | - | |||||||||||||||||||
248 | - | |||||||||||||||||||
249 | - | |||||||||||||||||||
250 | - | |||||||||||||||||||
251 | - | |||||||||||||||||||
252 | bool QCommandLineParserPrivate::registerFoundOption(const QString &optionName) | - | ||||||||||||||||||
253 | { | - | ||||||||||||||||||
254 | if (nameHash.contains(optionName)
| 5-47 | ||||||||||||||||||
255 | optionNames.append(optionName); | - | ||||||||||||||||||
256 | return executed 47 times by 1 test: true;return true; Executed by:
executed 47 times by 1 test: return true; Executed by:
| 47 | ||||||||||||||||||
257 | } else { | - | ||||||||||||||||||
258 | unknownOptionNames.append(optionName); | - | ||||||||||||||||||
259 | return executed 5 times by 1 test: false;return false; Executed by:
executed 5 times by 1 test: return false; Executed by:
| 5 | ||||||||||||||||||
260 | } | - | ||||||||||||||||||
261 | } | - | ||||||||||||||||||
262 | bool QCommandLineParserPrivate::parseOptionValue(const QString &optionName, const QString &argument, | - | ||||||||||||||||||
263 | QStringList::const_iterator *argumentIterator, QStringList::const_iterator argsEnd) | - | ||||||||||||||||||
264 | { | - | ||||||||||||||||||
265 | const QLatin1Char assignChar('='); | - | ||||||||||||||||||
266 | const NameHash_t::const_iterator nameHashIt = nameHash.constFind(optionName); | - | ||||||||||||||||||
267 | if (nameHashIt != nameHash.constEnd()
| 1-38 | ||||||||||||||||||
268 | const int assignPos = argument.indexOf(assignChar); | - | ||||||||||||||||||
269 | const NameHash_t::mapped_type optionOffset = *nameHashIt; | - | ||||||||||||||||||
270 | const bool withValue = !commandLineOptionList.at(optionOffset).valueName().isEmpty(); | - | ||||||||||||||||||
271 | if (withValue
| 14-24 | ||||||||||||||||||
272 | if (assignPos == -1
| 4-20 | ||||||||||||||||||
273 | ++(*argumentIterator); | - | ||||||||||||||||||
274 | if (*
| 1-19 | ||||||||||||||||||
275 | errorText = QCommandLineParser::tr("Missing value after '%1'.").arg(argument); | - | ||||||||||||||||||
276 | return executed 1 time by 1 test: false;return false; Executed by:
executed 1 time by 1 test: return false; Executed by:
| 1 | ||||||||||||||||||
277 | } | - | ||||||||||||||||||
278 | optionValuesHash[optionOffset].append(*(*argumentIterator)); | - | ||||||||||||||||||
279 | } executed 19 times by 1 test: else {end of block Executed by:
| 19 | ||||||||||||||||||
280 | optionValuesHash[optionOffset].append(argument.mid(assignPos + 1)); | - | ||||||||||||||||||
281 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
282 | } else { | - | ||||||||||||||||||
283 | if (assignPos != -1
| 2-12 | ||||||||||||||||||
284 | errorText = QCommandLineParser::tr("Unexpected value after '%1'.").arg(argument.left(assignPos)); | - | ||||||||||||||||||
285 | return executed 2 times by 1 test: false;return false; Executed by:
executed 2 times by 1 test: return false; Executed by:
| 2 | ||||||||||||||||||
286 | } | - | ||||||||||||||||||
287 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||
288 | } | - | ||||||||||||||||||
289 | return executed 36 times by 1 test: true;return true; Executed by:
executed 36 times by 1 test: return true; Executed by:
| 36 | ||||||||||||||||||
290 | } | - | ||||||||||||||||||
291 | bool QCommandLineParserPrivate::parse(const QStringList &args) | - | ||||||||||||||||||
292 | { | - | ||||||||||||||||||
293 | needsParsing = false; | - | ||||||||||||||||||
294 | bool error = false; | - | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | const QString doubleDashString(([]() -> QString { enum { Size = sizeof(u"" "--")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "--" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 50 times by 1 test: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 50 times by 1 test: }()));return qstring_literal_temp; Executed by:
| 50 | ||||||||||||||||||
297 | const QLatin1Char dashChar('-'); | - | ||||||||||||||||||
298 | const QLatin1Char assignChar('='); | - | ||||||||||||||||||
299 | - | |||||||||||||||||||
300 | bool forcePositional = false; | - | ||||||||||||||||||
301 | errorText.clear(); | - | ||||||||||||||||||
302 | positionalArgumentList.clear(); | - | ||||||||||||||||||
303 | optionNames.clear(); | - | ||||||||||||||||||
304 | unknownOptionNames.clear(); | - | ||||||||||||||||||
305 | optionValuesHash.clear(); | - | ||||||||||||||||||
306 | - | |||||||||||||||||||
307 | if (args.isEmpty()
| 1-49 | ||||||||||||||||||
308 | QMessageLogger(__FILE__, 700, __PRETTY_FUNCTION__).warning("QCommandLineParser: argument list cannot be empty, it should contain at least the executable name"); | - | ||||||||||||||||||
309 | return executed 1 time by 1 test: false;return false; Executed by:
executed 1 time by 1 test: return false; Executed by:
| 1 | ||||||||||||||||||
310 | } | - | ||||||||||||||||||
311 | - | |||||||||||||||||||
312 | QStringList::const_iterator argumentIterator = args.begin(); | - | ||||||||||||||||||
313 | ++argumentIterator; | - | ||||||||||||||||||
314 | - | |||||||||||||||||||
315 | for (; argumentIterator != args.end()
| 48-63 | ||||||||||||||||||
316 | QString argument = *argumentIterator; | - | ||||||||||||||||||
317 | - | |||||||||||||||||||
318 | if (forcePositional
| 9-54 | ||||||||||||||||||
319 | positionalArgumentList.append(argument); | - | ||||||||||||||||||
320 | } executed 9 times by 1 test: else if (argument.startsWith(doubleDashString)end of block Executed by:
| 9-30 | ||||||||||||||||||
321 | if (argument.length() > 2
| 2-22 | ||||||||||||||||||
322 | QString optionName = argument.mid(2).section(assignChar, 0, 0); | - | ||||||||||||||||||
323 | if (registerFoundOption(optionName)
| 2-20 | ||||||||||||||||||
324 | if (!parseOptionValue(optionName, argument, &argumentIterator, args.end())
| 1-19 | ||||||||||||||||||
325 | error = true; executed 1 time by 1 test: error = true; Executed by:
| 1 | ||||||||||||||||||
326 | } executed 20 times by 1 test: else {end of block Executed by:
| 20 | ||||||||||||||||||
327 | error = true; | - | ||||||||||||||||||
328 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
329 | } else { | - | ||||||||||||||||||
330 | forcePositional = true; | - | ||||||||||||||||||
331 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
332 | } else if (argument.startsWith(dashChar)
| 7-23 | ||||||||||||||||||
333 | if (argument.size() == 1
| 2-21 | ||||||||||||||||||
334 | positionalArgumentList.append(argument); | - | ||||||||||||||||||
335 | continue; executed 2 times by 1 test: continue; Executed by:
| 2 | ||||||||||||||||||
336 | } | - | ||||||||||||||||||
337 | switch (singleDashWordOptionMode) { | - | ||||||||||||||||||
338 | case executed 16 times by 1 test: QCommandLineParser::ParseAsCompactedShortOptions:case QCommandLineParser::ParseAsCompactedShortOptions: Executed by:
executed 16 times by 1 test: case QCommandLineParser::ParseAsCompactedShortOptions: Executed by:
| 16 | ||||||||||||||||||
339 | { | - | ||||||||||||||||||
340 | QString optionName; | - | ||||||||||||||||||
341 | bool valueFound = false; | - | ||||||||||||||||||
342 | for (int pos = 1 ; pos < argument.size()
| 9-25 | ||||||||||||||||||
343 | optionName = argument.mid(pos, 1); | - | ||||||||||||||||||
344 | if (!registerFoundOption(optionName)
| 3-22 | ||||||||||||||||||
345 | error = true; | - | ||||||||||||||||||
346 | } executed 3 times by 1 test: else {end of block Executed by:
| 3 | ||||||||||||||||||
347 | const NameHash_t::const_iterator nameHashIt = nameHash.constFind(optionName); | - | ||||||||||||||||||
348 | ((!(nameHashIt != nameHash.constEnd())) ? qt_assert("nameHashIt != nameHash.constEnd()",__FILE__,740) : qt_noop()); | - | ||||||||||||||||||
349 | const NameHash_t::mapped_type optionOffset = *nameHashIt; | - | ||||||||||||||||||
350 | const bool withValue = !commandLineOptionList.at(optionOffset).valueName().isEmpty(); | - | ||||||||||||||||||
351 | if (withValue
| 6-16 | ||||||||||||||||||
352 | if (pos + 1 < argument.size()
| 2-4 | ||||||||||||||||||
353 | if (argument.at(pos + 1) == assignChar
| 1 | ||||||||||||||||||
354 | ++ executed 1 time by 1 test: pos;++pos; Executed by:
executed 1 time by 1 test: ++pos; Executed by:
| 1 | ||||||||||||||||||
355 | optionValuesHash[optionOffset].append(argument.mid(pos + 1)); | - | ||||||||||||||||||
356 | valueFound = true; | - | ||||||||||||||||||
357 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
358 | break; executed 6 times by 1 test: break; Executed by:
| 6 | ||||||||||||||||||
359 | } | - | ||||||||||||||||||
360 | if (pos + 1 < argument.size()
| 1-8 | ||||||||||||||||||
361 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||||||||
362 | } executed 15 times by 1 test: end of block Executed by:
| 15 | ||||||||||||||||||
363 | } | - | ||||||||||||||||||
364 | if (!valueFound
| 1-14 | ||||||||||||||||||
365 | error = true; executed 1 time by 1 test: error = true; Executed by:
| 1 | ||||||||||||||||||
366 | break; executed 16 times by 1 test: break; Executed by:
| 16 | ||||||||||||||||||
367 | } | - | ||||||||||||||||||
368 | case executed 5 times by 1 test: QCommandLineParser::ParseAsLongOptions:case QCommandLineParser::ParseAsLongOptions: Executed by:
executed 5 times by 1 test: case QCommandLineParser::ParseAsLongOptions: Executed by:
| 5 | ||||||||||||||||||
369 | { | - | ||||||||||||||||||
370 | const QString optionName = argument.mid(1).section(assignChar, 0, 0); | - | ||||||||||||||||||
371 | if (registerFoundOption(optionName)
| 0-5 | ||||||||||||||||||
372 | if (!parseOptionValue(optionName, argument, &argumentIterator, args.end())
| 1-4 | ||||||||||||||||||
373 | error = true; executed 1 time by 1 test: error = true; Executed by:
| 1 | ||||||||||||||||||
374 | } executed 5 times by 1 test: else {end of block Executed by:
| 5 | ||||||||||||||||||
375 | error = true; | - | ||||||||||||||||||
376 | } never executed: end of block | 0 | ||||||||||||||||||
377 | break; executed 5 times by 1 test: break; Executed by:
| 5 | ||||||||||||||||||
378 | } | - | ||||||||||||||||||
379 | } | - | ||||||||||||||||||
380 | } executed 21 times by 1 test: else {end of block Executed by:
| 21 | ||||||||||||||||||
381 | positionalArgumentList.append(argument); | - | ||||||||||||||||||
382 | if (optionsAfterPositionalArgumentsMode == QCommandLineParser::ParseAsPositionalArguments
| 2-5 | ||||||||||||||||||
383 | forcePositional = true; executed 2 times by 1 test: forcePositional = true; Executed by:
| 2 | ||||||||||||||||||
384 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||
385 | if (argumentIterator == args.end()
| 1-60 | ||||||||||||||||||
386 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||||||||
387 | } executed 60 times by 1 test: end of block Executed by:
| 60 | ||||||||||||||||||
388 | return executed 49 times by 1 test: !error;return !error; Executed by:
executed 49 times by 1 test: return !error; Executed by:
| 49 | ||||||||||||||||||
389 | } | - | ||||||||||||||||||
390 | bool QCommandLineParser::isSet(const QString &name) const | - | ||||||||||||||||||
391 | { | - | ||||||||||||||||||
392 | d->checkParsed("isSet"); | - | ||||||||||||||||||
393 | if (d->optionNames.contains(name)
| 18-29 | ||||||||||||||||||
394 | return executed 18 times by 1 test: true;return true; Executed by:
executed 18 times by 1 test: return true; Executed by:
| 18 | ||||||||||||||||||
395 | const QStringList aliases = d->aliases(name); | - | ||||||||||||||||||
396 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(d->optionNames)>::type> _container_((d->optionNames)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QString &optionName = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
397 | if (aliases.contains(optionName)
| 1-12 | ||||||||||||||||||
398 | return executed 12 times by 1 test: true;return true; Executed by:
executed 12 times by 1 test: return true; Executed by:
| 12 | ||||||||||||||||||
399 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
400 | return executed 17 times by 1 test: false;return false; Executed by:
executed 17 times by 1 test: return false; Executed by:
| 17 | ||||||||||||||||||
401 | } | - | ||||||||||||||||||
402 | QString QCommandLineParser::value(const QString &optionName) const | - | ||||||||||||||||||
403 | { | - | ||||||||||||||||||
404 | d->checkParsed("value"); | - | ||||||||||||||||||
405 | const QStringList valueList = values(optionName); | - | ||||||||||||||||||
406 | - | |||||||||||||||||||
407 | if (!valueList.isEmpty()
| 11-34 | ||||||||||||||||||
408 | return executed 34 times by 1 test: valueList.last();return valueList.last(); Executed by:
executed 34 times by 1 test: return valueList.last(); Executed by:
| 34 | ||||||||||||||||||
409 | - | |||||||||||||||||||
410 | return executed 11 times by 1 test: QString();return QString(); Executed by:
executed 11 times by 1 test: return QString(); Executed by:
| 11 | ||||||||||||||||||
411 | } | - | ||||||||||||||||||
412 | QStringList QCommandLineParser::values(const QString &optionName) const | - | ||||||||||||||||||
413 | { | - | ||||||||||||||||||
414 | d->checkParsed("values"); | - | ||||||||||||||||||
415 | const NameHash_t::const_iterator it = d->nameHash.constFind(optionName); | - | ||||||||||||||||||
416 | if (it != d->nameHash.cend()
| 4-80 | ||||||||||||||||||
417 | const int optionOffset = *it; | - | ||||||||||||||||||
418 | QStringList values = d->optionValuesHash.value(optionOffset); | - | ||||||||||||||||||
419 | if (values.isEmpty()
| 30-50 | ||||||||||||||||||
420 | values = d->commandLineOptionList.at(optionOffset).defaultValues(); executed 30 times by 1 test: values = d->commandLineOptionList.at(optionOffset).defaultValues(); Executed by:
| 30 | ||||||||||||||||||
421 | return executed 80 times by 1 test: values;return values; Executed by:
executed 80 times by 1 test: return values; Executed by:
| 80 | ||||||||||||||||||
422 | } | - | ||||||||||||||||||
423 | - | |||||||||||||||||||
424 | QMessageLogger(__FILE__, 869, __PRETTY_FUNCTION__).warning("QCommandLineParser: option not defined: \"%s\"", QString(optionName).toLocal8Bit().constData()); | - | ||||||||||||||||||
425 | return executed 4 times by 1 test: QStringList();return QStringList(); Executed by:
executed 4 times by 1 test: return QStringList(); Executed by:
| 4 | ||||||||||||||||||
426 | } | - | ||||||||||||||||||
427 | bool QCommandLineParser::isSet(const QCommandLineOption &option) const | - | ||||||||||||||||||
428 | { | - | ||||||||||||||||||
429 | - | |||||||||||||||||||
430 | return executed 8 times by 1 test: !option.names().isEmpty()return !option.names().isEmpty() && isSet(option.names().first()); Executed by:
executed 8 times by 1 test: return !option.names().isEmpty() && isSet(option.names().first()); Executed by:
| 0-8 | ||||||||||||||||||
431 | } | - | ||||||||||||||||||
432 | QString QCommandLineParser::value(const QCommandLineOption &option) const | - | ||||||||||||||||||
433 | { | - | ||||||||||||||||||
434 | return never executed: value(option.names().first());return value(option.names().first()); never executed: return value(option.names().first()); | 0 | ||||||||||||||||||
435 | } | - | ||||||||||||||||||
436 | QStringList QCommandLineParser::values(const QCommandLineOption &option) const | - | ||||||||||||||||||
437 | { | - | ||||||||||||||||||
438 | return executed 8 times by 1 test: values(option.names().first());return values(option.names().first()); Executed by:
executed 8 times by 1 test: return values(option.names().first()); Executed by:
| 8 | ||||||||||||||||||
439 | } | - | ||||||||||||||||||
440 | QStringList QCommandLineParser::positionalArguments() const | - | ||||||||||||||||||
441 | { | - | ||||||||||||||||||
442 | d->checkParsed("positionalArguments"); | - | ||||||||||||||||||
443 | return executed 25 times by 1 test: d->positionalArgumentList;return d->positionalArgumentList; Executed by:
executed 25 times by 1 test: return d->positionalArgumentList; Executed by:
| 25 | ||||||||||||||||||
444 | } | - | ||||||||||||||||||
445 | QStringList QCommandLineParser::optionNames() const | - | ||||||||||||||||||
446 | { | - | ||||||||||||||||||
447 | d->checkParsed("optionNames"); | - | ||||||||||||||||||
448 | return executed 35 times by 1 test: d->optionNames;return d->optionNames; Executed by:
executed 35 times by 1 test: return d->optionNames; Executed by:
| 35 | ||||||||||||||||||
449 | } | - | ||||||||||||||||||
450 | QStringList QCommandLineParser::unknownOptionNames() const | - | ||||||||||||||||||
451 | { | - | ||||||||||||||||||
452 | d->checkParsed("unknownOptionNames"); | - | ||||||||||||||||||
453 | return executed 26 times by 1 test: d->unknownOptionNames;return d->unknownOptionNames; Executed by:
executed 26 times by 1 test: return d->unknownOptionNames; Executed by:
| 26 | ||||||||||||||||||
454 | } | - | ||||||||||||||||||
455 | __attribute__((__noreturn__)) void QCommandLineParser::showVersion() | - | ||||||||||||||||||
456 | { | - | ||||||||||||||||||
457 | showParserMessage(QCoreApplication::applicationName() + QLatin1Char(' ') | - | ||||||||||||||||||
458 | + QCoreApplication::applicationVersion() + QLatin1Char('\n'), | - | ||||||||||||||||||
459 | UsageMessage); | - | ||||||||||||||||||
460 | qt_call_post_routines(); | - | ||||||||||||||||||
461 | :: never executed: exit(0);::exit(0); never executed: ::exit(0); | 0 | ||||||||||||||||||
462 | } | - | ||||||||||||||||||
463 | __attribute__((__noreturn__)) void QCommandLineParser::showHelp(int exitCode) | - | ||||||||||||||||||
464 | { | - | ||||||||||||||||||
465 | showParserMessage(d->helpText(), UsageMessage); | - | ||||||||||||||||||
466 | qt_call_post_routines(); | - | ||||||||||||||||||
467 | :: never executed: exit(exitCode);::exit(exitCode); never executed: ::exit(exitCode); | 0 | ||||||||||||||||||
468 | } | - | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | - | |||||||||||||||||||
471 | - | |||||||||||||||||||
472 | - | |||||||||||||||||||
473 | - | |||||||||||||||||||
474 | - | |||||||||||||||||||
475 | QString QCommandLineParser::helpText() const | - | ||||||||||||||||||
476 | { | - | ||||||||||||||||||
477 | return executed 1 time by 1 test: d->helpText();return d->helpText(); Executed by:
executed 1 time by 1 test: return d->helpText(); Executed by:
| 1 | ||||||||||||||||||
478 | } | - | ||||||||||||||||||
479 | - | |||||||||||||||||||
480 | static QString wrapText(const QString &names, int longestOptionNameString, const QString &description) | - | ||||||||||||||||||
481 | { | - | ||||||||||||||||||
482 | const QLatin1Char nl('\n'); | - | ||||||||||||||||||
483 | QString text = ([]() -> QString { enum { Size = sizeof(u"" " ")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" " " }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 1 time by 1 test: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 1 time by 1 test: }()) + names.leftJustified(longestOptionNameString) + QLatin1Char(' ');return qstring_literal_temp; Executed by:
| 1 | ||||||||||||||||||
484 | const int indent = text.length(); | - | ||||||||||||||||||
485 | int lineStart = 0; | - | ||||||||||||||||||
486 | int lastBreakable = -1; | - | ||||||||||||||||||
487 | const int max = 79 - indent; | - | ||||||||||||||||||
488 | int x = 0; | - | ||||||||||||||||||
489 | const int len = description.length(); | - | ||||||||||||||||||
490 | - | |||||||||||||||||||
491 | for (int i = 0; i < len
| 1-30 | ||||||||||||||||||
492 | ++x; | - | ||||||||||||||||||
493 | const QChar c = description.at(i); | - | ||||||||||||||||||
494 | if (c.isSpace()
| 4-26 | ||||||||||||||||||
495 | lastBreakable = i; executed 4 times by 1 test: lastBreakable = i; Executed by:
| 4 | ||||||||||||||||||
496 | - | |||||||||||||||||||
497 | int breakAt = -1; | - | ||||||||||||||||||
498 | int nextLineStart = -1; | - | ||||||||||||||||||
499 | if (x > max
| 0-30 | ||||||||||||||||||
500 | - | |||||||||||||||||||
501 | breakAt = lastBreakable; | - | ||||||||||||||||||
502 | nextLineStart = lastBreakable + 1; | - | ||||||||||||||||||
503 | } never executed: else if ((x > max - 1end of block
| 0-30 | ||||||||||||||||||
504 | - | |||||||||||||||||||
505 | breakAt = i + 1; | - | ||||||||||||||||||
506 | nextLineStart = breakAt; | - | ||||||||||||||||||
507 | } executed 1 time by 1 test: else if (c == nlend of block Executed by:
| 0-29 | ||||||||||||||||||
508 | - | |||||||||||||||||||
509 | breakAt = i; | - | ||||||||||||||||||
510 | nextLineStart = i + 1; | - | ||||||||||||||||||
511 | } never executed: end of block | 0 | ||||||||||||||||||
512 | - | |||||||||||||||||||
513 | if (breakAt != -1
| 1-29 | ||||||||||||||||||
514 | const int numChars = breakAt - lineStart; | - | ||||||||||||||||||
515 | - | |||||||||||||||||||
516 | if (lineStart > 0
| 0-1 | ||||||||||||||||||
517 | text += QString(indent, QLatin1Char(' ')); never executed: text += QString(indent, QLatin1Char(' ')); | 0 | ||||||||||||||||||
518 | text += description.midRef(lineStart, numChars) + nl; | - | ||||||||||||||||||
519 | x = 0; | - | ||||||||||||||||||
520 | lastBreakable = -1; | - | ||||||||||||||||||
521 | lineStart = nextLineStart; | - | ||||||||||||||||||
522 | if (lineStart < len
| 0-1 | ||||||||||||||||||
523 | ++ never executed: lineStart;++lineStart; never executed: ++lineStart; | 0 | ||||||||||||||||||
524 | i = lineStart; | - | ||||||||||||||||||
525 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
526 | } executed 30 times by 1 test: end of block Executed by:
| 30 | ||||||||||||||||||
527 | - | |||||||||||||||||||
528 | return executed 1 time by 1 test: text;return text; Executed by:
executed 1 time by 1 test: return text; Executed by:
| 1 | ||||||||||||||||||
529 | } | - | ||||||||||||||||||
530 | - | |||||||||||||||||||
531 | QString QCommandLineParserPrivate::helpText() const | - | ||||||||||||||||||
532 | { | - | ||||||||||||||||||
533 | const QLatin1Char nl('\n'); | - | ||||||||||||||||||
534 | QString text; | - | ||||||||||||||||||
535 | const QString exeName = QCoreApplication::instance()->arguments().first(); | - | ||||||||||||||||||
536 | QString usage = exeName; | - | ||||||||||||||||||
537 | if (!commandLineOptionList.isEmpty()
| 0-1 | ||||||||||||||||||
538 | usage += QLatin1Char(' '); | - | ||||||||||||||||||
539 | usage += QCommandLineParser::tr("[options]"); | - | ||||||||||||||||||
540 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
541 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(positionalArgumentDefinitions)>::type> _container_((positionalArgumentDefinitions)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const PositionalArgumentDefinition &arg = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
542 | usage += QLatin1Char(' '); | - | ||||||||||||||||||
543 | usage += arg.syntax; | - | ||||||||||||||||||
544 | } never executed: end of block | 0 | ||||||||||||||||||
545 | text += QCommandLineParser::tr("Usage: %1").arg(usage) + nl; | - | ||||||||||||||||||
546 | if (!description.isEmpty()
| 0-1 | ||||||||||||||||||
547 | text += description + nl; never executed: text += description + nl; | 0 | ||||||||||||||||||
548 | text += nl; | - | ||||||||||||||||||
549 | if (!commandLineOptionList.isEmpty()
| 0-1 | ||||||||||||||||||
550 | text += QCommandLineParser::tr("Options:") + nl; executed 1 time by 1 test: text += QCommandLineParser::tr("Options:") + nl; Executed by:
| 1 | ||||||||||||||||||
551 | QStringList optionNameList; | - | ||||||||||||||||||
552 | int longestOptionNameString = 0; | - | ||||||||||||||||||
553 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(commandLineOptionList)>::type> _container_((commandLineOptionList)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QCommandLineOption &option = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
554 | QStringList optionNames; | - | ||||||||||||||||||
555 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(option.names())>::type> _container_((option.names())); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QString &optionName = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
556 | if (optionName.length() == 1
| 0-1 | ||||||||||||||||||
557 | optionNames.append(QLatin1Char('-') + optionName); never executed: optionNames.append(QLatin1Char('-') + optionName); | 0 | ||||||||||||||||||
558 | else | - | ||||||||||||||||||
559 | optionNames.append(([]() -> QString { enum { Size = sizeof(u"" "--")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "--" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 1 time by 1 test: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 1 time by 1 test: }()) + optionName);return qstring_literal_temp; Executed by:
executed 1 time by 1 test: optionNames.append(([]() -> QString { enum { Size = sizeof(u"" "--")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "--" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()) + optionName); Executed by:
| 1 | ||||||||||||||||||
560 | } | - | ||||||||||||||||||
561 | QString optionNamesString = optionNames.join(([]() -> QString { enum { Size = sizeof(u"" ", ")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" ", " }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 1 time by 1 test: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 1 time by 1 test: }()));return qstring_literal_temp; Executed by:
| 1 | ||||||||||||||||||
562 | if (!option.valueName().isEmpty()
| 0-1 | ||||||||||||||||||
563 | optionNamesString += ([]() -> QString { enum { Size = sizeof(u"" " <")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" " <" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 1 time by 1 test: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 1 time by 1 test: }()) + option.valueName() + QLatin1Char('>');return qstring_literal_temp; Executed by:
executed 1 time by 1 test: optionNamesString += ([]() -> QString { enum { Size = sizeof(u"" " <")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" " <" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()) + option.valueName() + QLatin1Char('>'); Executed by:
| 1 | ||||||||||||||||||
564 | optionNameList.append(optionNamesString); | - | ||||||||||||||||||
565 | longestOptionNameString = qMax(longestOptionNameString, optionNamesString.length()); | - | ||||||||||||||||||
566 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
567 | ++longestOptionNameString; | - | ||||||||||||||||||
568 | for (int i = 0; i < commandLineOptionList.count()
| 1 | ||||||||||||||||||
569 | const QCommandLineOption &option = commandLineOptionList.at(i); | - | ||||||||||||||||||
570 | if (option.isHidden()
| 0-1 | ||||||||||||||||||
571 | continue; never executed: continue; | 0 | ||||||||||||||||||
572 | text += wrapText(optionNameList.at(i), longestOptionNameString, option.description()); | - | ||||||||||||||||||
573 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
574 | if (!positionalArgumentDefinitions.isEmpty()
| 0-1 | ||||||||||||||||||
575 | if (!commandLineOptionList.isEmpty()
| 0 | ||||||||||||||||||
576 | text += nl; never executed: text += nl; | 0 | ||||||||||||||||||
577 | text += QCommandLineParser::tr("Arguments:") + nl; | - | ||||||||||||||||||
578 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(positionalArgumentDefinitions)>::type> _container_((positionalArgumentDefinitions)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const PositionalArgumentDefinition &arg = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
579 | text += wrapText(arg.name, longestOptionNameString, arg.description); | - | ||||||||||||||||||
580 | } never executed: end of block | 0 | ||||||||||||||||||
581 | } never executed: end of block | 0 | ||||||||||||||||||
582 | return executed 1 time by 1 test: text;return text; Executed by:
executed 1 time by 1 test: return text; Executed by:
| 1 | ||||||||||||||||||
583 | } | - | ||||||||||||||||||
584 | - | |||||||||||||||||||
585 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |