-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Modularize the src and change the name of the function as it will load more variables from the config file
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "config_utils.hpp" | ||
#include <iostream> | ||
#include <fstream> | ||
|
||
std::string ConfigLoad(const std::string& filename) { | ||
std::ifstream configFile(filename); | ||
if (!configFile) { | ||
std::cerr << "Error opening the config file: " << filename << std::endl; | ||
return ""; | ||
} | ||
|
||
std::string line; | ||
while (std::getline(configFile, line)) { | ||
if (line.empty() || line[0] == '#') continue; | ||
|
||
auto pos = line.find('='); | ||
if (pos != std::string::npos) { | ||
std::string key = line.substr(0, pos); | ||
std::string value = line.substr(pos + 1); | ||
key.erase(0, key.find_first_not_of(" \t")); | ||
key.erase(key.find_last_not_of(" \t") + 1); | ||
value.erase(0, value.find_first_not_of(" \t")); | ||
value.erase(value.find_last_not_of(" \t") + 1); | ||
if (key == "languageCode") { | ||
return value; | ||
} | ||
} | ||
} | ||
std::cerr << "Error: 'languageCode' not found in the config file" << std::endl; | ||
return "en"; // Default language | ||
} |