| 81 | } |
| 82 | |
| 83 | bool MatchParser::parse() |
| 84 | { |
| 85 | QStringList::const_iterator it; |
| 86 | for (it = m_args.constBegin(); it != m_args.constEnd(); ++it) |
| 87 | { |
| 88 | if (!m_validOptions.contains(*it)) |
| 89 | { |
| 90 | qWarning("Unknown option: \"%s\"", qUtf8Printable(*it)); |
| 91 | return false; |
| 92 | } |
| 93 | QString name = *it; |
| 94 | PrivateOption& option = m_validOptions[name]; |
| 95 | |
| 96 | QStringList list; |
| 97 | while (++it != m_args.constEnd()) |
| 98 | { |
| 99 | if (it->size() > 1 && it->startsWith('-')) |
| 100 | { |
| 101 | bool ok = false; |
| 102 | it->toDouble(&ok); |
| 103 | if (!ok) |
| 104 | break; |
| 105 | } |
| 106 | list << *it; |
| 107 | } |
| 108 | --it; |
| 109 | |
| 110 | if (!option.duplicates && contains(name)) |
| 111 | { |
| 112 | qWarning("Multiple instances of option \"%s\"", |
| 113 | qUtf8Printable(name)); |
| 114 | return false; |
| 115 | } |
| 116 | |
| 117 | if (list.size() < option.minArgs) |
| 118 | { |
| 119 | if (option.maxArgs == option.minArgs) |
| 120 | qWarning("Option \"%s\" needs %d argument(s)", |
| 121 | qUtf8Printable(name), option.minArgs); |
| 122 | else |
| 123 | qWarning("Option \"%s\" needs at least %d argument(s)", |
| 124 | qUtf8Printable(name), option.minArgs); |
| 125 | return false; |
| 126 | } |
| 127 | if (option.maxArgs != -1 && list.size() > option.maxArgs) |
| 128 | { |
| 129 | qWarning("Too many arguments for option \"%s\"", |
| 130 | qUtf8Printable(name)); |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | // Boolean option |
| 135 | if (list.isEmpty()) |
| 136 | { |
| 137 | Option tmp = { name, QVariant(true) }; |
| 138 | m_options.insert(option.priority, tmp); |
| 139 | continue; |
| 140 | } |
no test coverage detected