From 5e3d72f23da7634e1b87d005333eb7708ea78e4d Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Mon, 20 Aug 2012 17:25:04 -0600 Subject: [PATCH] separate whitespace handling into its own function --- src/com/dogcows/resources/C++Driver | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/com/dogcows/resources/C++Driver b/src/com/dogcows/resources/C++Driver index 89e00f0..24ab333 100644 --- a/src/com/dogcows/resources/C++Driver +++ b/src/com/dogcows/resources/C++Driver @@ -22,7 +22,7 @@ static void __timer_start() struct timeval tv; if (gettimeofday(&tv, NULL) == 0) { - __time = (double)tv.tv_sec + (double)tv.tv_usec * 0.000001; + __time = double(tv.tv_sec) + double(tv.tv_usec) * 0.000001; } } @@ -34,6 +34,12 @@ static double __timer_stop() } +static void __eat_whitespace(std::istream& in) +{ + while (in.good() && std::isspace(in.peek())) in.get(); +} + + std::ostream& operator << (std::ostream& out, const std::string& str) { out << '"' << str.c_str() << '"'; @@ -55,7 +61,7 @@ std::ostream& operator << (std::ostream& out, const std::vector& vec) std::istream& operator >> (std::istream& in, std::string& str) { - while (in.good() && std::isspace(in.peek())) in.get(); + __eat_whitespace(in); int c; if (in.good() && (c = in.get()) == '"') @@ -74,26 +80,29 @@ std::istream& operator >> (std::istream& in, std::string& str) template std::istream& operator >> (std::istream& in, std::vector& vec) { - while (in.good() && std::isspace(in.peek())) in.get(); + __eat_whitespace(in); int c; if (in.good() && (c = in.get()) == '{') { - while (in.good() && std::isspace(in.peek())) in.get(); - T t; + __eat_whitespace(in); vec.clear(); while (in.good() && (c = in.get()) != '}') { if (c != ',') in.putback(c); + + T t; in >> t; + __eat_whitespace(in); + vec.push_back(t); - while (in.good() && std::isspace(in.peek())) in.get(); } } return in; } + template bool __equals(const T& actual, const T& expected) { -- 2.43.0