Skip to content

Commit 26df3de

Browse files
committed
coding style: initialize regexes in a more developer-friendly way
Closes: https://github.com/kdudka/csdiff/pull/15
1 parent ca11be2 commit 26df3de

File tree

12 files changed

+226
-205
lines changed

12 files changed

+226
-205
lines changed

src/abstract-writer.cc

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
#include "abstract-writer.hh"
2121

2222
#include "cswriter.hh"
23+
#include "html-writer.hh"
2324
#include "instream.hh"
2425
#include "json-writer.hh"
25-
#include "html-writer.hh"
26-
27-
#include <boost/regex.hpp>
26+
#include "regex.hh"
2827

2928
// /////////////////////////////////////////////////////////////////////////////
3029
// implementation of AbstractWriter
@@ -121,14 +120,8 @@ AbstractWriter* createWriter(
121120
// implementation of CtxEventDetector
122121

123122
struct CtxEventDetector::Private {
124-
boost::regex reAnyCtxLine;
125-
boost::regex reKeyCtxLine;
126-
127-
Private():
128-
reAnyCtxLine("^ *[0-9]+\\|(?:->)? .*$"),
129-
reKeyCtxLine("^ *[0-9]+\\|-> .*$")
130-
{
131-
}
123+
const RE reAnyCtxLine = RE("^ *[0-9]+\\|(?:->)? .*$");
124+
const RE reKeyCtxLine = RE("^ *[0-9]+\\|-> .*$");
132125
};
133126

134127
CtxEventDetector::CtxEventDetector():

src/csdiff.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
#include "csdiff-core.hh"
2121
#include "csfilter.hh"
2222
#include "instream.hh"
23+
#include "regex.hh"
2324
#include "version.hh"
2425

2526
#include <cstdlib>
2627

2728
#include <boost/program_options.hpp>
28-
#include <boost/regex.hpp>
2929

3030
int main(int argc, char *argv[])
3131
{
@@ -119,7 +119,7 @@ int main(int argc, char *argv[])
119119
if (vm.count("file-rename")) {
120120
const TStringList &substList = vm["file-rename"].as<TStringList>();
121121
boost::smatch sm;
122-
const boost::regex reSubst("([^,]+),(.*)");
122+
const RE reSubst("([^,]+),(.*)");
123123
for (const string &subst : substList) {
124124
if (!boost::regex_match(subst, sm, reSubst)) {
125125
std::cerr << "bad substutution format: " << subst

src/csfilter.cc

Lines changed: 58 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@
1818
*/
1919

2020
#include "csfilter.hh"
21+
#include "regex.hh"
2122

2223
#include <iostream>
2324

24-
#include <boost/regex.hpp>
25-
2625
// Setup verbosity for debugging string substitions while matching them.
2726
// Verbosity levels are from 0 to 3 (0 is off)
2827
#define DEBUG_SUBST 0
2928

3029
inline std::string regexReplaceWrap(
3130
const std::string &input,
32-
const boost::regex &re,
31+
const RE &re,
3332
const std::string &fmt)
3433
{
3534
std::string output(boost::regex_replace(input, re, fmt));
@@ -43,7 +42,7 @@ inline std::string regexReplaceWrap(
4342
MsgFilter* MsgFilter::self_;
4443

4544
struct MsgReplace {
46-
const boost::regex regex;
45+
const RE regex;
4746
const std::string replaceWith;
4847

4948
MsgReplace(const std::string &regex_, const std::string &rpl) :
@@ -57,18 +56,18 @@ typedef std::vector<MsgReplace *> TRegexList;
5756
typedef std::map<const std::string, TRegexList> TMsgFilterMap;
5857

5958
struct MsgFilter::Private {
60-
bool ignorePath;
61-
const std::string strKrn;
62-
const boost::regex reKrn;
63-
const boost::regex reMsgConstExprRes;
64-
const boost::regex reDir;
65-
const boost::regex reFile;
66-
const boost::regex rePath;
67-
const boost::regex reTmpPath;
68-
const boost::regex reTmpCleaner;
59+
bool ignorePath = false;
6960
TMsgFilterMap msgFilterMap;
7061
TSubstMap fileSubsts;
7162

63+
const std::string strKrn = "^[a-zA-Z+]+";
64+
const RE reKrn = RE(strKrn);
65+
const RE reDir = RE("^([^:]*/)");
66+
const RE reFile = RE("[^/]+$");
67+
const RE rePath = RE("^(?:/builddir/build/BUILD/)?([^/]+/)(.*)(\\.[ly])?$");
68+
const RE reTmpPath = RE("^(/var)?/tmp/(.*)$");
69+
const RE reTmpCleaner = RE("(.*)");
70+
7271
void addMsgFilter(
7372
const std::string &checker,
7473
const std::string &regexp,
@@ -77,68 +76,56 @@ struct MsgFilter::Private {
7776
struct MsgReplace *rpl = new MsgReplace(regexp, replacement);
7877
msgFilterMap[checker].push_back(rpl);
7978
}
80-
81-
Private():
82-
ignorePath(false),
83-
strKrn("^[a-zA-Z+]+"),
84-
reKrn(strKrn),
85-
reDir("^([^:]*/)"),
86-
reFile("[^/]+$"),
87-
rePath("^(?:/builddir/build/BUILD/)?([^/]+/)(.*)(\\.[ly])?$"),
88-
reTmpPath("^(/var)?/tmp/(.*)$"),
89-
reTmpCleaner("(.*)")
90-
{
91-
addMsgFilter("", "[0-9][0-9]* out of [0-9][0-9]* times");
92-
addMsgFilter("UNUSED_VALUE",
93-
"\\(instance [0-9]+\\)");
94-
addMsgFilter("STRING_OVERFLOW",
95-
"You might overrun the [0-9][0-9]* byte");
96-
// ignore changes in parameters -> it is still the same UNUSED_VALUE
97-
addMsgFilter("UNUSED_VALUE",
98-
"returned by \"([^\\(]+)\\(.*\\)\"",
99-
"returned by \"\\1\\(\\)\"");
100-
101-
// unify the format of glib/gnome dprecation warnings
102-
// NOTE: "\u007f\u007f\u007f" does not compile on el6
103-
static const char uniApos[] = { 0x7f, 0x7f, 0x7f, 0x00 };
104-
addMsgFilter("COMPILER_WARNING", uniApos, "'");
105-
106-
// ignore embeded declaration location
107-
addMsgFilter("COMPILER_WARNING", " \\(declared at [^)]*\\)", "");
108-
109-
// ignore suggestion for deprecation warnings
110-
addMsgFilter("COMPILER_WARNING", ": Use '[^']*' instead", "");
111-
112-
// unify (per build random) names of temporary variables
113-
addMsgFilter("COMPILER_WARNING", "_tmp[0-9]+_", "_tmp_");
114-
115-
// pylint reports, either raw, or prospector-wrapped
116-
const std::vector<std::string> pylintCheckers= {
117-
"PROSPECTOR_WARNING",
118-
"PYLINT_WARNING"
119-
};
120-
for (const std::string &checker : pylintCheckers) {
121-
// "Too many lines in module (1152/1000)" etc.
122-
addMsgFilter(checker, " \\([0-9]+/[0-9]+\\)$", "");
123-
124-
// "... Redefining name 'desc' from outer scope (line 10)" etc.
125-
addMsgFilter(checker, " \\((?:imported )?line [0-9]+\\)$", "");
126-
}
127-
128-
// "__coverity_strcmp" -> "strcmp", etc.
129-
addMsgFilter("", "__coverity_", "");
130-
131-
// artificial field names of anonymous unions that Coverity produces
132-
addMsgFilter("", "__C[0-9]+");
133-
134-
// used by IDENTIFIER_TYPO (but applies generally)
135-
addMsgFilter("", "at least [0-9][0-9]* times.$");
136-
}
13779
};
13880

13981
MsgFilter::MsgFilter():
14082
d(new Private)
14183
{
84+
d->addMsgFilter("", "[0-9][0-9]* out of [0-9][0-9]* times");
85+
d->addMsgFilter("UNUSED_VALUE",
86+
"\\(instance [0-9]+\\)");
87+
d->addMsgFilter("STRING_OVERFLOW",
88+
"You might overrun the [0-9][0-9]* byte");
89+
// ignore changes in parameters -> it is still the same UNUSED_VALUE
90+
d->addMsgFilter("UNUSED_VALUE",
91+
"returned by \"([^\\(]+)\\(.*\\)\"",
92+
"returned by \"\\1\\(\\)\"");
93+
94+
// unify the format of glib/gnome dprecation warnings
95+
// NOTE: "\u007f\u007f\u007f" does not compile on el6
96+
static const char uniApos[] = { 0x7f, 0x7f, 0x7f, 0x00 };
97+
d->addMsgFilter("COMPILER_WARNING", uniApos, "'");
98+
99+
// ignore embeded declaration location
100+
d->addMsgFilter("COMPILER_WARNING", " \\(declared at [^)]*\\)", "");
101+
102+
// ignore suggestion for deprecation warnings
103+
d->addMsgFilter("COMPILER_WARNING", ": Use '[^']*' instead", "");
104+
105+
// unify (per build random) names of temporary variables
106+
d->addMsgFilter("COMPILER_WARNING", "_tmp[0-9]+_", "_tmp_");
107+
108+
// pylint reports, either raw, or prospector-wrapped
109+
const std::vector<std::string> pylintCheckers= {
110+
"PROSPECTOR_WARNING",
111+
"PYLINT_WARNING"
112+
};
113+
for (const std::string &checker : pylintCheckers) {
114+
// "Too many lines in module (1152/1000)" etc.
115+
d->addMsgFilter(checker, " \\([0-9]+/[0-9]+\\)$", "");
116+
117+
// "... Redefining name 'desc' from outer scope (line 10)" etc.
118+
d->addMsgFilter(checker, " \\((?:imported )?line [0-9]+\\)$", "");
119+
}
120+
121+
// "__coverity_strcmp" -> "strcmp", etc.
122+
d->addMsgFilter("", "__coverity_", "");
123+
124+
// artificial field names of anonymous unions that Coverity produces
125+
d->addMsgFilter("", "__C[0-9]+");
126+
127+
// used by IDENTIFIER_TYPO (but applies generally)
128+
d->addMsgFilter("", "at least [0-9][0-9]* times.$");
142129
}
143130

144131
MsgFilter::~MsgFilter()
@@ -224,7 +211,7 @@ std::string MsgFilter::filterPath(const std::string &origPath)
224211
std::cerr << "krnPattern: " << krnPattern << "\n";
225212
#endif
226213

227-
const boost::regex reKill(krnPattern);
214+
const RE reKill(krnPattern);
228215
core = boost::regex_replace(core, reKill, "");
229216

230217
// quirk for Coverity inconsistency in handling bison-generated file names

src/csgrep.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "abstract-filter.hh"
2222
#include "cswriter.hh"
2323
#include "json-writer.hh"
24+
#include "regex.hh"
2425
#include "version.hh"
2526

2627
#include <cstdlib>
@@ -29,7 +30,6 @@
2930
#include <map>
3031

3132
#include <boost/program_options.hpp>
32-
#include <boost/regex.hpp>
3333

3434
class StatWriter: public AbstractWriter {
3535
public:
@@ -171,10 +171,10 @@ class FileDefCounter: public StatWriter {
171171

172172
class MsgPredicate: public IPredicate {
173173
private:
174-
boost::regex re_;
174+
const RE re_;
175175

176176
public:
177-
MsgPredicate(const boost::regex &re):
177+
MsgPredicate(const RE &re):
178178
re_(re)
179179
{
180180
}
@@ -191,10 +191,10 @@ class MsgPredicate: public IPredicate {
191191

192192
class KeyEventPredicate: public IPredicate {
193193
private:
194-
boost::regex re_;
194+
const RE re_;
195195

196196
public:
197-
KeyEventPredicate(const boost::regex &re):
197+
KeyEventPredicate(const RE &re):
198198
re_(re)
199199
{
200200
}
@@ -207,10 +207,10 @@ class KeyEventPredicate: public IPredicate {
207207

208208
class ErrorPredicate: public IPredicate {
209209
private:
210-
boost::regex re_;
210+
const RE re_;
211211

212212
public:
213-
ErrorPredicate(const boost::regex &re):
213+
ErrorPredicate(const RE &re):
214214
re_(re)
215215
{
216216
}
@@ -223,10 +223,10 @@ class ErrorPredicate: public IPredicate {
223223

224224
class PathPredicate: public IPredicate {
225225
private:
226-
boost::regex re_;
226+
const RE re_;
227227

228228
public:
229-
PathPredicate(const boost::regex &re):
229+
PathPredicate(const RE &re):
230230
re_(re)
231231
{
232232
}
@@ -239,10 +239,10 @@ class PathPredicate: public IPredicate {
239239

240240
class CheckerPredicate: public IPredicate {
241241
private:
242-
boost::regex re_;
242+
const RE re_;
243243

244244
public:
245-
CheckerPredicate(const boost::regex &re):
245+
CheckerPredicate(const RE &re):
246246
re_(re)
247247
{
248248
}
@@ -254,10 +254,10 @@ class CheckerPredicate: public IPredicate {
254254

255255
class AnnotPredicate: public IPredicate {
256256
private:
257-
boost::regex re_;
257+
const RE re_;
258258

259259
public:
260-
AnnotPredicate(const boost::regex &re):
260+
AnnotPredicate(const RE &re):
261261
re_(re)
262262
{
263263
}
@@ -269,10 +269,10 @@ class AnnotPredicate: public IPredicate {
269269

270270
class SrcAnnotPredicate: public IPredicate {
271271
private:
272-
boost::regex re_;
272+
const RE re_;
273273

274274
public:
275-
SrcAnnotPredicate(const boost::regex &re):
275+
SrcAnnotPredicate(const RE &re):
276276
re_(re)
277277
{
278278
}
@@ -430,7 +430,7 @@ bool appendPredIfNeeded(
430430
TPred *pred = 0;
431431
const std::string &reStr = vm[key].as<std::string>();
432432
try {
433-
boost::regex re(reStr, flags);
433+
const RE re(reStr, flags);
434434
pred = new TPred(re);
435435
}
436436
catch (...) {

src/cshtml.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@
2121
#include "deflookup.hh"
2222
#include "html-writer.hh"
2323
#include "instream.hh"
24+
#include "regex.hh"
2425
#include "version.hh"
2526

2627
#include <boost/program_options.hpp>
27-
#include <boost/regex.hpp>
2828

2929
std::string titleFromFileName(const std::string &fileName)
3030
{
3131
if (!fileName.compare("-"))
3232
return "";
3333

34-
const boost::regex reNoVer("^(.*/)?[^/0-9]*$");
34+
const RE reNoVer("^(.*/)?[^/0-9]*$");
3535
if (boost::regex_match(fileName, reNoVer))
3636
// no version information -> bailing out
3737
return "";
3838

39-
const boost::regex reTitle("^(?:.*/)?([^/]*)\\.(?:err|js)$");
39+
const RE reTitle("^(?:.*/)?([^/]*)\\.(?:err|js)$");
4040

4141
boost::smatch sm;
4242
if (!boost::regex_match(fileName, sm, reTitle))

0 commit comments

Comments
 (0)