feat(cpp-object-oriented-modular-refactoring): step 11 - source-target-resolver
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
#include "fesa/core/ascii.h"
|
||||
|
||||
#include <charconv>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
char AsciiLower(const char value) noexcept {
|
||||
if (value >= 'A' && value <= 'Z') {
|
||||
return static_cast<char>(value + ('a' - 'A'));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
bool AsciiCaseInsensitiveEquals(const std::string_view lhs,
|
||||
const std::string_view rhs) noexcept {
|
||||
if (lhs.size() != rhs.size()) {
|
||||
return false;
|
||||
}
|
||||
for (std::size_t index = 0U; index < lhs.size(); ++index) {
|
||||
if (AsciiLower(lhs[index]) != AsciiLower(rhs[index])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Result<std::int64_t> ParsePositiveSourceLabel(const std::string_view text) {
|
||||
std::int64_t value = 0;
|
||||
const char* const storage = text.empty() ? "" : text.data();
|
||||
const char* const first = storage;
|
||||
const char* const last = storage + text.size();
|
||||
const auto parsed = std::from_chars(first, last, value, 10);
|
||||
if (parsed.ec == std::errc{} && parsed.ptr == last && value > 0) {
|
||||
return Result<std::int64_t>::Success(value);
|
||||
}
|
||||
const std::string identity{text};
|
||||
return Result<std::int64_t>::Failure(Status::Failure(
|
||||
FailureCategory::kInput,
|
||||
{{Severity::kError,
|
||||
"invalid-source-label",
|
||||
{{}, 0U},
|
||||
"SOURCE_LABEL",
|
||||
identity,
|
||||
"A source label must be a complete positive base-10 integer."}}));
|
||||
}
|
||||
|
||||
} // namespace fesa
|
||||
Reference in New Issue
Block a user