! \internal \brief Parse the value for a given option, if it was defined to expect one. The value is taken from the next argument, or after the equal sign in \a argument. \param optionName the short option name \param argument the argument from the command line currently parsed. Only used for -k=value parsing. \param argumentIterator iterator to the currently parsed argum
| 481 | Returns \c true on success. |
| 482 | */ |
| 483 | bool QCommandLineParserPrivate::parseOptionValue(const QString &optionName, const QString &argument, |
| 484 | QStringList::const_iterator *argumentIterator, QStringList::const_iterator argsEnd) |
| 485 | { |
| 486 | const QLatin1Char assignChar('='); |
| 487 | const NameHash_t::const_iterator nameHashIt = nameHash.constFind(optionName); |
| 488 | if (nameHashIt != nameHash.constEnd()) { |
| 489 | const int assignPos = argument.indexOf(assignChar); |
| 490 | const NameHash_t::mapped_type optionOffset = *nameHashIt; |
| 491 | const bool withValue = !commandLineOptionList.at(optionOffset).valueName().isEmpty(); |
| 492 | if (withValue) { |
| 493 | if (assignPos == -1) { |
| 494 | ++(*argumentIterator); |
| 495 | if (*argumentIterator == argsEnd) { |
| 496 | errorText = QCommandLineParser::tr("Missing value after '%1'.").arg(argument); |
| 497 | return false; |
| 498 | } |
| 499 | optionValuesHash[optionOffset].append(*(*argumentIterator)); |
| 500 | } else { |
| 501 | optionValuesHash[optionOffset].append(argument.mid(assignPos + 1)); |
| 502 | } |
| 503 | } else { |
| 504 | if (assignPos != -1) { |
| 505 | errorText = QCommandLineParser::tr("Unexpected value after '%1'.").arg(argument.left(assignPos)); |
| 506 | return false; |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | return true; |
| 511 | } |
| 512 | |
| 513 | /*! |
| 514 | \internal |