Commit 9af419de authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[2369] Add InputSource::mark() as a combination of saveLine() and compact()

parent ccb09734
......@@ -117,6 +117,11 @@ InputSource::ungetAll() {
at_eof_ = false;
}
void
InputSource::saveLine() {
saved_line_ = line_;
}
void
InputSource::compact() {
if (buffer_pos_ == buffer_.size()) {
......@@ -128,6 +133,12 @@ InputSource::compact() {
buffer_pos_ = 0;
}
void
InputSource::mark() {
saveLine();
compact();
}
} // namespace master_lexer_internal
} // namespace dns
} // namespace isc
......@@ -95,9 +95,15 @@ public:
/// \brief Saves the current line being read. Later, when
/// \c ungetAll() is called, it skips back to the last-saved line.
void saveLine() {
saved_line_ = line_;
}
void saveLine();
/// Removes buffered content before the current location in the
/// \c InputSource. It's not possible to \c ungetChar() after this,
/// unless we read more data using \c getChar().
void compact();
/// Calls \c saveLine() and \c compact() in sequence.
void mark();
/// \brief Returns a single character from the input source. If end
/// of file is reached, \c END_OF_STREAM is returned.
......@@ -121,11 +127,6 @@ public:
/// saved.
void ungetAll();
/// Removes buffered content before the current location in the
/// \c InputSource. It's not possible to \c ungetChar() after this,
/// unless we read more data using \c getChar().
void compact();
private:
bool at_eof_;
size_t line_;
......
......@@ -185,7 +185,7 @@ TEST_F(InputSourceTest, compact) {
EXPECT_TRUE(source_.atEOF());
}
TEST_F(InputSourceTest, compactDuring) {
TEST_F(InputSourceTest, markDuring) {
// First, skip to line 2.
while (!source_.atEOF() &&
(source_.getCurrentLine() != 2)) {
......@@ -199,8 +199,9 @@ TEST_F(InputSourceTest, compactDuring) {
source_.ungetChar();
source_.ungetChar();
source_.saveLine();
source_.compact();
// Now "mark" the source, meaning that we save line number and also
// compact the internal buffer at this stage.
source_.mark();
// Ungetting here must throw.
EXPECT_THROW(source_.ungetChar(), InputSource::UngetBeforeBeginning);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment