36 if (is.peek() != comment_char)
40 is.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
47 if (!line.empty() && *line.rbegin() ==
'\r')
49 line.resize(line.size()-1);
72 char delim =
'"',
char escape =
'\\')
74 using tt = std::string::traits_type;
75 auto equal = [](tt::int_type c1, tt::char_type c2) ->
bool
77 return tt::eq_int_type(c1, tt::to_int_type(c2));
80 if (!equal(in.peek(), delim)) {
return 1; }
82 for (
auto c = in.get(); !equal(c, delim); c = in.get())
87 if (!equal(c, escape) && !equal(c, delim)) { result += escape; }
89 if (!in) {
return 2; }
90 result += tt::to_char_type(c);
98 std::ostringstream oss;
99 oss << std::setw(digits) << std::setfill(
'0') << i;
107 std::stringstream(str) >> i;
std::string to_padded_string(int i, int digits)
Convert an integer to a 0-padded string with the given number of digits.
int parse_quoted_string(std::string &result, std::istream &in, char delim='"', char escape = '\\')
Read a string formatted using std::quoted. Return nonzero on error.
void filter_dos(std::string &line)
Check for, and remove, a trailing '\r' from and std::string.
int to_int(const std::string &str)
Convert a string to an int.
void skip_comment_lines(std::istream &is, const char comment_char)
Check if the stream starts with comment_char. If so skip it.