Skip to content

Commit

Permalink
Ignored empty strings, removed useless includes, added useful ones, t…
Browse files Browse the repository at this point in the history
…ypo and conventions update
  • Loading branch information
clement authored and Teskann committed Apr 5, 2023
1 parent ba7b833 commit 3d0f24d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <iostream>

int main() {
for (auto const &ns : blns::Blns::getStrings())
for (const auto& ns : blns::Blns::getStrings())
{
std::cout << ns << std::endl;
}
Expand Down
11 changes: 5 additions & 6 deletions include/blns/blns.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
*
* @author Elia Bieri <[email protected]>
*/
#include <fstream>
#include <iterator>

#include <vector>
#include <filesystem>
#include <string>

namespace blns
{
Expand All @@ -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<std::string> const &getStrings() ;
[[nodiscard]] static const std::vector<std::string>& getStrings() ;

private:
inline static std::vector<std::string> blns;
inline static std::vector<std::string> s_blns;

static void readFile();
};
Expand Down
16 changes: 9 additions & 7 deletions src/blns/blns.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#include <blns/blns.h>
#include <cassert>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <filesystem>

std::vector<std::string> const &blns::Blns::getStrings() {
if(blns.empty()) {
const std::vector<std::string>& blns::Blns::getStrings() {
if(s_blns.empty()) {
readFile();
}
return blns;
return s_blns;
}

void blns::Blns::readFile() {
Expand All @@ -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());
}

0 comments on commit 3d0f24d

Please sign in to comment.