diff options
Diffstat (limited to 'include/fud_format.hpp')
-rw-r--r-- | include/fud_format.hpp | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/include/fud_format.hpp b/include/fud_format.hpp index e156f43..c06643d 100644 --- a/include/fud_format.hpp +++ b/include/fud_format.hpp @@ -125,10 +125,10 @@ struct FormatFill { length = 2; auto fill = data[0]; if (not Ascii::valid(fill)) { - return FudStatus::Utf8Invalid; + return RetType::error(FudStatus::Utf8Invalid); } if (fill == '{' || fill == '}') { - return FudStatus::FormatInvalid; + return RetType::error(FudStatus::FormatInvalid); } return RetType::okay(FormatFill{std::move(align2).value(), data[0]}); } @@ -465,45 +465,46 @@ FormatResult vFormat(Sink& sink, FormatCharMode formatMode, FormatString fmt, co template <size_t Size> Result<uint32_t, FudStatus> getSpecField(FormatSpec& formatSpec, uint32_t index, const FormatArguments<Size>& args) { + using RetType = Result<uint32_t, FudStatus>; static_assert(not std::is_signed_v<utf8>); if (not formatSpec.takesPosition() || not formatSpec.takesWidth) { - return FudStatus::ArgumentInvalid; + return RetType::error(FudStatus::ArgumentInvalid); } if (index >= Size) { - return FudStatus::FormatInvalid; + return RetType::error(FudStatus::FormatInvalid); } if (std::holds_alternative<utf8>(args[index])) { - return std::get<utf8>(args[index]); + return RetType::okay(std::get<utf8>(args[index])); } if (std::holds_alternative<int32_t>(args[index])) { auto value = std::get<int32_t>(args[index]); if (value < 0) { - return FudStatus::FormatInvalid; + return RetType::error(FudStatus::FormatInvalid); } - return static_cast<uint32_t>(value); + return RetType::okay(static_cast<uint32_t>(value)); } if (std::holds_alternative<int64_t>(args[index])) { auto value = std::get<int64_t>(args[index]); if (value < 0 || value > std::numeric_limits<uint32_t>::max()) { - return FudStatus::FormatInvalid; + return RetType::error(FudStatus::FormatInvalid); } - return static_cast<uint32_t>(value); + return RetType::okay(static_cast<uint32_t>(value)); } if (std::holds_alternative<uint32_t>(args[index])) { - return std::get<uint32_t>(args[index]); + return RetType::okay(std::get<uint32_t>(args[index])); } if (std::holds_alternative<uint32_t>(args[index])) { auto value = std::get<uint64_t>(args[index]); if (value > std::numeric_limits<uint32_t>::max()) { - return FudStatus::FormatInvalid; + return RetType::error(FudStatus::FormatInvalid); } - return static_cast<uint32_t>(value); + return RetType::okay(static_cast<uint32_t>(value)); } - return FudStatus::FormatInvalid; + return RetType::error(FudStatus::FormatInvalid); } template <size_t Size> @@ -514,6 +515,7 @@ Result<FormatSpec, FudStatus> vFormatPrepareSpec( bool& firstSpec, bool& takesPosition) { + using RetType = Result<FormatSpec, FudStatus>; if (firstSpec) { firstSpec = false; return vFormatPrepareFirstSpec(scanView, args, argIndex, takesPosition); @@ -528,24 +530,24 @@ Result<FormatSpec, FudStatus> vFormatPrepareSpec( auto formatSpec{formatSpecResult.getOkay()}; if (takesPosition != formatSpec.takesPosition() || (takesPosition && formatSpec.position >= Size)) { - return FudStatus::FormatInvalid; + return RetType::error(FudStatus::FormatInvalid); } if (takesPosition) { auto status = vFormatPreparePositionalSpec(formatSpec, args); if (status != FudStatus::Success) { - return status; + return RetType::error(status); } } else { auto status = vFormatPrepareNonPositionalSpec(formatSpec, args, argIndex); if (status != FudStatus::Success) { - return status; + return RetType::error(status); } } scanView.advanceUnsafe(specLength); - return formatSpec; + return RetType::okay(formatSpec); } template <size_t Size> @@ -555,6 +557,7 @@ Result<FormatSpec, FudStatus> vFormatPrepareFirstSpec( const uint32_t& argIndex, bool& takesPosition) { + using RetType = Result<FormatSpec, FudStatus>; size_t specLength{0}; auto formatSpecResult{FormatSpec::parse(scanView, specLength)}; if (formatSpecResult.isError()) { @@ -567,18 +570,18 @@ Result<FormatSpec, FudStatus> vFormatPrepareFirstSpec( if (takesPosition) { auto status = vFormatPreparePositionalSpec(formatSpec, args); if (status != FudStatus::Success) { - return status; + return RetType::error(status); } } else { auto status = vFormatPrepareNonPositionalSpec(formatSpec, args, argIndex); if (status != FudStatus::Success) { - return status; + return RetType::error(status); } } scanView.advanceUnsafe(specLength); - return formatSpec; + return RetType::okay(formatSpec); } template <size_t Size> |