#include "freevars.h" #include #include freevars::freevars() { vars = new std::map* >(); } void freevars::addVar(std::string name, std::string filename) { std::vector* eltlist = new std::vector(); std::ifstream infile(filename.c_str()); if (infile) { std::string line; while (getline(infile, line)) { eltlist->push_back(line); } } else { eltlist->push_back(""); } (*vars)[name] = eltlist; } std::string freevars::parse(std::string in) { std::string res(in); for (std::map* >::iterator it = vars->begin(); it != vars->end(); it++) { std::string tofind = "$" + it->first + "$"; size_t fpos = res.find(tofind); if (fpos != std::string::npos) { int r = rand() % it->second->size(); res.replace(fpos, tofind.length(), (*it->second)[r], 0, std::string::npos); } } return res; }