Skip to content

Added error messages #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 9, 2021
Merged

Added error messages #3

merged 2 commits into from
Jul 9, 2021

Conversation

NikolaJelic
Copy link
Collaborator

Added:

  • optional error messages which the user can turn on or off
  • excessive white space trimming
  • lines starting with # which can be considered comments are ignored
  • lines with empty keys are ignored

@NikolaJelic NikolaJelic self-assigned this Jul 8, 2021
@hentai-chan
Copy link

I'll submit my review tomorrow, there are a few edge cases that I want to test

@@ -65,7 +81,20 @@ std::int32_t pini::get_int32(std::string const& key, std::uint32_t def) const {

std::string_view pini::get_string(std::string const& key) const {
auto it = key_value_pairs.find(key);
if (it == key_value_pairs.end()) { return {}; }
if (it == key_value_pairs.end()) {
if (pn::pini::on_msg_t) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you ok with repeating this pattern every time you need to log stuff? There are ways to make it more succinct.

}
return ret;
}

std::unordered_map<std::string, std::string> insert_pairs(std::vector<std::string> file_lines) {
std::unordered_map<std::string, std::string> key_value_pairs;

std::size_t line_number = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, you used size_t and not int

// std::filesystem::path filename{"/test/test.ini"};
if (!pin.load_text(raw_input)) { return 1; }
if (pin.get_int32("a") != 5) { return 1; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with this line?

if (pin.get_int32("a") != 5) { return 1; }
std::cout << pin.get_int32("a");
std::cout << pin.get_int32("b");
std::cout << pin.get_int32("c");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put some more failure cases instead of just printing stuff: you won't see these logs via ctest / through CI etc.

@NikolaJelic NikolaJelic requested a review from karnkaul July 9, 2021 15:07
@NikolaJelic NikolaJelic merged commit fea7b87 into main Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants