2121
2222#include < cstdio>
2323
24- #include < boost/tokenizer.hpp>
25-
2624// /////////////////////////////////////////////////////////////////////////////
2725// implementation of CweMap
2826struct CweMap ::Private {
2927 typedef std::map<std::string, int > TNumByEvent;
3028 typedef std::map<std::string, TNumByEvent> TMapByChk;
3129
32- std::string fileName;
33- std::string line;
34- int lineno;
35- bool silent;
36- bool hasError;
3730 TMapByChk mapByChk;
38-
39- void parseError (const std::string &msg);
40- void parseLine ();
4131};
4232
4333CweMap::CweMap ():
4434 d(new Private)
4535{
46- d->silent = false ;
47- d->hasError = false ;
4836}
4937
5038CweMap::~CweMap ()
@@ -57,35 +45,11 @@ bool CweMap::empty() const
5745 return d->mapByChk .empty ();
5846}
5947
60- void CweMap::setSilent (bool silent)
61- {
62- d->silent = silent;
63- }
64-
65- void CweMap::Private::parseError (const std::string &msg)
66- {
67- this ->hasError = true ;
68- if (this ->silent )
69- return ;
70- std::cerr
71- << this ->fileName << " :"
72- << this ->lineno << " : error: "
73- << msg << " \n " ;
74- }
75-
76- void CweMap::Private::parseLine ()
48+ bool CweMap::handleLine (const TStringList &fields)
7749{
78- // initialize tokenizer
79- typedef boost::escaped_list_separator<char > TSeparator;
80- typedef boost::tokenizer<TSeparator> TTokenizer;
81- TTokenizer tok (this ->line );
82-
83- // break the current line into fields
84- typedef std::vector<std::string> TStringList;
85- TStringList fields (tok.begin (), tok.end ());
8650 if (3U != fields.size ()) {
8751 this ->parseError (" invalid count of fields" );
88- return ;
52+ return /* continue */ true ;
8953 }
9054
9155 // parse CWE number
@@ -94,12 +58,12 @@ void CweMap::Private::parseLine()
9458 if (1 != sscanf (fields[/* CWE */ 2 ].c_str (), " CWE-%u%c" , &cwe, &c) || !cwe)
9559 {
9660 this ->parseError (" invalid CWE ID" );
97- return ;
61+ return /* continue */ true ;
9862 }
9963
10064 // lookup by checker
10165 const std::string &chk = fields[/* chk */ 0 ];
102- TNumByEvent &row = this ->mapByChk [chk];
66+ Private:: TNumByEvent &row = d ->mapByChk [chk];
10367
10468 // lookup by event
10569 const std::string &evt = fields[/* evt */ 1 ];
@@ -108,19 +72,8 @@ void CweMap::Private::parseLine()
10872
10973 // store the mapping
11074 row[evt] = cwe;
111- }
112-
113- bool CweMap::loadCweMap (std::istream &str, const std::string &fileName)
114- {
115- d->fileName = fileName;
116- d->lineno = 0 ;
117-
118- while (std::getline (str, d->line )) {
119- d->lineno ++;
120- d->parseLine ();
121- }
12275
123- return !d-> hasError ;
76+ return /* continue */ true ;
12477}
12578
12679bool CweMap::assignCwe (Defect &def) const
@@ -134,7 +87,7 @@ bool CweMap::assignCwe(Defect &def) const
13487 // CWE already assigned, stay silent
13588 return true ;
13689
137- if (!d ->silent )
90+ if (!this ->silent )
13891 std::cerr << " warning: CWE not found: checker = "
13992 << def.checker <<" \n " ;
14093 return false ;
@@ -149,7 +102,7 @@ bool CweMap::assignCwe(Defect &def) const
149102 // CWE already assigned, stay silent
150103 return true ;
151104
152- if (!d ->silent )
105+ if (!this ->silent )
153106 std::cerr << " warning: CWE not found: checker = " << def.checker
154107 << " , event = " << evt.event << " \n " ;
155108
@@ -167,7 +120,7 @@ bool CweMap::assignCwe(Defect &def) const
167120 // already assigned to the requested value
168121 return true ;
169122
170- if (cweDst && !d ->silent )
123+ if (cweDst && !this ->silent )
171124 // we are rewriting the CWE
172125 std::cerr << " warning: CWE overriden: "
173126 << cweSrc << " -> "
0 commit comments