Skip to content

Commit

Permalink
feat(ConfigParser):
Browse files Browse the repository at this point in the history
- readFile reads json file and removes spaces, tabs, newlines, carriage
returns
- parseJSON prints text from json file
  • Loading branch information
Taanviir committed Jan 24, 2024
1 parent c029264 commit 407b360
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions parser/ConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@ ConfigParser::ConfigParser() {}

ConfigParser::~ConfigParser() {}

void ConfigParser::parseJSON(std::string file) {
std::cout << "Parsing config file: " << file << std::endl;
void ConfigParser::readFile(const std::string& filepath, std::string& output) {
std::cout << "Reading config file: " << filepath << std::endl;

std::ifstream inputFileStream(file.c_str());
std::ifstream inputFileStream(filepath.c_str());
if (inputFileStream.fail()) {
std::cerr << ERR_OPEN << std::endl;
exit(1);
}
std::string line;
while (std::getline(inputFileStream, line)) {
std::cout << line << std::endl;
line.erase(remove_if(line.begin(), line.end(), isspace), line.end());
if (line.empty())
continue;
output.append(line);
}
inputFileStream.close();
}

void ConfigParser::parseJSON(const std::string file) {
std::string json;
readFile(file, json);
std::cout << json;
}
1 change: 1 addition & 0 deletions parser/ConfigParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ConfigParser {

private:
ConfigParser();
static void readFile(const std::string& filepath, std::string& output);
};

#endif // CONFIG_PARSER_HPP

0 comments on commit 407b360

Please sign in to comment.