File tree Expand file tree Collapse file tree 5 files changed +42
-34
lines changed Expand file tree Collapse file tree 5 files changed +42
-34
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ add_library(cs STATIC
38
38
instream.cc
39
39
json-parser.cc
40
40
json-writer.cc
41
+ parser-common.cc
41
42
shared-string.cc
42
43
version .cc
43
44
)
Original file line number Diff line number Diff line change 29
29
#include < sstream>
30
30
31
31
#include < boost/algorithm/string.hpp>
32
- #include < boost/lexical_cast.hpp>
33
32
#include < boost/regex.hpp>
34
33
35
34
class LineReader {
@@ -185,20 +184,10 @@ EToken ErrFileLexer::readNext() {
185
184
evt_.msg = sm[/* msg */ 5 ];
186
185
187
186
// parse line number
188
- try {
189
- evt_.line = boost::lexical_cast<int >(sm[/* line */ 2 ]);
190
- }
191
- catch (boost::bad_lexical_cast &) {
192
- evt_.line = 0 ;
193
- }
187
+ evt_.line = parse_int (sm[/* line */ 2 ]);
194
188
195
189
// parse column number
196
- try {
197
- evt_.column = boost::lexical_cast<int >(sm[/* col */ 3 ]);
198
- }
199
- catch (boost::bad_lexical_cast &) {
200
- evt_.column = 0 ;
201
- }
190
+ evt_.column = parse_int (sm[/* col */ 3 ]);
202
191
203
192
return T_EVENT;
204
193
}
Original file line number Diff line number Diff line change 24
24
#include < algorithm>
25
25
26
26
#include < boost/foreach.hpp>
27
- #include < boost/lexical_cast.hpp>
28
27
#include < boost/regex.hpp>
29
28
30
29
enum EToken {
@@ -156,20 +155,10 @@ EToken Tokenizer::readNext(DefEvent *pEvt) {
156
155
pEvt->fileName = sm[/* file */ 1 ];
157
156
158
157
// parse line number
159
- try {
160
- pEvt->line = boost::lexical_cast<int >(sm[/* line */ 2 ]);
161
- }
162
- catch (boost::bad_lexical_cast &) {
163
- pEvt->line = 0 ;
164
- }
158
+ pEvt->line = parse_int (sm[/* line */ 2 ]);
165
159
166
160
// parse column number
167
- try {
168
- pEvt->column = boost::lexical_cast<int >(sm[/* col */ 3 ]);
169
- }
170
- catch (boost::bad_lexical_cast &) {
171
- pEvt->column = 0 ;
172
- }
161
+ pEvt->column = parse_int (sm[/* col */ 3 ]);
173
162
174
163
return tok;
175
164
}
@@ -574,14 +563,8 @@ void PostProcessor::transGccAnal(Defect *pDef) {
574
563
575
564
// pick CWE number if available
576
565
const std::string rawMsg = sm[/* msg */ 1 ];
577
- if (boost::regex_match (rawMsg, sm, reGccAnalCwe_)) {
578
- try {
579
- pDef->cwe = boost::lexical_cast<int >(sm[/* cwe */ 1 ]);
580
- }
581
- catch (boost::bad_lexical_cast &) {
582
- pDef->cwe = 0 ;
583
- }
584
- }
566
+ if (boost::regex_match (rawMsg, sm, reGccAnalCwe_))
567
+ pDef->cwe = parse_int (sm[/* cwe */ 1 ]);
585
568
}
586
569
587
570
void PostProcessor::apply (Defect *pDef) {
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (C) 2020 Red Hat, Inc.
3
+ *
4
+ * This file is part of csdiff.
5
+ *
6
+ * csdiff is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * any later version.
10
+ *
11
+ * csdiff is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with csdiff. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+ #include " parser-common.hh"
21
+
22
+ #include < boost/lexical_cast.hpp>
23
+
24
+ int parse_int (const std::string &str, const int fallback) {
25
+ try {
26
+ return boost::lexical_cast<int >(str);
27
+ }
28
+ catch (boost::bad_lexical_cast &) {
29
+ return fallback;
30
+ }
31
+ }
Original file line number Diff line number Diff line change 20
20
#ifndef H_GUARD_PARSER_COMMON_H
21
21
#define H_GUARD_PARSER_COMMON_H
22
22
23
+ #include < string>
24
+
23
25
#define RE_EVENT_GCC " (?:(?:(?:fatal|internal) )?[a-z][\\ [\\ ]A-Za-z0-9_-]+)"
24
26
#define RE_EVENT_PROSPECTOR " (?:[A-Z]+[0-9]+\\ [[a-z0-9-]+\\ ])"
25
27
#define RE_EVENT RE_EVENT_GCC " |" RE_EVENT_PROSPECTOR
26
28
29
+ int parse_int (const std::string &, int fallback = 0 );
30
+
27
31
#endif /* H_GUARD_PARSER_COMMON_H */
You can’t perform that action at this time.
0 commit comments