#include "Util.h" #include "FormatError.h" #include #include #include using err::FormatError; namespace util { string Util::read_string_between_percent(istream& is) { char c; string s = ""; bool read = false; for(int i = 0; i < 2; ++i) { while (true) { is >> c; if (!is) throw FormatError("Could not read char!"); if (c == '%') { read = !read; break; } if (!read) continue; s += c; } } return s; } vector Util::read_numbers(istream &is) { int i; string until_eol; getline(is, until_eol); vector numbers_as_string = Util::split(until_eol); vector nums; try { for(string s : numbers_as_string) nums.push_back(stoi(s)); } catch (exception& _) { throw FormatError("Could not convert string to int"); } return nums; } vector Util::split(const string& s) { vector strs; string result = ""; for(char c : s) { if (c == ' ') { if (result != "") { strs.push_back(result); result = ""; } break; } result += c; } return strs; } }