diff --git a/examples/example.cpp b/examples/example.cpp index 054bcba..2c29cf2 100644 --- a/examples/example.cpp +++ b/examples/example.cpp @@ -2,7 +2,7 @@ #include int main() { - for (auto const &ns : blns::Blns::getStrings()) + for (const auto& ns : blns::Blns::getStrings()) { std::cout << ns << std::endl; } diff --git a/include/blns/blns.h b/include/blns/blns.h index 20454af..949fcb4 100644 --- a/include/blns/blns.h +++ b/include/blns/blns.h @@ -4,10 +4,9 @@ * * @author Elia Bieri */ -#include -#include + #include -#include +#include namespace blns { @@ -18,12 +17,12 @@ class Blns /* * Returns the list of Naughty Strings - * @return list of naugthy strings + * @return list of naughty strings */ - [[nodiscard]] static std::vector const &getStrings() ; + [[nodiscard]] static const std::vector& getStrings() ; private: - inline static std::vector blns; + inline static std::vector s_blns; static void readFile(); }; diff --git a/src/blns/blns.cpp b/src/blns/blns.cpp index 92d597d..c16c212 100644 --- a/src/blns/blns.cpp +++ b/src/blns/blns.cpp @@ -1,13 +1,15 @@ #include #include -#include #include +#include +#include +#include -std::vector const &blns::Blns::getStrings() { - if(blns.empty()) { +const std::vector& blns::Blns::getStrings() { + if(s_blns.empty()) { readFile(); } - return blns; + return s_blns; } void blns::Blns::readFile() { @@ -21,9 +23,9 @@ void blns::Blns::readFile() { std::string line; while(getline(blnsFile, line)) { // Skip comments in txt file - if(line.rfind('#', 0) != 0) { - blns.push_back(line); + if(!line.empty() && line.rfind('#', 0) != 0) { + s_blns.push_back(line); } } - assert(!blns.empty()); + assert(!s_blns.empty()); }