diff options
Diffstat (limited to 'source/fud_string_convert.cpp')
-rw-r--r-- | source/fud_string_convert.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/source/fud_string_convert.cpp b/source/fud_string_convert.cpp index 428ab36..fdf3436 100644 --- a/source/fud_string_convert.cpp +++ b/source/fud_string_convert.cpp @@ -36,59 +36,60 @@ Result<bool, FudStatus> checkNegative(StringView& view, size_t& skipIndex) { bool isNegative = view.data()[0] == '-'; if (isNegative && view.length() == 1) { - return FudStatus::ArgumentInvalid; + return FudError{FudStatus::ArgumentInvalid}; } if (isNegative) { skipIndex += 1; view.advanceUnsafe(); } - return isNegative; + return Okay<bool>{isNegative}; } Result<Radix, FudStatus> determineRadix(StringView input, size_t& index) { if (input.length() < 1) { - return FudStatus::ArgumentInvalid; + return FudError{FudStatus::ArgumentInvalid}; } if (input.length() == 1 && input.data()[0] == '0') { - return Radix::Octal; + return Okay<Radix>{Radix::Octal}; } if (input.length() == 1) { - return Radix::Decimal; + return Okay<Radix>{Radix::Decimal}; } if (input.data()[0] == '0' && (input.data()[1] == 'x' || input.data()[1] == 'X')) { index += 2; - return Radix::Hexadecimal; + return Okay<Radix>{Radix::Hexadecimal}; } if (input.data()[0] == '0') { auto nextChar = input.data()[1]; auto nextVal = AsciiLookup[nextChar]; if (nextVal >= 0 && nextVal < static_cast<uint8_t>(Radix::Octal)) { - return Radix::Octal; + return Okay<Radix>{Radix::Octal}; } if (nextVal >= static_cast<uint8_t>(Radix::Octal)) { - return FudStatus::ArgumentInvalid; + return FudError{FudStatus::ArgumentInvalid}; } } - return Radix::Decimal; + return Okay<Radix>{Radix::Decimal}; } Result<uint8_t, FudStatus> getRadix(StringView& view, size_t& skipIndex, Option<uint8_t> specifiedRadixOption) { + using RetType = Result<uint8_t, FudStatus>; if (specifiedRadixOption.isNone()) { size_t radixIndex = 0; auto status = determineRadix(view, radixIndex); if (status.isOkay()) { skipIndex += radixIndex; view.advanceUnsafe(radixIndex); - return static_cast<uint8_t>(status.takeOkay()); + return RetType::okay(static_cast<uint8_t>(status.takeOkay())); } - return status.takeError(); + return RetType::error(status); } auto radix = specifiedRadixOption.value(); @@ -104,7 +105,7 @@ Result<uint8_t, FudStatus> getRadix(StringView& view, size_t& skipIndex, Option< view.advanceUnsafe(2); } - return radix; + return RetType::okay(radix); } } // namespace fud::impl |