[clang-tidy] Fix treating non-space whitespaces in checks list.

Summary:
This furtherly improves r295303: [clang-tidy] Ignore spaces between globs in the Checks option.
Trims all whitespaces and not only spaces and correctly computes the offset of the checks list (taking the size before trimming).

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: cfe-commits, JDevlieghere

Differential Revision: https://reviews.llvm.org/D30567

llvm-svn: 298621
This commit is contained in:
Marek Kurdej 2017-03-23 16:32:06 +00:00
parent 4e7b71bc86
commit 92ecb51fae
2 changed files with 713 additions and 705 deletions

View File

@ -129,8 +129,9 @@ static bool ConsumeNegativeIndicator(StringRef &GlobList) {
// Converts first glob from the comma-separated list of globs to Regex and // Converts first glob from the comma-separated list of globs to Regex and
// removes it and the trailing comma from the GlobList. // removes it and the trailing comma from the GlobList.
static llvm::Regex ConsumeGlob(StringRef &GlobList) { static llvm::Regex ConsumeGlob(StringRef &GlobList) {
StringRef Glob = GlobList.substr(0, GlobList.find(',')).trim(); StringRef UntrimmedGlob = GlobList.substr(0, GlobList.find(','));
GlobList = GlobList.substr(Glob.size() + 1); StringRef Glob = UntrimmedGlob.trim(' ');
GlobList = GlobList.substr(UntrimmedGlob.size() + 1);
SmallString<128> RegexText("^"); SmallString<128> RegexText("^");
StringRef MetaChars("()^$|*+?.[]\\{}"); StringRef MetaChars("()^$|*+?.[]\\{}");
for (char C : Glob) { for (char C : Glob) {

View File

@ -66,6 +66,13 @@ TEST(GlobList, Simple) {
EXPECT_FALSE(Filter.contains("bbb")); EXPECT_FALSE(Filter.contains("bbb"));
} }
TEST(GlobList, WhitespacesAtBegin) {
GlobList Filter("-*, a.b.*");
EXPECT_TRUE(Filter.contains("a.b.c"));
EXPECT_FALSE(Filter.contains("b.c"));
}
TEST(GlobList, Complex) { TEST(GlobList, Complex) {
GlobList Filter("*,-a.*, -b.*, a.1.* ,-a.1.A.*,-..,-...,-..+,-*$, -*qwe* "); GlobList Filter("*,-a.*, -b.*, a.1.* ,-a.1.A.*,-..,-...,-..+,-*$, -*qwe* ");