Browse Source

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

Mukund Sivaraman 12 years ago
parent
commit
9af419deb6

+ 11 - 0
src/lib/dns/master_lexer_inputsource.cc

@@ -118,6 +118,11 @@ InputSource::ungetAll() {
 }
 
 void
+InputSource::saveLine() {
+    saved_line_ = line_;
+}
+
+void
 InputSource::compact() {
     if (buffer_pos_ == buffer_.size()) {
         buffer_.clear();
@@ -128,6 +133,12 @@ InputSource::compact() {
     buffer_pos_ = 0;
 }
 
+void
+InputSource::mark() {
+    saveLine();
+    compact();
+}
+
 } // namespace master_lexer_internal
 } // namespace dns
 } // namespace isc

+ 9 - 8
src/lib/dns/master_lexer_inputsource.h

@@ -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_;

+ 4 - 3
src/lib/dns/tests/master_lexer_inputsource_unittest.cc

@@ -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);