namespace { // unnamed namespace
std::string
-createStreamName(std::istream& input_stream) {
+createStreamName(const std::istream& input_stream) {
std::stringstream ss;
ss << "stream-" << &input_stream;
return (ss.str());
return (END_OF_STREAM);
}
// We are not yet at EOF. Read from the stream.
- int c = input_.get();
+ const int c = input_.get();
// Have we reached EOF now? If so, set at_eof_ and return early,
// but don't modify buffer_pos_ (which should still be equal to
// the size of buffer_).
buffer_.push_back(c);
}
- int c = buffer_[buffer_pos_++];
+ const int c = buffer_[buffer_pos_++];
if (c == '\n') {
line_++;
}
// getChar() should return characters from the input stream in
// sequence. ungetChar() should skip backwards.
void
-checkGetAndUngetChar(InputSource& source, const char* str, size_t str_length)
+checkGetAndUngetChar(InputSource& source,
+ const char* str, const size_t str_length)
{
for (size_t i = 0; i < str_length; i++) {
EXPECT_EQ(str[i], source.getChar());
source.ungetChar();
for (size_t i = 0; i < str_length; i++) {
- size_t index = str_length - 1 - i;
+ const size_t index = str_length - 1 - i;
// Skip one character.
source.ungetChar();
EXPECT_EQ(str[index], source.getChar());
TEST_F(InputSourceTest, file) {
std::ifstream fs(TEST_DATA_SRCDIR "/masterload.txt");
- std::string str((std::istreambuf_iterator<char>(fs)),
- std::istreambuf_iterator<char>());
+ const std::string str((std::istreambuf_iterator<char>(fs)),
+ std::istreambuf_iterator<char>());
fs.close();
InputSource source(TEST_DATA_SRCDIR "/masterload.txt");
source_.getChar();
}
EXPECT_FALSE(source_.atEOF());
- size_t line = source_.getCurrentLine();
- EXPECT_EQ(2, line);
+ EXPECT_EQ(2, source_.getCurrentLine());
// Now, unget a couple of characters. This should cause the
// buffer_pos_ to be not equal to the size of the buffer.
source_.getChar();
}
EXPECT_FALSE(source_.atEOF());
- size_t line = source_.getCurrentLine();
- EXPECT_EQ(2, line);
+ EXPECT_EQ(2, source_.getCurrentLine());
// Now, save the line.
source_.saveLine();
while (!source_.atEOF()) {
source_.getChar();
}
- line = source_.getCurrentLine();
// Now, we are at EOF.
EXPECT_TRUE(source_.atEOF());
- EXPECT_EQ(4, line);
+ EXPECT_EQ(4, source_.getCurrentLine());
// Now, ungetAll() and check where it goes back.
source_.ungetAll();