simplify reading key/value pairs from string

This commit is contained in:
Axel Kohlmeyer
2020-05-28 22:38:23 -04:00
parent 08ee1cb4fa
commit 797ba373c4

View File

@ -60,19 +60,11 @@ TestConfigReader::TestConfigReader(TestConfig & config)
void TestConfigReader::prerequisites(const yaml_event_t & event) {
config.prerequisites.clear();
std::stringstream data((char *)event.data.scalar.value);
std::string line;
std::string key, value;
while(std::getline(data, line, '\n')) {
std::size_t found = line.find_first_of(" \t");
std::string key = line.substr(0,found);
found = line.find_first_not_of(" \t",found);
// skip invalid data
if (found == std::string::npos) {
std::cerr << "Skipping invalid prerequisite line:\n"
<< line << std::endl;
continue;
}
std::string value = line.substr(found,line.find_first_of(" \t",found));
while(1) {
data >> key >> value;
if (data.eof()) break;
config.prerequisites.push_back(std::make_pair(key,value));
}
}
@ -116,12 +108,11 @@ void TestConfigReader::input_file(const yaml_event_t & event) {
void TestConfigReader::extract(const yaml_event_t & event) {
config.extract.clear();
std::stringstream data((char *)event.data.scalar.value);
std::string line;
while (std::getline(data, line, '\n')) {
std::size_t found = line.find_first_of(" \t");
std::string name = line.substr(0,found);
int value = atoi(line.substr(found).c_str());
std::string name;
int value;
while(1) {
data >> name >> value;
if (data.eof()) break;
config.extract.push_back(make_pair(name, value));
}
}