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

View File

@ -39,18 +39,18 @@ public:
/**
* Constructs #OptionParser.
*/
OptionParser(int _argc, char **_argv)
OptionParser(int _argc, char **_argv) noexcept
:argc(_argc - 1), argv(_argv + 1) {}
/**
* 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.
*/
char *GetOption() {
char *GetOption() noexcept {
assert(option_raw != nullptr);
return option_raw;
}
@ -58,13 +58,14 @@ public:
/**
* 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
* 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);
}
@ -74,12 +75,12 @@ public:
* Regardless of result, advances current position to the next
* command line entry.
*/
bool ParseNext();
bool ParseNext() noexcept;
/**
* 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);
return s[0] == '-';
}