mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-02 06:55:16 +00:00
[2369] Constify variables in various places
This commit is contained in:
@@ -21,7 +21,7 @@ namespace master_lexer_internal {
|
|||||||
namespace { // unnamed namespace
|
namespace { // unnamed namespace
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
createStreamName(std::istream& input_stream) {
|
createStreamName(const std::istream& input_stream) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "stream-" << &input_stream;
|
ss << "stream-" << &input_stream;
|
||||||
return (ss.str());
|
return (ss.str());
|
||||||
@@ -70,7 +70,7 @@ InputSource::getChar() {
|
|||||||
return (END_OF_STREAM);
|
return (END_OF_STREAM);
|
||||||
}
|
}
|
||||||
// We are not yet at EOF. Read from the 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,
|
// 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
|
// but don't modify buffer_pos_ (which should still be equal to
|
||||||
// the size of buffer_).
|
// the size of buffer_).
|
||||||
@@ -87,7 +87,7 @@ InputSource::getChar() {
|
|||||||
buffer_.push_back(c);
|
buffer_.push_back(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = buffer_[buffer_pos_++];
|
const int c = buffer_[buffer_pos_++];
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
line_++;
|
line_++;
|
||||||
}
|
}
|
||||||
|
@@ -68,7 +68,8 @@ TEST_F(InputSourceTest, nonExistentFile) {
|
|||||||
// getChar() should return characters from the input stream in
|
// getChar() should return characters from the input stream in
|
||||||
// sequence. ungetChar() should skip backwards.
|
// sequence. ungetChar() should skip backwards.
|
||||||
void
|
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++) {
|
for (size_t i = 0; i < str_length; i++) {
|
||||||
EXPECT_EQ(str[i], source.getChar());
|
EXPECT_EQ(str[i], source.getChar());
|
||||||
@@ -101,7 +102,7 @@ checkGetAndUngetChar(InputSource& source, const char* str, size_t str_length)
|
|||||||
source.ungetChar();
|
source.ungetChar();
|
||||||
|
|
||||||
for (size_t i = 0; i < str_length; i++) {
|
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.
|
// Skip one character.
|
||||||
source.ungetChar();
|
source.ungetChar();
|
||||||
EXPECT_EQ(str[index], source.getChar());
|
EXPECT_EQ(str[index], source.getChar());
|
||||||
@@ -119,7 +120,7 @@ TEST_F(InputSourceTest, stream) {
|
|||||||
|
|
||||||
TEST_F(InputSourceTest, file) {
|
TEST_F(InputSourceTest, file) {
|
||||||
std::ifstream fs(TEST_DATA_SRCDIR "/masterload.txt");
|
std::ifstream fs(TEST_DATA_SRCDIR "/masterload.txt");
|
||||||
std::string str((std::istreambuf_iterator<char>(fs)),
|
const std::string str((std::istreambuf_iterator<char>(fs)),
|
||||||
std::istreambuf_iterator<char>());
|
std::istreambuf_iterator<char>());
|
||||||
fs.close();
|
fs.close();
|
||||||
|
|
||||||
@@ -191,8 +192,7 @@ TEST_F(InputSourceTest, compactDuring) {
|
|||||||
source_.getChar();
|
source_.getChar();
|
||||||
}
|
}
|
||||||
EXPECT_FALSE(source_.atEOF());
|
EXPECT_FALSE(source_.atEOF());
|
||||||
size_t line = source_.getCurrentLine();
|
EXPECT_EQ(2, source_.getCurrentLine());
|
||||||
EXPECT_EQ(2, line);
|
|
||||||
|
|
||||||
// Now, unget a couple of characters. This should cause the
|
// Now, unget a couple of characters. This should cause the
|
||||||
// buffer_pos_ to be not equal to the size of the buffer.
|
// buffer_pos_ to be not equal to the size of the buffer.
|
||||||
@@ -299,8 +299,7 @@ TEST_F(InputSourceTest, saveLine) {
|
|||||||
source_.getChar();
|
source_.getChar();
|
||||||
}
|
}
|
||||||
EXPECT_FALSE(source_.atEOF());
|
EXPECT_FALSE(source_.atEOF());
|
||||||
size_t line = source_.getCurrentLine();
|
EXPECT_EQ(2, source_.getCurrentLine());
|
||||||
EXPECT_EQ(2, line);
|
|
||||||
|
|
||||||
// Now, save the line.
|
// Now, save the line.
|
||||||
source_.saveLine();
|
source_.saveLine();
|
||||||
@@ -309,11 +308,10 @@ TEST_F(InputSourceTest, saveLine) {
|
|||||||
while (!source_.atEOF()) {
|
while (!source_.atEOF()) {
|
||||||
source_.getChar();
|
source_.getChar();
|
||||||
}
|
}
|
||||||
line = source_.getCurrentLine();
|
|
||||||
|
|
||||||
// Now, we are at EOF.
|
// Now, we are at EOF.
|
||||||
EXPECT_TRUE(source_.atEOF());
|
EXPECT_TRUE(source_.atEOF());
|
||||||
EXPECT_EQ(4, line);
|
EXPECT_EQ(4, source_.getCurrentLine());
|
||||||
|
|
||||||
// Now, ungetAll() and check where it goes back.
|
// Now, ungetAll() and check where it goes back.
|
||||||
source_.ungetAll();
|
source_.ungetAll();
|
||||||
|
Reference in New Issue
Block a user