Skip to content

Commit 7f4d27d

Browse files
committed
abstract-filter: drop existing ctx lines from defect
... before appending new context lines
1 parent bff3f6c commit 7f4d27d

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

abstract-filter.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ void EventPrunner::handleDef(const Defect &defOrig) {
9999
// /////////////////////////////////////////////////////////////////////////////
100100
// implementation of CtxEmbedder
101101

102+
void dropCtxLines(TEvtList *pEvtList) {
103+
static CtxEventDetector detector;
104+
105+
TEvtList dst;
106+
BOOST_FOREACH(const DefEvent &evt, *pEvtList) {
107+
if (detector.isAnyCtxLine(evt))
108+
continue;
109+
110+
dst.push_back(evt);
111+
}
112+
113+
pEvtList->swap(dst);
114+
}
115+
102116
void appendCtxLines(
103117
TEvtList *pDst,
104118
std::istream &inStr,
@@ -156,6 +170,7 @@ void CtxEmbedder::handleDef(const Defect &defOrig) {
156170

157171
// clone defOrig and append the context lines
158172
Defect def(defOrig);
173+
dropCtxLines(&def.events);
159174
appendCtxLines(&def.events, fstr, evt.line, ctxLines_ - 1);
160175

161176
// close the file stream and forward the result

abstract-writer.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "instream.hh"
2424
#include "json-writer.hh"
2525

26+
#include <boost/regex.hpp>
27+
2628
// /////////////////////////////////////////////////////////////////////////////
2729
// implementation of AbstractWriter
2830

@@ -100,3 +102,30 @@ AbstractWriter* createWriter(
100102

101103
return writer;
102104
}
105+
106+
107+
// /////////////////////////////////////////////////////////////////////////////
108+
// implementation of CtxEventDetector
109+
110+
struct CtxEventDetector::Private {
111+
boost::regex reAnyCtxLine;
112+
113+
Private():
114+
reAnyCtxLine("^ *[0-9]+\\|(?:->)? .*$")
115+
{
116+
}
117+
};
118+
119+
CtxEventDetector::CtxEventDetector():
120+
d(new Private)
121+
{
122+
}
123+
124+
CtxEventDetector::~CtxEventDetector() {
125+
delete d;
126+
}
127+
128+
bool CtxEventDetector::isAnyCtxLine(const DefEvent &evt) const {
129+
return (evt.event == "#")
130+
&& boost::regex_match(evt.msg, d->reAnyCtxLine);
131+
}

abstract-writer.hh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,16 @@ AbstractWriter* createWriter(
7272
const EColorMode cm = CM_AUTO,
7373
const TScanProps &scanProps = TScanProps());
7474

75+
class CtxEventDetector {
76+
public:
77+
CtxEventDetector();
78+
~CtxEventDetector();
79+
80+
bool isAnyCtxLine(const DefEvent &evt) const;
81+
82+
private:
83+
struct Private;
84+
Private *d;
85+
};
86+
7587
#endif /* H_GUARD_ABSTRACT_WRITER_H */

0 commit comments

Comments
 (0)