Skip to content

Commit 647f8ac

Browse files
committed
Support negative match on product
Makes it easy to get all non-CMIP products in a single handler. This can be used by specifying `products = [ "^cmip" ]`.
1 parent 0e65a31 commit 647f8ac

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/goesproc/handler_goesr.cc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,28 @@ bool GOESRProduct::matchProduct(const std::vector<std::string>& products) const
290290
return true;
291291
}
292292

293+
// Check for a positive match.
293294
const auto begin = std::begin(products);
294295
const auto end = std::end(products);
295296
const auto it = std::find(begin, end, product_.nameShort);
296-
return it != end;
297+
if (it != end) {
298+
return true;
299+
}
300+
301+
// Check for a negative match.
302+
bool performed_negative_check = false;
303+
for (const auto& product : products) {
304+
if (product.empty() || product.at(0) != '^') {
305+
continue;
306+
}
307+
// Compare the sub-string after the negation character.
308+
performed_negative_check = true;
309+
if (product.substr(1) == product_.nameShort) {
310+
return false;
311+
}
312+
}
313+
314+
return performed_negative_check;
297315
}
298316

299317
bool GOESRProduct::matchRegion(const std::vector<std::string>& regions) const {

0 commit comments

Comments
 (0)