Project: Make checkForLine() a const member function

This only ever queries the existence of a line, so it can be made const.
This commit is contained in:
Lioncash 2020-04-05 09:16:29 -04:00
parent 613b503cd6
commit 393e824838
1 changed files with 4 additions and 5 deletions

View File

@ -1,4 +1,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <algorithm>
#include <cerrno> #include <cerrno>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
@ -105,16 +107,13 @@ void Project::ConfigFile::removeLine(std::string_view refLine) {
} }
} }
bool Project::ConfigFile::checkForLine(std::string_view refLine) { bool Project::ConfigFile::checkForLine(std::string_view refLine) const {
if (!m_lockedFile) { if (!m_lockedFile) {
LogModule.reportSource(logvisor::Fatal, __FILE__, __LINE__, fmt("Project::ConfigFile::lockAndRead not yet called")); LogModule.reportSource(logvisor::Fatal, __FILE__, __LINE__, fmt("Project::ConfigFile::lockAndRead not yet called"));
return false; return false;
} }
for (const std::string& line : m_lines) return std::any_of(m_lines.cbegin(), m_lines.cend(), [&refLine](const auto& line) { return line == refLine; });
if (line == refLine)
return true;
return false;
} }
void Project::ConfigFile::unlockAndDiscard() { void Project::ConfigFile::unlockAndDiscard() {