mayah / tinytoml

A header only C++11 library for parsing TOML
BSD 2-Clause "Simplified" License
167 stars 31 forks source link

Check state of input stream before parsing #32

Open DoumanAsh opened 6 years ago

DoumanAsh commented 6 years ago

Currently passing failed/bad stream results in successful parsing(which actually parses nothing at all).

Simple case would be pass ifstream to non-existing fail

std::ifstream ifs("foo.toml");
toml::ParseResult pr = toml::parse(ifs);

if (!pr.valid()) {
    cout << pr.errorReason << endl;
    return;
}

It is a bit tricky as it should be up to user to provide a valid output. But on other hand there is no way it would be possible parse failed/bad stream.

What do you think? Should there be error on such cases?

mayah commented 6 years ago

@DoumanAsh Thanks for reporting... Yeah, I think it's not good. It should be an error. I'll fix it.