Skip to content

Commit 8e50d1d

Browse files
committed
Suppression match shortcut
1 parent 2671b60 commit 8e50d1d

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

lib/pathmatch.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
#include <string>
2828
#include <vector>
2929

30-
struct Pathstr {
30+
struct Pathstr
31+
{
3132
static Pathstr from_pattern(const std::string &pattern, const std::string &basepath, bool icase)
3233
{
3334
if (!pattern.empty() && pattern[0] == '.')
@@ -89,7 +90,8 @@ struct Pathstr {
8990
return c;
9091
}
9192

92-
void simplify(bool leadsep) {
93+
void simplify(bool leadsep)
94+
{
9395
while (left() != 0) {
9496
State rst = st;
9597

@@ -161,16 +163,18 @@ struct Pathstr {
161163
}
162164
}
163165

164-
Pathstr &operator++(int) {
166+
void operator++()
167+
{
165168
advance();
166-
return *this;
167169
}
168170

169-
char operator*() const {
171+
char operator*() const
172+
{
170173
return current();
171174
}
172175

173-
struct State {
176+
struct State
177+
{
174178
const char *p;
175179
std::size_t l;
176180
int c {EOF};
@@ -195,6 +199,7 @@ static bool match_one(const std::string &pattern, const std::string &path, const
195199

196200
Pathstr s = Pathstr::from_pattern(pattern, basepath, icase);
197201
Pathstr t = Pathstr::from_path(path, basepath, icase);
202+
198203
Pathstr p = s;
199204
Pathstr q = t;
200205

@@ -204,23 +209,23 @@ static bool match_one(const std::string &pattern, const std::string &path, const
204209
switch (*s) {
205210
case '*': {
206211
bool slash = false;
207-
s++;
212+
++s;
208213
if (*s == '*') {
209214
slash = true;
210-
s++;
215+
++s;
211216
}
212217
b.emplace(s.st, t.st);
213218
while (*t != '\0' && (slash || *t != '/')) {
214219
if (*s == *t)
215220
b.emplace(s.st, t.st);
216-
t++;
221+
++t;
217222
}
218223
continue;
219224
}
220225
case '?': {
221226
if (*t != '\0' && *t != '/') {
222-
s++;
223-
t++;
227+
++s;
228+
++t;
224229
continue;
225230
}
226231
break;
@@ -232,8 +237,8 @@ static bool match_one(const std::string &pattern, const std::string &path, const
232237
}
233238
default: {
234239
if (*s == *t) {
235-
s++;
236-
t++;
240+
++s;
241+
++t;
237242
continue;
238243
}
239244
break;
@@ -249,10 +254,10 @@ static bool match_one(const std::string &pattern, const std::string &path, const
249254
}
250255

251256
while (*q != '\0' && *q != '/')
252-
q++;
257+
++q;
253258

254259
if (*q == '/') {
255-
q++;
260+
++q;
256261
s = p;
257262
t = q;
258263
continue;
@@ -269,10 +274,8 @@ PathMatch::PathMatch(std::vector<std::string> patterns, std::string basepath, Mo
269274

270275
bool PathMatch::match(const std::string &path) const
271276
{
272-
bool icase = (mMode == Mode::icase);
273-
274277
return std::any_of(mPatterns.cbegin(), mPatterns.cend(), [=] (const std::string &pattern) {
275-
return match_one(pattern, path, mBasepath, icase);
278+
return match_one(pattern, path, mBasepath, mMode == Mode::icase);
276279
});
277280
}
278281

lib/suppressions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ SuppressionList::Suppression::Result SuppressionList::Suppression::isSuppressed(
397397
if (!errorId.empty() && !matchglob(errorId, errmsg.errorId))
398398
return Result::Checked;
399399
} else {
400-
if (!fileName.empty() && !PathMatch::match(fileName, errmsg.getFileName(), std::string()))
400+
if (!fileName.empty() && fileName != errmsg.getFileName() && !PathMatch::match(fileName, errmsg.getFileName()))
401401
return Result::None;
402402
if ((SuppressionList::Type::unique == type) && (lineNumber != NO_LINE) && (lineNumber != errmsg.lineNumber)) {
403403
if (!thisAndNextLine || lineNumber + 1 != errmsg.lineNumber)

0 commit comments

Comments
 (0)