Skip to content

Commit

Permalink
cfg parser: stop relying on exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
leonmavr committed Aug 25, 2024
1 parent d0146b9 commit 1069bab
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/cfg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,13 @@ void CfgParser::ParseConfigFile(const std::string& filename) {
std::string line_lower = line;
std::transform(line_lower.begin(), line_lower.end(), line_lower.begin(),
[](char c){ return std::tolower(c); });
if (line_lower == "on")
quirks_ = true;
else if (line_lower == "off")
quirks_ = false;
else {
try {
frequency_ = std::stoi(line);
} catch (const std::invalid_argument& e) {
std::cerr << "Invalid argument: " << e.what() << std::endl;
}
}
bool contains_quirks = line_lower == "on" || line_lower == "off";
bool contains_freq = !line_lower.empty() &&
std::all_of(line_lower.begin(), line_lower.end(), ::isdigit);
quirks_ = (contains_quirks && line_lower == "on") ? true :
(contains_quirks && line_lower == "off") ? false : quirks_;
if (contains_freq)
frequency_ = std::stoi(line);
}
}
file.close();
Expand Down

0 comments on commit 1069bab

Please sign in to comment.