[ox] Make ox::String::String(const char*) explicit

This commit is contained in:
2023-12-01 22:36:24 -06:00
parent e9822bf124
commit 1a1c8ae6cc
13 changed files with 83 additions and 105 deletions

View File

@@ -13,7 +13,7 @@ namespace ox {
ClArgs::ClArgs(int argc, const char **args) noexcept {
for (auto i = 0u; i < static_cast<unsigned>(argc); ++i) {
String arg = args[i];
auto arg = String(args[i]);
if (arg[0] == '-') {
while (arg[0] == '-' && arg.len()) {
arg = arg.substr(1);
@@ -21,7 +21,7 @@ ClArgs::ClArgs(int argc, const char **args) noexcept {
m_bools[arg] = true;
// parse additional arguments
if (i < static_cast<unsigned>(argc) && args[i + 1]) {
String val = args[i + 1];
auto val = String(args[i + 1]);
if (val.len() && val[i] != '-') {
if (val == "false") {
m_bools[arg] = false;
@@ -37,32 +37,32 @@ ClArgs::ClArgs(int argc, const char **args) noexcept {
}
}
bool ClArgs::getBool(ox::CRString arg, bool defaultValue) const noexcept {
bool ClArgs::getBool(ox::CRStringView arg, bool defaultValue) const noexcept {
auto [value, err] = m_ints.at(arg);
return !err ? *value : defaultValue;
}
String ClArgs::getString(ox::CRString arg, const char *defaultValue) const noexcept {
String ClArgs::getString(ox::CRStringView arg, const char *defaultValue) const noexcept {
auto [value, err] = m_strings.at(arg);
return !err ? *value : defaultValue;
return !err ? *value : ox::String(defaultValue);
}
int ClArgs::getInt(ox::CRString arg, int defaultValue) const noexcept {
int ClArgs::getInt(ox::CRStringView arg, int defaultValue) const noexcept {
auto [value, err] = m_ints.at(arg);
return !err ? *value : defaultValue;
}
Result<bool> ClArgs::getBool(ox::CRString arg) const noexcept {
Result<bool> ClArgs::getBool(ox::CRStringView arg) const noexcept {
oxRequire(out, m_bools.at(arg));
return *out;
}
Result<String> ClArgs::getString(ox::CRString argName) const noexcept {
Result<String> ClArgs::getString(ox::CRStringView argName) const noexcept {
oxRequire(out, m_strings.at(argName));
return *out;
}
Result<int> ClArgs::getInt(ox::CRString arg) const noexcept {
Result<int> ClArgs::getInt(ox::CRStringView arg) const noexcept {
oxRequire(out, m_ints.at(arg));
return *out;
}

View File

@@ -23,21 +23,21 @@ class ClArgs {
ClArgs(int argc, const char **args) noexcept;
[[nodiscard]]
bool getBool(ox::CRString arg, bool defaultValue) const noexcept;
bool getBool(ox::CRStringView arg, bool defaultValue) const noexcept;
[[nodiscard]]
String getString(ox::CRString argName, const char *defaultValue) const noexcept;
String getString(ox::CRStringView argName, const char *defaultValue) const noexcept;
[[nodiscard]]
int getInt(ox::CRString arg, int defaultValue) const noexcept;
int getInt(ox::CRStringView arg, int defaultValue) const noexcept;
[[nodiscard]]
Result<bool> getBool(ox::CRString arg) const noexcept;
Result<bool> getBool(ox::CRStringView arg) const noexcept;
[[nodiscard]]
Result<String> getString(ox::CRString argName) const noexcept;
Result<String> getString(ox::CRStringView argName) const noexcept;
Result<int> getInt(ox::CRString arg) const noexcept;
Result<int> getInt(ox::CRStringView arg) const noexcept;
};