Strip optional --type / --extension / --avail / --min-size / --max-size flags from `args`, leaving only the search keyword(s). Each flag takes exactly one whitespace-separated value. Unknown tokens are preserved as part of the search query, joined by single spaces in input order. Returns true on success, false if a flag is missing its value or a value fails to parse; on failure the output values a
| 150 | // Returns true on success, false if a flag is missing its value or a value |
| 151 | // fails to parse; on failure the output values are undefined. |
| 152 | static bool ParseSearchFilters( |
| 153 | wxString& args, |
| 154 | wxString& type, |
| 155 | wxString& extension, |
| 156 | uint32& avail, |
| 157 | uint64& min_size, |
| 158 | uint64& max_size) |
| 159 | { |
| 160 | type.Clear(); |
| 161 | extension.Clear(); |
| 162 | avail = 0; |
| 163 | min_size = 0; |
| 164 | max_size = 0; |
| 165 | |
| 166 | wxString remaining; |
| 167 | wxStringTokenizer tok(args, wxT(" \t")); |
| 168 | while (tok.HasMoreTokens()) { |
| 169 | wxString t = tok.GetNextToken(); |
| 170 | if (t == wxT("--type")) { |
| 171 | if (!tok.HasMoreTokens()) return false; |
| 172 | type = tok.GetNextToken(); |
| 173 | } else if (t == wxT("--extension") || t == wxT("--ext")) { |
| 174 | if (!tok.HasMoreTokens()) return false; |
| 175 | extension = tok.GetNextToken(); |
| 176 | } else if (t == wxT("--avail") || t == wxT("--availability")) { |
| 177 | if (!tok.HasMoreTokens()) return false; |
| 178 | unsigned long n = 0; |
| 179 | if (!tok.GetNextToken().ToULong(&n)) return false; |
| 180 | avail = static_cast<uint32>(n); |
| 181 | } else if (t == wxT("--min-size")) { |
| 182 | if (!tok.HasMoreTokens()) return false; |
| 183 | if (!ParseSizeWithSuffix(tok.GetNextToken(), min_size)) return false; |
| 184 | } else if (t == wxT("--max-size")) { |
| 185 | if (!tok.HasMoreTokens()) return false; |
| 186 | if (!ParseSizeWithSuffix(tok.GetNextToken(), max_size)) return false; |
| 187 | } else { |
| 188 | if (!remaining.IsEmpty()) { |
| 189 | remaining += wxT(' '); |
| 190 | } |
| 191 | remaining += t; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | args = remaining; |
| 196 | return true; |
| 197 | } |
| 198 | |
| 199 | //------------------------------------------------------------------- |
| 200 | IMPLEMENT_APP (CamulecmdApp) |
no test coverage detected