@@ -388,6 +388,55 @@ class DropScanProps: public GenericAbstractFilter {
388
388
const TScanProps emp_;
389
389
};
390
390
391
+ class ScanPropSetter : public GenericAbstractFilter {
392
+ public:
393
+ ScanPropSetter (AbstractWriter *agent, const TStringList &propList);
394
+
395
+ // / override specified scan properties
396
+ void setScanProps (const TScanProps &origProps) override ;
397
+
398
+ private:
399
+ // key/val pairs are stored in a vector
400
+ using TItem = std::pair<std::string, std::string>;
401
+ using TList = std::vector<TItem>;
402
+ TList itemList_;
403
+ };
404
+
405
+ ScanPropSetter::ScanPropSetter (
406
+ AbstractWriter *agent,
407
+ const TStringList &propList):
408
+ GenericAbstractFilter(agent)
409
+ {
410
+ // iterate over the given NAME:VALUE strings
411
+ for (const std::string &str : propList) {
412
+ // split the string by the first occurrence of ':'
413
+ size_t ddAt = str.find (' :' );
414
+ if (std::string::npos == ddAt) {
415
+ const auto msg = " missing ':' in " + str;
416
+ throw std::runtime_error (msg);
417
+ }
418
+
419
+ // store the key/val pair into the vector
420
+ TItem item;
421
+ item./* key */ first = str.substr (0 , ddAt);
422
+ item./* val */ second = str.substr (ddAt + 1 );
423
+ itemList_.emplace_back (item);
424
+ }
425
+ }
426
+
427
+ void ScanPropSetter::setScanProps (const TScanProps &origProps)
428
+ {
429
+ // we need to copy the given map
430
+ TScanProps props = origProps;
431
+
432
+ // apply specified changes
433
+ for (const auto &item : itemList_)
434
+ props[item./* key */ first] = item./* val */ second;
435
+
436
+ // forward the result
437
+ agent_->setScanProps (props);
438
+ }
439
+
391
440
class DuplicateFilter : public AbstractFilter {
392
441
public:
393
442
DuplicateFilter (AbstractWriter *agent):
@@ -632,6 +681,7 @@ int main(int argc, char *argv[])
632
681
(" embed-context,U" , po::value<int >(), " embed a number of lines of context from the source file for the key event" )
633
682
(" prune-events" , po::value<int >(), " event is preserved if its verbosity level is below the given number" )
634
683
(" remove-duplicates,u" , " remove defects that are not unique by their key event" )
684
+ (" set-scan-prop" , po::value<TStringList>(), " NAME:VALUE pair to override the specified scan property" )
635
685
(" strip-path-prefix" , po::value<string>(), " string prefix to strip from path (applied after all filters)" )
636
686
637
687
(" ignore-case,i" , " ignore case when matching regular expressions" )
@@ -712,6 +762,11 @@ int main(int argc, char *argv[])
712
762
" strip-path-prefix" ))
713
763
return 1 ;
714
764
765
+ // insert ScanPropSetter into the chain if requested
766
+ if (!chainDecoratorGeneric<ScanPropSetter, TStringList>(&eng, vm,
767
+ " set-scan-prop" ))
768
+ return 1 ;
769
+
715
770
// chain all filters
716
771
if (!chainFilters (&eng, vm))
717
772
// an error message already printed out
0 commit comments