]> Dogcows Code - chaz/vimcoder/commitdiff
separate whitespace handling into its own function
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Mon, 20 Aug 2012 23:25:04 +0000 (17:25 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Mon, 20 Aug 2012 23:25:04 +0000 (17:25 -0600)
src/com/dogcows/resources/C++Driver

index 89e00f0678349fa54f17d27c59bd8fef604cebf6..24ab333609ffa5ed8a51c9c80f0b32943fe2fb19 100644 (file)
@@ -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<T>& 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 <class T>
 std::istream& operator >> (std::istream& in, std::vector<T>& 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 <class T>
 bool __equals(const T& actual, const T& expected)
 {
This page took 0.031112 seconds and 4 git commands to generate.