Skip to content

Commit b17a347

Browse files
authored
Path: removed deprecated functions / renamed isHeader2() to isHeader() (#6427)
1 parent ab69847 commit b17a347

6 files changed

Lines changed: 18 additions & 153 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
184184
// Output a warning for the user if he tries to exclude headers
185185
const std::vector<std::string>& ignored = getIgnoredPaths();
186186
const bool warn = std::any_of(ignored.cbegin(), ignored.cend(), [](const std::string& i) {
187-
return Path::isHeader2(i);
187+
return Path::isHeader(i);
188188
});
189189
if (warn) {
190190
mLogger.printMessage("filename exclusion does not apply to header (.h and .hpp) files.");

gui/resultstree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ void ResultsTree::recheckSelectedFiles()
964964
askFileDir(currentFile);
965965
return;
966966
}
967-
if (Path::isHeader2(currentFile.toStdString())) {
967+
if (Path::isHeader(currentFile.toStdString())) {
968968
if (!data[FILE0].toString().isEmpty() && !selectedItems.contains(data[FILE0].toString())) {
969969
selectedItems<<((!mCheckPath.isEmpty() && (data[FILE0].toString().indexOf(mCheckPath) != 0)) ? (mCheckPath + "/" + data[FILE0].toString()) : data[FILE0].toString());
970970
if (!selectedItems.contains(fileNameWithCheckPath))

gui/resultsview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ void ResultsView::updateDetails(const QModelIndex &index)
462462
QString formattedMsg = message;
463463

464464
const QString file0 = data["file0"].toString();
465-
if (!file0.isEmpty() && Path::isHeader2(data["file"].toString().toStdString()))
465+
if (!file0.isEmpty() && Path::isHeader(data["file"].toString().toStdString()))
466466
formattedMsg += QString("\n\n%1: %2").arg(tr("First included by")).arg(QDir::toNativeSeparators(file0));
467467

468468
if (data["cwe"].toInt() > 0)

lib/path.cpp

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -207,44 +207,12 @@ static const std::unordered_set<std::string> header_exts = {
207207
".h", ".hpp", ".h++", ".hxx", ".hh"
208208
};
209209

210-
bool Path::isC(const std::string &path)
211-
{
212-
// In unix, ".C" is considered C++ file
213-
const std::string extension = getFilenameExtension(path);
214-
return extension == ".c" ||
215-
extension == ".cl";
216-
}
217-
218-
bool Path::isCPP(const std::string &path)
219-
{
220-
const std::string extension = getFilenameExtensionInLowerCase(path);
221-
return extension == ".cpp" ||
222-
extension == ".cxx" ||
223-
extension == ".cc" ||
224-
extension == ".c++" ||
225-
extension == ".hpp" ||
226-
extension == ".hxx" ||
227-
extension == ".hh" ||
228-
extension == ".tpp" ||
229-
extension == ".txx" ||
230-
extension == ".ipp" ||
231-
extension == ".ixx" ||
232-
getFilenameExtension(path) == ".C"; // In unix, ".C" is considered C++ file
233-
}
234-
235210
bool Path::acceptFile(const std::string &path, const std::set<std::string> &extra)
236211
{
237212
bool header = false;
238213
return (identify(path, &header) != Standards::Language::None && !header) || extra.find(getFilenameExtension(path)) != extra.end();
239214
}
240215

241-
// cppcheck-suppress unusedFunction
242-
bool Path::isHeader(const std::string &path)
243-
{
244-
const std::string extension = getFilenameExtensionInLowerCase(path);
245-
return startsWith(extension, ".h");
246-
}
247-
248216
Standards::Language Path::identify(const std::string &path, bool *header)
249217
{
250218
// cppcheck-suppress uninitvar - TODO: FP
@@ -274,7 +242,7 @@ Standards::Language Path::identify(const std::string &path, bool *header)
274242
return Standards::Language::None;
275243
}
276244

277-
bool Path::isHeader2(const std::string &path)
245+
bool Path::isHeader(const std::string &path)
278246
{
279247
bool header;
280248
(void)Path::identify(path, &header);

lib/path.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -153,36 +153,12 @@ class CPPCHECKLIB Path {
153153
*/
154154
static bool acceptFile(const std::string &path, const std::set<std::string> &extra);
155155

156-
/**
157-
* @brief Identify language based on file extension.
158-
* @param path filename to check. path info is optional
159-
* @return true if extension is meant for C files
160-
* @deprecated does not account for headers - use @identify() instead
161-
*/
162-
static DEPRECATED bool isC(const std::string &path);
163-
164-
/**
165-
* @brief Identify language based on file extension.
166-
* @param path filename to check. path info is optional
167-
* @return true if extension is meant for C++ files
168-
* @deprecated returns true for some header extensions - use @identify() instead
169-
*/
170-
static DEPRECATED bool isCPP(const std::string &path);
171-
172-
/**
173-
* @brief Is filename a header based on file extension
174-
* @param path filename to check. path info is optional
175-
* @return true if filename extension is meant for headers
176-
* @deprecated returns only heuristic result - use @identify() or @isHeader2() instead
177-
*/
178-
static DEPRECATED bool isHeader(const std::string &path);
179-
180156
/**
181157
* @brief Is filename a header based on file extension
182158
* @param path filename to check. path info is optional
183159
* @return true if filename extension is meant for headers
184160
*/
185-
static bool isHeader2(const std::string &path);
161+
static bool isHeader(const std::string &path);
186162

187163
/**
188164
* @brief Identify the language based on the file extension

test/testpath.cpp

Lines changed: 13 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,14 @@ class TestPath : public TestFixture {
3838
TEST_CASE(getCurrentExecutablePath);
3939
TEST_CASE(isAbsolute);
4040
TEST_CASE(getRelative);
41-
TEST_CASE(is_c);
42-
TEST_CASE(is_cpp);
43-
TEST_CASE(is_header);
4441
TEST_CASE(get_path_from_filename);
4542
TEST_CASE(join);
4643
TEST_CASE(isDirectory);
4744
TEST_CASE(isFile);
4845
TEST_CASE(sameFileName);
4946
TEST_CASE(getFilenameExtension);
5047
TEST_CASE(identify);
51-
TEST_CASE(is_header_2);
48+
TEST_CASE(is_header);
5249
}
5350

5451
void removeQuotationMarks() const {
@@ -131,82 +128,6 @@ class TestPath : public TestFixture {
131128
ASSERT_EQUALS("C:/foobar/test.cpp", Path::getRelativePath("C:/foobar/test.cpp", basePaths));
132129
}
133130

134-
#ifdef __clang__
135-
#pragma clang diagnostic push
136-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
137-
#endif
138-
139-
void is_c() const {
140-
ASSERT(Path::isC("index.c"));
141-
ASSERT(Path::isC("index.cl"));
142-
ASSERT(Path::isC("C:\\foo\\index.c"));
143-
ASSERT(Path::isC("/mnt/c/foo/index.c"));
144-
145-
// In unix .C is considered C++
146-
#if defined(_WIN32) || (defined(__APPLE__) && defined(__MACH__))
147-
ASSERT_EQUALS(true, Path::isC("C:\\foo\\index.C"));
148-
#else
149-
ASSERT_EQUALS(false, Path::isC("C:\\foo\\index.C"));
150-
#endif
151-
152-
ASSERT(Path::isC("index.cpp")==false);
153-
ASSERT(Path::isC("")==false);
154-
ASSERT(Path::isC("c")==false);
155-
156-
// unlike isCPP() it does not account for headers
157-
ASSERT(Path::isC(".h")==false);
158-
}
159-
160-
void is_cpp() const {
161-
ASSERT(Path::isCPP("index.cpp"));
162-
ASSERT(Path::isCPP("index.cxx"));
163-
ASSERT(Path::isCPP("index.cc"));
164-
ASSERT(Path::isCPP("index.c++"));
165-
ASSERT(Path::isCPP("index.tpp"));
166-
ASSERT(Path::isCPP("index.txx"));
167-
ASSERT(Path::isCPP("index.ipp"));
168-
ASSERT(Path::isCPP("index.ixx"));
169-
ASSERT(Path::isCPP("C:\\foo\\index.cpp"));
170-
ASSERT(Path::isCPP("C:\\foo\\index.Cpp"));
171-
ASSERT(Path::isCPP("/mnt/c/foo/index.cpp"));
172-
ASSERT(Path::isCPP("/mnt/c/foo/index.Cpp"));
173-
174-
// In unix .C is considered C++
175-
#if defined(_WIN32) || (defined(__APPLE__) && defined(__MACH__))
176-
ASSERT_EQUALS(false, Path::isCPP("index.C"));
177-
#else
178-
ASSERT_EQUALS(true, Path::isCPP("index.C"));
179-
#endif
180-
181-
ASSERT(Path::isCPP("index.c")==false);
182-
183-
// C++ headers are also considered C++
184-
ASSERT(Path::isCPP("index.hpp"));
185-
// .h++ is missing in the list of C++ headers
186-
ASSERT(Path::isCPP("index.h++")==false);
187-
}
188-
189-
void is_header() const {
190-
ASSERT(Path::isHeader("index.h"));
191-
ASSERT(Path::isHeader("index.hpp"));
192-
ASSERT(Path::isHeader("index.hxx"));
193-
ASSERT(Path::isHeader("index.h++"));
194-
ASSERT(Path::isHeader("index.hh"));
195-
196-
ASSERT(Path::isHeader("index.c")==false);
197-
ASSERT(Path::isHeader("index.cpp")==false);
198-
199-
// function uses heuristic approach which causes these false positives
200-
// no need to fix - function is deprecated and was replaced by identify()
201-
TODO_ASSERT(Path::isHeader("index.header")==false);
202-
TODO_ASSERT(Path::isHeader("index.htm")==false);
203-
TODO_ASSERT(Path::isHeader("index.html")==false);
204-
}
205-
206-
#ifdef __clang__
207-
#pragma clang diagnostic pop
208-
#endif
209-
210131
void get_path_from_filename() const {
211132
ASSERT_EQUALS("", Path::getPathFromFilename("index.h"));
212133
ASSERT_EQUALS("/tmp/", Path::getPathFromFilename("/tmp/index.h"));
@@ -368,18 +289,18 @@ class TestPath : public TestFixture {
368289
ASSERT_EQUALS(Standards::Language::None, Path::identify("index.html"));
369290
}
370291

371-
void is_header_2() const {
372-
ASSERT(Path::isHeader2("index.h"));
373-
ASSERT(Path::isHeader2("index.hpp"));
374-
ASSERT(Path::isHeader2("index.hxx"));
375-
ASSERT(Path::isHeader2("index.h++"));
376-
ASSERT(Path::isHeader2("index.hh"));
377-
378-
ASSERT(Path::isHeader2("index.c")==false);
379-
ASSERT(Path::isHeader2("index.cpp")==false);
380-
ASSERT(Path::isHeader2("index.header")==false);
381-
ASSERT(Path::isHeader2("index.htm")==false);
382-
ASSERT(Path::isHeader2("index.html")==false);
292+
void is_header() const {
293+
ASSERT(Path::isHeader("index.h"));
294+
ASSERT(Path::isHeader("index.hpp"));
295+
ASSERT(Path::isHeader("index.hxx"));
296+
ASSERT(Path::isHeader("index.h++"));
297+
ASSERT(Path::isHeader("index.hh"));
298+
299+
ASSERT(Path::isHeader("index.c")==false);
300+
ASSERT(Path::isHeader("index.cpp")==false);
301+
ASSERT(Path::isHeader("index.header")==false);
302+
ASSERT(Path::isHeader("index.htm")==false);
303+
ASSERT(Path::isHeader("index.html")==false);
383304
}
384305
};
385306

0 commit comments

Comments
 (0)