Corrade::Utility::String::ParseResult class new in Git master

String parse result.

Stores a ParseState and an optional byte index of where a parsing failure happened, returned from parseDecimal() and parseHexadecimal(). The instance is implicitly convertible to a ParseState, allowing you to use just the enum if details about parsing failure aren't needed for anything:

std::int32_t value;
if(Utility::String::parseDecimal(…, value) == Utility::String::ParseState::Failed) {
    // Handle parsing failure ...
}

Furthermore, if your code treats ParseState::Clamped the same way as ParseState::Failed, you can use a bool conversion that returns true only for ParseState::Success:

std::int32_t value;
if(!Utility::String::parseDecimal(…, value)) {
    // Handle parsing failure or value out of bounds ...
}

Constructors, destructors, conversion operators

ParseResult(ParseState state, std::size_t index = 0)
Constructor.
operator ParseState() const
Parse state.
operator bool() const explicit
Whether the result succeeded.

Public functions

auto state() const -> ParseState
Parse state.
auto index() const -> std::size_t
Parse failure byte index.

Function documentation

Corrade::Utility::String::ParseResult::operator bool() const explicit

Whether the result succeeded.

Returns true if state() is ParseState::Success, false if it's either ParseState::Clamped or ParseState::Failed.

std::size_t Corrade::Utility::String::ParseResult::index() const

Parse failure byte index.

Index of a byte in the parsed string on which a parsing failure happened. Has a meaningful value only for ParseState::Failed, otherwise the value is 0.