summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-12-16 11:34:26 +0100
committerMax Kellermann <max@duempel.org>2015-12-16 11:34:26 +0100
commit51168169e73528d388b39b826afe1df3370bd10a (patch)
treef0fcdd175e57a03365b3d3522dd9f50a69f75d0d /src/util
parentd256a0e98f587c0af714c74038ff75903c0903fe (diff)
util/Tokenizer: use std::runtime_error on syntax error
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Tokenizer.cxx64
-rw-r--r--src/util/Tokenizer.hxx44
2 files changed, 38 insertions, 70 deletions
diff --git a/src/util/Tokenizer.cxx b/src/util/Tokenizer.cxx
index 19322b70d..e065ab6e0 100644
--- a/src/util/Tokenizer.cxx
+++ b/src/util/Tokenizer.cxx
@@ -31,10 +31,8 @@
#include "Tokenizer.hxx"
#include "CharUtil.hxx"
#include "StringUtil.hxx"
-#include "Error.hxx"
-#include "Domain.hxx"
-static constexpr Domain tokenizer_domain("tokenizer");
+#include <stdexcept>
static inline bool
valid_word_first_char(char ch)
@@ -49,7 +47,7 @@ valid_word_char(char ch)
}
char *
-Tokenizer::NextWord(Error &error)
+Tokenizer::NextWord()
{
char *const word = input;
@@ -58,10 +56,8 @@ Tokenizer::NextWord(Error &error)
/* check the first character */
- if (!valid_word_first_char(*input)) {
- error.Set(tokenizer_domain, "Letter expected");
- return nullptr;
- }
+ if (!valid_word_first_char(*input))
+ throw std::runtime_error("Letter expected");
/* now iterate over the other characters until we find a
whitespace or end-of-string */
@@ -75,10 +71,8 @@ Tokenizer::NextWord(Error &error)
break;
}
- if (!valid_word_char(*input)) {
- error.Set(tokenizer_domain, "Invalid word character");
- return nullptr;
- }
+ if (!valid_word_char(*input))
+ throw std::runtime_error("Invalid word character");
}
/* end of string: the string is already null-terminated
@@ -94,7 +88,7 @@ valid_unquoted_char(char ch)
}
char *
-Tokenizer::NextUnquoted(Error &error)
+Tokenizer::NextUnquoted()
{
char *const word = input;
@@ -103,10 +97,8 @@ Tokenizer::NextUnquoted(Error &error)
/* check the first character */
- if (!valid_unquoted_char(*input)) {
- error.Set(tokenizer_domain, "Invalid unquoted character");
- return nullptr;
- }
+ if (!valid_unquoted_char(*input))
+ throw std::runtime_error("Invalid unquoted character");
/* now iterate over the other characters until we find a
whitespace or end-of-string */
@@ -120,11 +112,8 @@ Tokenizer::NextUnquoted(Error &error)
break;
}
- if (!valid_unquoted_char(*input)) {
- error.Set(tokenizer_domain,
- "Invalid unquoted character");
- return nullptr;
- }
+ if (!valid_unquoted_char(*input))
+ throw std::runtime_error("Invalid unquoted character");
}
/* end of string: the string is already null-terminated
@@ -134,7 +123,7 @@ Tokenizer::NextUnquoted(Error &error)
}
char *
-Tokenizer::NextString(Error &error)
+Tokenizer::NextString()
{
char *const word = input, *dest = input;
@@ -144,10 +133,8 @@ Tokenizer::NextString(Error &error)
/* check for the opening " */
- if (*input != '"') {
- error.Set(tokenizer_domain, "'\"' expected");
- return nullptr;
- }
+ if (*input != '"')
+ throw std::runtime_error("'\"' expected");
++input;
@@ -159,14 +146,8 @@ Tokenizer::NextString(Error &error)
character */
++input;
- if (*input == 0) {
- /* return input-1 so the caller can see the
- difference between "end of line" and
- "error" */
- --input;
- error.Set(tokenizer_domain, "Missing closing '\"'");
- return nullptr;
- }
+ if (*input == 0)
+ throw std::runtime_error("Missing closing '\"'");
/* copy one character */
*dest++ = *input++;
@@ -176,11 +157,8 @@ Tokenizer::NextString(Error &error)
line) */
++input;
- if (!IsWhitespaceFast(*input)) {
- error.Set(tokenizer_domain,
- "Space expected after closing '\"'");
- return nullptr;
- }
+ if (!IsWhitespaceFast(*input))
+ throw std::runtime_error("Space expected after closing '\"'");
/* finish the string and return it */
@@ -190,10 +168,10 @@ Tokenizer::NextString(Error &error)
}
char *
-Tokenizer::NextParam(Error &error)
+Tokenizer::NextParam()
{
if (*input == '"')
- return NextString(error);
+ return NextString();
else
- return NextUnquoted(error);
+ return NextUnquoted();
}
diff --git a/src/util/Tokenizer.hxx b/src/util/Tokenizer.hxx
index 3f3448d52..01e4db762 100644
--- a/src/util/Tokenizer.hxx
+++ b/src/util/Tokenizer.hxx
@@ -30,8 +30,6 @@
#ifndef TOKENIZER_HXX
#define TOKENIZER_HXX
-class Error;
-
class Tokenizer {
char *input;
@@ -58,50 +56,42 @@ public:
}
/**
- * Reads the next word.
+ * Reads the next word. Throws std::runtime_error on error.
*
- * @param error if this function returns nullptr and
- * **input_p!=0, it provides an #Error object in
- * this argument
* @return a pointer to the null-terminated word, or nullptr
- * on error or end of line
+ * on end of line
*/
- char *NextWord(Error &error);
+ char *NextWord();
/**
- * Reads the next unquoted word from the input string.
+ * Reads the next unquoted word from the input string. Throws
+ * std::runtime_error on error.
*
- * @param error if this function returns nullptr and **input_p!=0, it
- * provides an #Error object in this argument
* @return a pointer to the null-terminated word, or nullptr
- * on error or end of line
+ * on end of line
*/
- char *NextUnquoted(Error &error);
+ char *NextUnquoted();
/**
- * Reads the next quoted string from the input string. A backslash
- * escapes the following character. This function modifies the input
- * string.
+ * Reads the next quoted string from the input string. A
+ * backslash escapes the following character. This function
+ * modifies the input string. Throws std::runtime_error on
+ * error.
*
- * @param error if this function returns nullptr and **input_p!=0, it
- * provides an #Error object in this argument
- * @return a pointer to the null-terminated string, or nullptr on error
- * or end of line
+ * @return a pointer to the null-terminated string, or nullptr
+ * end of line
*/
- char *NextString(Error &error);
+ char *NextString();
/**
* Reads the next unquoted word or quoted string from the
* input. This is a wrapper for NextUnquoted() and
- * NextString().
+ * NextString(). Throws std::runtime_error on error.
*
- * @param error if this function returns nullptr and
- * **input_p!=0, it provides an #Error object in
- * this argument
* @return a pointer to the null-terminated string, or nullptr
- * on error or end of line
+ * on end of line
*/
- char *NextParam(Error &error);
+ char *NextParam();
};
#endif