Skip to content

Commit 5e3d72f

Browse files
committed
separate whitespace handling into its own function
1 parent fabb7e8 commit 5e3d72f

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/com/dogcows/resources/C++Driver

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static void __timer_start()
2222
struct timeval tv;
2323
if (gettimeofday(&tv, NULL) == 0)
2424
{
25-
__time = (double)tv.tv_sec + (double)tv.tv_usec * 0.000001;
25+
__time = double(tv.tv_sec) + double(tv.tv_usec) * 0.000001;
2626
}
2727
}
2828

@@ -34,6 +34,12 @@ static double __timer_stop()
3434
}
3535

3636

37+
static void __eat_whitespace(std::istream& in)
38+
{
39+
while (in.good() && std::isspace(in.peek())) in.get();
40+
}
41+
42+
3743
std::ostream& operator << (std::ostream& out, const std::string& str)
3844
{
3945
out << '"' << str.c_str() << '"';
@@ -55,7 +61,7 @@ std::ostream& operator << (std::ostream& out, const std::vector<T>& vec)
5561

5662
std::istream& operator >> (std::istream& in, std::string& str)
5763
{
58-
while (in.good() && std::isspace(in.peek())) in.get();
64+
__eat_whitespace(in);
5965

6066
int c;
6167
if (in.good() && (c = in.get()) == '"')
@@ -74,26 +80,29 @@ std::istream& operator >> (std::istream& in, std::string& str)
7480
template <class T>
7581
std::istream& operator >> (std::istream& in, std::vector<T>& vec)
7682
{
77-
while (in.good() && std::isspace(in.peek())) in.get();
83+
__eat_whitespace(in);
7884

7985
int c;
8086
if (in.good() && (c = in.get()) == '{')
8187
{
82-
while (in.good() && std::isspace(in.peek())) in.get();
83-
T t;
88+
__eat_whitespace(in);
8489
vec.clear();
8590
while (in.good() && (c = in.get()) != '}')
8691
{
8792
if (c != ',') in.putback(c);
93+
94+
T t;
8895
in >> t;
96+
__eat_whitespace(in);
97+
8998
vec.push_back(t);
90-
while (in.good() && std::isspace(in.peek())) in.get();
9199
}
92100
}
93101

94102
return in;
95103
}
96104

105+
97106
template <class T>
98107
bool __equals(const T& actual, const T& expected)
99108
{

0 commit comments

Comments
 (0)