Unverified Commit 797ba373 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

simplify reading key/value pairs from string

parent 08ee1cb4
Loading
Loading
Loading
Loading
+9 −18
Original line number Diff line number Diff line
@@ -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));
    }
}