bool ImposterInfo::save(const std::string &path) { std::string s1, s2; str_vec strs1, strs2; std::fstream fs(path.c_str(), std::fstream::out); if (fs.fail()) { return false; } strs1.resize(mRows.size()); projVec(strs1, mRows, row_name); joinStr(s1, ',', strs1); fs << s1 << std::endl; projVec(strs1, mRows, row_cv); joinStr(s1, ',', strs1); fs << s1 << std::endl; for (unsigned i = 0; i < mCount; ++i) { strs1.clear(); if (mRows[i].canVerify) { for (unsigned j = 0; j < mCount; ++j) { Item &ent = item(i, j); std::stringstream ss; ss << ent.score << '/' << ent.chosen; ss >> s2; strs1.push_back(s2); } } else { strs1.assign(mCount, "X"); } joinStr(s1, ',', strs1); fs << s1 << std::endl; }
std::string safePath(const std::string &unsafe) { std::vector<std::string> walking; for (auto path : splitStr(unsafe, "/")) { if (path == ".") // current directory continue; // skip it if (path == "..") // parent directory walking.pop_back(); else walking.push_back(path); } if (walking.size() == 1) return std::string("/"); return joinStr(walking, "/"); }
inline string joinStr(const vector<string>& source, const string& connector) { string res; joinStr(source, res, connector); return res; }