Skip to content

Commit

Permalink
io/config/LineParser: add noexcept
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Nov 15, 2023
1 parent 0435e8b commit aa25f25
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
16 changes: 8 additions & 8 deletions src/io/config/LineParser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <string.h>

bool
LineParser::SkipWord(const char *word)
LineParser::SkipWord(const char *word) noexcept
{
char *q = p;

Expand All @@ -29,7 +29,7 @@ LineParser::SkipWord(const char *word)
}

const char *
LineParser::NextWord()
LineParser::NextWord() noexcept
{
if (!IsWordChar(front()))
return nullptr;
Expand All @@ -49,7 +49,7 @@ LineParser::NextWord()
}

inline char *
LineParser::NextUnquotedValue()
LineParser::NextUnquotedValue() noexcept
{
if (!IsUnquotedChar(front()))
return nullptr;
Expand All @@ -69,7 +69,7 @@ LineParser::NextUnquotedValue()
}

inline char *
LineParser::NextRelaxedUnquotedValue()
LineParser::NextRelaxedUnquotedValue() noexcept
{
if (IsEnd())
return nullptr;
Expand All @@ -88,7 +88,7 @@ LineParser::NextRelaxedUnquotedValue()
}

inline char *
LineParser::NextQuotedValue(const char stop)
LineParser::NextQuotedValue(const char stop) noexcept
{
char *const value = p;
char *q = strchr(p, stop);
Expand All @@ -101,7 +101,7 @@ LineParser::NextQuotedValue(const char stop)
}

char *
LineParser::NextValue()
LineParser::NextValue() noexcept
{
const char ch = front();
if (IsQuote(ch)) {
Expand All @@ -112,7 +112,7 @@ LineParser::NextValue()
}

char *
LineParser::NextRelaxedValue()
LineParser::NextRelaxedValue() noexcept
{
const char ch = front();
if (IsQuote(ch)) {
Expand All @@ -123,7 +123,7 @@ LineParser::NextRelaxedValue()
}

char *
LineParser::NextUnescape()
LineParser::NextUnescape() noexcept
{
const char stop = front();
if (!IsQuote(stop))
Expand Down
36 changes: 19 additions & 17 deletions src/io/config/LineParser.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,33 @@ class LineParser {
public:
using Error = std::runtime_error;

explicit LineParser(char *_p):p(StripLeft(_p)) {
explicit LineParser(char *_p) noexcept
:p(StripLeft(_p))
{
StripRight(p);
}

/**
* Replace the string pointer. This is a kludge for class
* #VariableConfigParser.
*/
void Replace(char *_p) {
void Replace(char *_p) noexcept {
p = _p;
}

char *Rest() {
char *Rest() noexcept {
return p;
}

void Strip() {
void Strip() noexcept {
p = StripLeft(p);
}

char front() const {
char front() const noexcept {
return *p;
}

bool IsEnd() const {
bool IsEnd() const noexcept {
return front() == 0;
}

Expand Down Expand Up @@ -81,7 +83,7 @@ public:
return found;
}

bool SkipSymbol(char a, char b) {
bool SkipSymbol(char a, char b) noexcept {
bool found = p[0] == a && p[1] == b;
if (found)
p += 2;
Expand All @@ -93,12 +95,12 @@ public:
* return true. If not, the method returns false, leaving the
* object unmodified.
*/
bool SkipWord(const char *word);
bool SkipWord(const char *word) noexcept;

const char *NextWord();
char *NextValue();
char *NextRelaxedValue();
char *NextUnescape();
const char *NextWord() noexcept;
char *NextValue() noexcept;
char *NextRelaxedValue() noexcept;
char *NextUnescape() noexcept;

bool NextBool();
unsigned NextPositiveInteger();
Expand All @@ -124,15 +126,15 @@ public:
}

private:
char *NextUnquotedValue();
char *NextRelaxedUnquotedValue();
char *NextQuotedValue(char stop);
char *NextUnquotedValue() noexcept;
char *NextRelaxedUnquotedValue() noexcept;
char *NextQuotedValue(char stop) noexcept;

static constexpr bool IsUnquotedChar(char ch) {
static constexpr bool IsUnquotedChar(char ch) noexcept {
return IsWordChar(ch) || ch == '.' || ch == '-' || ch == ':';
}

static constexpr bool IsQuote(char ch) {
static constexpr bool IsQuote(char ch) noexcept {
return ch == '"' || ch == '\'';
}
};
Expand Down

0 comments on commit aa25f25

Please sign in to comment.