time_stamp_t time_stamp_t::from_str(const str &s) { size_t space_at; for (space_at = 0; space_at < s.length(); space_at++) { if (s[space_at] == ' ') break; } if (space_at == s.length() - 1) { throw std::invalid_argument("Malformed time stamp: " + s + "."); } str d = s.substr(0, space_at); str t = s.substr(space_at + 1, s.length() - space_at - 1); return time_stamp_t(date_t::from_str(d), time_t::from_str(t)); }
str get_filename_from_pathname(const str& pathname) { auto pos = pathname.find_last_of('/'); if(pos == pathname.size() - 1) throw std::runtime_error("bad pathname: " + pathname); else if(pos != str::npos) return pathname.substr(pos + 1); return pathname; }
std::vector<str> load_lines(const str& s) { std::vector<str> result; size_t curr = 0; for(size_t i = 0; i < s.length(); i++) { if (s[i] == '\n') { result.push_back( s.substr(curr, i) ); curr = i; } } return result; }
str::size_type extract_delimited_text(const str& in, const str& d1, const str& d2, str& out, size_t pos) { if(pos == str::npos) return pos; size_t end = pos; if((pos = in.find(d1, pos)) != str::npos) if((end = in.find(d2, (pos = pos + d1.size()))) != str::npos) { out = in.substr(pos, end - pos); return end + d2.size(); } return str::npos; }
void property_value(const str& value) { current_.add_prop( propname_, value.substr(1, value.size() - 2) ); }