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() { ...@@ -117,6 +117,11 @@ InputSource::ungetAll() {
at_eof_ = false; at_eof_ = false;
} }
void
InputSource::saveLine() {
saved_line_ = line_;
}
void void
InputSource::compact() { InputSource::compact() {
if (buffer_pos_ == buffer_.size()) { if (buffer_pos_ == buffer_.size()) {
...@@ -128,6 +133,12 @@ InputSource::compact() { ...@@ -128,6 +133,12 @@ InputSource::compact() {
buffer_pos_ = 0; buffer_pos_ = 0;
} }
void
InputSource::mark() {
saveLine();
compact();
}
} // namespace master_lexer_internal } // namespace master_lexer_internal
} // namespace dns } // namespace dns
} // namespace isc } // namespace isc
...@@ -95,9 +95,15 @@ public: ...@@ -95,9 +95,15 @@ public:
/// \brief Saves the current line being read. Later, when /// \brief Saves the current line being read. Later, when
/// \c ungetAll() is called, it skips back to the last-saved line. /// \c ungetAll() is called, it skips back to the last-saved line.
void saveLine() { void saveLine();
saved_line_ = line_;
} /// 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 /// \brief Returns a single character from the input source. If end
/// of file is reached, \c END_OF_STREAM is returned. /// of file is reached, \c END_OF_STREAM is returned.
...@@ -121,11 +127,6 @@ public: ...@@ -121,11 +127,6 @@ public:
/// saved. /// saved.
void ungetAll(); 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: private:
bool at_eof_; bool at_eof_;
size_t line_; size_t line_;
......
...@@ -185,7 +185,7 @@ TEST_F(InputSourceTest, compact) { ...@@ -185,7 +185,7 @@ TEST_F(InputSourceTest, compact) {
EXPECT_TRUE(source_.atEOF()); EXPECT_TRUE(source_.atEOF());
} }
TEST_F(InputSourceTest, compactDuring) { TEST_F(InputSourceTest, markDuring) {
// First, skip to line 2. // First, skip to line 2.
while (!source_.atEOF() && while (!source_.atEOF() &&
(source_.getCurrentLine() != 2)) { (source_.getCurrentLine() != 2)) {
...@@ -199,8 +199,9 @@ TEST_F(InputSourceTest, compactDuring) { ...@@ -199,8 +199,9 @@ TEST_F(InputSourceTest, compactDuring) {
source_.ungetChar(); source_.ungetChar();
source_.ungetChar(); source_.ungetChar();
source_.saveLine(); // Now "mark" the source, meaning that we save line number and also
source_.compact(); // compact the internal buffer at this stage.
source_.mark();
// Ungetting here must throw. // Ungetting here must throw.
EXPECT_THROW(source_.ungetChar(), InputSource::UngetBeforeBeginning); 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