Improved JSON config error reporting

Show incorrect lines in config.json together with line number and position.
This commit is contained in:
SChernykh 2020-04-29 11:08:45 +02:00
parent b38046db46
commit 05d3f17f15
5 changed files with 99 additions and 1 deletions

View file

@ -191,6 +191,37 @@ rapidjson::Value xmrig::Json::normalize(double value, bool zero)
}
bool xmrig::Json::convertOffset(std::ifstream& ifs, size_t offset, size_t& line, size_t& pos, std::vector<std::string>& s)
{
std::string prev_t;
std::string t;
line = 0;
pos = 0;
size_t k = 0;
while (!ifs.eof()) {
prev_t = t;
std::getline(ifs, t);
k += t.length() + 1;
++line;
if (k > offset) {
pos = offset + t.length() + 1 - k + 1;
s.clear();
if (!prev_t.empty()) {
s.emplace_back(prev_t);
}
s.emplace_back(t);
return true;
}
}
return false;
}
bool xmrig::JsonReader::isEmpty() const
{
return Json::isEmpty(m_obj);