[ox/std] Make ox_atoi return an ox::Result
This commit is contained in:
parent
28e68adc75
commit
c5773202b5
4
deps/ox/src/ox/clargs/clargs.cpp
vendored
4
deps/ox/src/ox/clargs/clargs.cpp
vendored
@ -28,7 +28,9 @@ ClArgs::ClArgs(int argc, const char **args) {
|
|||||||
m_bools[arg] = false;
|
m_bools[arg] = false;
|
||||||
}
|
}
|
||||||
m_strings[arg] = val;
|
m_strings[arg] = val;
|
||||||
m_ints[arg] = ox_atoi(val.c_str());
|
if (auto r = ox_atoi(val.c_str()); r.error == 0) {
|
||||||
|
m_ints[arg] = r.value;
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
deps/ox/src/ox/claw/read.cpp
vendored
4
deps/ox/src/ox/claw/read.cpp
vendored
@ -49,7 +49,9 @@ Result<ClawHeader> readHeader(const char *buff, std::size_t buffLen) noexcept {
|
|||||||
return OxError(1);
|
return OxError(1);
|
||||||
}
|
}
|
||||||
hdr.typeName = typeName;
|
hdr.typeName = typeName;
|
||||||
hdr.typeVersion = ox_atoi(versionStr.c_str());
|
if (auto r = ox_atoi(versionStr.c_str()); r.error == 0) {
|
||||||
|
hdr.typeVersion = r.value;
|
||||||
|
}
|
||||||
hdr.data = buff;
|
hdr.data = buff;
|
||||||
hdr.dataSize = buffLen;
|
hdr.dataSize = buffLen;
|
||||||
return hdr;
|
return hdr;
|
||||||
|
9
deps/ox/src/ox/std/strops.hpp
vendored
9
deps/ox/src/ox/std/strops.hpp
vendored
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "error.hpp"
|
||||||
#include "math.hpp"
|
#include "math.hpp"
|
||||||
#include "types.hpp"
|
#include "types.hpp"
|
||||||
#include "typetraits.hpp"
|
#include "typetraits.hpp"
|
||||||
@ -125,15 +126,17 @@ template<typename T1, typename T2>
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr int ox_atoi(const char *str) noexcept {
|
[[nodiscard]] constexpr ox::Result<int> ox_atoi(const char *str) noexcept {
|
||||||
int total = 0;
|
int total = 0;
|
||||||
int multiplier = 1;
|
int multiplier = 1;
|
||||||
|
|
||||||
for (auto i = static_cast<int64_t>(ox_strlen(str)) - 1; i != -1; i--) {
|
for (auto i = static_cast<int64_t>(ox_strlen(str)) - 1; i != -1; i--) {
|
||||||
|
if (str[i] >= '0' && str[i] <= '9') {
|
||||||
total += (str[i] - '0') * multiplier;
|
total += (str[i] - '0') * multiplier;
|
||||||
multiplier *= 10;
|
multiplier *= 10;
|
||||||
|
} else {
|
||||||
|
return OxError(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user