util/OptionParser: add "noexcept"

This commit is contained in:
Max Kellermann
2018-01-16 10:13:39 +01:00
parent 465b154fc0
commit 42c1fe963b
2 changed files with 12 additions and 9 deletions

View File

@@ -22,7 +22,8 @@
#include <string.h> #include <string.h>
bool OptionParser::CheckOption(const OptionDef &opt) bool
OptionParser::CheckOption(const OptionDef &opt) const noexcept
{ {
assert(option != nullptr); assert(option != nullptr);
@@ -35,7 +36,8 @@ bool OptionParser::CheckOption(const OptionDef &opt)
option[1] == '\0'; option[1] == '\0';
} }
bool OptionParser::ParseNext() bool
OptionParser::ParseNext() noexcept
{ {
assert(HasEntries()); assert(HasEntries());
char *arg = *argv; char *arg = *argv;

View File

@@ -39,18 +39,18 @@ public:
/** /**
* Constructs #OptionParser. * Constructs #OptionParser.
*/ */
OptionParser(int _argc, char **_argv) OptionParser(int _argc, char **_argv) noexcept
:argc(_argc - 1), argv(_argv + 1) {} :argc(_argc - 1), argv(_argv + 1) {}
/** /**
* Checks if there are command line entries to process. * Checks if there are command line entries to process.
*/ */
bool HasEntries() const { return argc > 0; } bool HasEntries() const noexcept { return argc > 0; }
/** /**
* Gets the last parsed option. * Gets the last parsed option.
*/ */
char *GetOption() { char *GetOption() noexcept {
assert(option_raw != nullptr); assert(option_raw != nullptr);
return option_raw; return option_raw;
} }
@@ -58,13 +58,14 @@ public:
/** /**
* Checks if current option is a specified option. * Checks if current option is a specified option.
*/ */
bool CheckOption(const OptionDef& opt); bool CheckOption(const OptionDef &opt) const noexcept;
/** /**
* Checks if current option is a specified option * Checks if current option is a specified option
* or specified alternative option. * or specified alternative option.
*/ */
bool CheckOption(const OptionDef& opt, const OptionDef &alt_opt) { bool CheckOption(const OptionDef &opt,
const OptionDef &alt_opt) const noexcept {
return CheckOption(opt) || CheckOption(alt_opt); return CheckOption(opt) || CheckOption(alt_opt);
} }
@@ -74,12 +75,12 @@ public:
* Regardless of result, advances current position to the next * Regardless of result, advances current position to the next
* command line entry. * command line entry.
*/ */
bool ParseNext(); bool ParseNext() noexcept;
/** /**
* Checks if specified string is a command line option. * Checks if specified string is a command line option.
*/ */
static bool IsOption(const char *s) { static bool IsOption(const char *s) noexcept {
assert(s != nullptr); assert(s != nullptr);
return s[0] == '-'; return s[0] == '-';
} }