Exemplo n.º 1
0
MwIniImporter::multistrmap MwIniImporter::loadCfgFile(const std::string& filename) {
    std::cout << "load cfg file: " << filename << std::endl;

    MwIniImporter::multistrmap map;
    bfs::ifstream file((bfs::path(filename)));

    std::string line;
    while (std::getline(file, line)) {

        // we cant say comment by only looking at first char anymore
        int comment_pos = line.find("#");
        if(comment_pos > 0) {
            line = line.substr(0,comment_pos);
        }

        if(line.empty()) {
            continue;
        }

        int pos = line.find("=");
        if(pos < 1) {
            continue;
        }

        std::string key(line.substr(0,pos));
        std::string value(line.substr(pos+1));

        if(map.find(key) == map.end()) {
            map.insert( std::make_pair (key, std::vector<std::string>() ) );
        }
        map[key].push_back(value);
    }

    return map;
}
Exemplo n.º 2
0
MwIniImporter::multistrmap MwIniImporter::loadIniFile(const std::string& filename) const {
    std::cout << "load ini file: " << filename << std::endl;

    std::string section("");
    MwIniImporter::multistrmap map;
    bfs::ifstream file((bfs::path(filename)));
    ToUTF8::Utf8Encoder encoder(mEncoding);

    std::string line;
    while (std::getline(file, line)) {

        line = encoder.getUtf8(line);

        // unify Unix-style and Windows file ending
        if (!(line.empty()) && (line[line.length()-1]) == '\r') {
            line = line.substr(0, line.length()-1);
        }

        if(line.empty()) {
            continue;
        }

        if(line[0] == '[') {
            int pos = line.find(']');
            if(pos < 2) {
                std::cout << "Warning: ini file wrongly formatted (" << line << "). Line ignored." << std::endl;
                continue;
            }

            section = line.substr(1, line.find(']')-1);
            continue;
        }

        int comment_pos = line.find(";");
        if(comment_pos > 0) {
            line = line.substr(0,comment_pos);
        }

        int pos = line.find("=");
        if(pos < 1) {
            continue;
        }

        std::string key(section + ":" + line.substr(0,pos));
        std::string value(line.substr(pos+1));
        if(value.empty()) {
            std::cout << "Warning: ignored empty value for key '" << key << "'." << std::endl;
            continue;
        }

        if(map.find(key) == map.end()) {
            map.insert( std::make_pair (key, std::vector<std::string>() ) );
        }
        map[key].push_back(value);
    }

    return map;
}
Exemplo n.º 3
0
MwIniImporter::multistrmap MwIniImporter::loadIniFile(std::string filename) {
    std::cout << "load ini file: " << filename << std::endl;

    std::string section("");
    MwIniImporter::multistrmap map;
    boost::iostreams::stream<boost::iostreams::file_source>file(filename.c_str());

    std::string line;
    while (std::getline(file, line)) {

        line = toUTF8(line);

        // unify Unix-style and Windows file ending
        if (!(line.empty()) && (line[line.length()-1]) == '\r') {
            line = line.substr(0, line.length()-1);
        }

        if(line[0] == '[') {
            int pos = line.find(']');
            if(pos < 2) {
                std::cout << "Warning: ini file wrongly formatted (" << line << "). Line ignored." << std::endl;
                continue;
            }

            section = line.substr(1, line.find(']')-1);
            continue;
        }

        int comment_pos = line.find(";");
        if(comment_pos > 0) {
            line = line.substr(0,comment_pos);
        }

        if(line.empty()) {
            continue;
        }

        int pos = line.find("=");
        if(pos < 1) {
            continue;
        }

        std::string key(section + ":" + line.substr(0,pos));
        std::string value(line.substr(pos+1));

        multistrmap::iterator it;
        if((it = map.find(key)) == map.end()) {
            map.insert( std::make_pair (key, std::vector<std::string>() ) );
        }
        map[key].push_back(value);
    }

    return map;
}
Exemplo n.º 4
0
MwIniImporter::multistrmap MwIniImporter::loadIniFile(std::string filename) {
    std::cout << "load ini file: " << filename << std::endl;

    std::string section("");
    MwIniImporter::multistrmap map;
    boost::iostreams::stream<boost::iostreams::file_source>file(filename.c_str());

    std::string line;
    while (std::getline(file, line)) {

        if(line[0] == '[') {
            if(line.length() > 2) {
                section = line.substr(1, line.length()-3);
            }
            continue;
        }

        int comment_pos = line.find(";");
        if(comment_pos > 0) {
            line = line.substr(0,comment_pos);
        }

        if(line.empty()) {
            continue;
        }

        int pos = line.find("=");
        if(pos < 1) {
            continue;
        }

        std::string key(section + ":" + line.substr(0,pos));
        std::string value(line.substr(pos+1));

        multistrmap::iterator it;
        if((it = map.find(key)) == map.end()) {
            map.insert( std::make_pair<std::string, std::vector<std::string> > (key, std::vector<std::string>() ) );
        }
        map[key].push_back(value);
    }

    return map;
}
Exemplo n.º 5
0
MwIniImporter::multistrmap MwIniImporter::loadCfgFile(std::string filename) {
    std::cout << "load cfg file: " << filename << std::endl;

    MwIniImporter::multistrmap map;
    boost::iostreams::stream<boost::iostreams::file_source>file(filename.c_str());

    std::string line;
    while (std::getline(file, line)) {

        // we cant say comment by only looking at first char anymore
        int comment_pos = line.find("#");
        if(comment_pos > 0) {
            line = line.substr(0,comment_pos);
        }

        if(line.empty()) {
            continue;
        }

        int pos = line.find("=");
        if(pos < 1) {
            continue;
        }

        std::string key(line.substr(0,pos));
        std::string value(line.substr(pos+1));

        multistrmap::iterator it;
        if((it = map.find(key)) == map.end()) {
            map.insert( std::make_pair<std::string, std::vector<std::string> > (key, std::vector<std::string>() ) );
        }
        map[key].push_back(value);
    }

    return map;
}