mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 21:45:37 +00:00
[2369] Throw a custom exception in ungetChar()
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
#include <dns/inputsource.h>
|
||||
#include <exceptions/exceptions.h>
|
||||
|
||||
namespace isc {
|
||||
namespace dns {
|
||||
@@ -53,7 +52,7 @@ InputSource::ungetChar() {
|
||||
if (at_eof_) {
|
||||
at_eof_ = false;
|
||||
} else if (buffer_pos_ == 0) {
|
||||
isc_throw(OutOfRange, "Cannot skip before the start of buffer");
|
||||
isc_throw(UngetError, "Cannot skip before the start of buffer");
|
||||
} else {
|
||||
buffer_pos_--;
|
||||
if (buffer_[buffer_pos_] == '\n') {
|
||||
|
@@ -15,6 +15,8 @@
|
||||
#ifndef DNS_INPUTSOURCE_H
|
||||
#define DNS_INPUTSOURCE_H 1
|
||||
|
||||
#include <exceptions/exceptions.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -50,6 +52,14 @@ public:
|
||||
saved_line_ = line_;
|
||||
}
|
||||
|
||||
/// \brief Exception thrown when ungetChar() is made to go before
|
||||
/// the start of buffer.
|
||||
struct UngetError : public OutOfRange {
|
||||
UngetError(const char* file, size_t line, const char* what) :
|
||||
OutOfRange(file, line, what)
|
||||
{}
|
||||
};
|
||||
|
||||
int getChar();
|
||||
void ungetChar();
|
||||
void ungetAll();
|
||||
|
@@ -96,7 +96,7 @@ TEST_F(InputSourceTest, getAndUngetChar) {
|
||||
}
|
||||
|
||||
// Skipping past the start of buffer should throw.
|
||||
EXPECT_THROW(source_.ungetChar(), isc::OutOfRange);
|
||||
EXPECT_THROW(source_.ungetChar(), InputSource::UngetError);
|
||||
}
|
||||
|
||||
// ungetAll() should skip back to the place where the InputSource
|
||||
@@ -162,7 +162,7 @@ TEST_F(InputSourceTest, lines) {
|
||||
((line - 1) == source_.getCurrentLine())));
|
||||
line = source_.getCurrentLine();
|
||||
}
|
||||
}, isc::OutOfRange);
|
||||
}, InputSource::UngetError);
|
||||
|
||||
// Now we are back to where we started.
|
||||
EXPECT_EQ(1, source_.getCurrentLine());
|
||||
|
Reference in New Issue
Block a user