blob: fe2dc6f624f4baccefcd23dcb8c70b4bc6ee3ab9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "line_reader.h"
namespace vbench {
namespace {
void stripCR(string &dst) {
if (!dst.empty() && dst[dst.size() - 1] == '\r') {
dst.resize(dst.size() - 1);
}
}
} // namespace vbench::<unnamed>
LineReader::LineReader(Input &input)
: _input(input)
{
}
bool
LineReader::readLine(string &dst)
{
dst.clear();
for (char c = _input.read(); !_input.failed(); c = _input.read()) {
if (c != '\n') {
dst.push_back(c);
} else {
stripCR(dst);
return true;
}
}
return !dst.empty();
}
} // namespace vbench
|