mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 13:37:42 -05:00
sys: Return std::nullopt instead of {} for empty optional values
This commit is contained in:
@@ -661,7 +661,7 @@ namespace hex::pl {
|
||||
continue;
|
||||
}
|
||||
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool evaluateCondition(Evaluator *evaluator) const {
|
||||
@@ -823,7 +823,7 @@ namespace hex::pl {
|
||||
FunctionResult execute(Evaluator *evaluator) const override {
|
||||
evaluator->createVariable(this->getName(), this->getType());
|
||||
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -1260,7 +1260,7 @@ namespace hex::pl {
|
||||
evaluator->createVariable(variableDecl->getName(), variableDecl->getType()->evaluate(evaluator));
|
||||
}
|
||||
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -1912,7 +1912,7 @@ namespace hex::pl {
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -2118,7 +2118,7 @@ namespace hex::pl {
|
||||
[[nodiscard]] std::vector<PatternData *> createPatterns(Evaluator *evaluator) const override {
|
||||
this->execute(evaluator);
|
||||
|
||||
return { };
|
||||
return {};
|
||||
}
|
||||
|
||||
FunctionResult execute(Evaluator *evaluator) const override {
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace hex::magic {
|
||||
}
|
||||
|
||||
if (error)
|
||||
return {};
|
||||
return std::nullopt;
|
||||
else
|
||||
return magicFiles;
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ namespace hex {
|
||||
this->m_shouldCancel = false;
|
||||
|
||||
if (result != CURLE_OK)
|
||||
return {};
|
||||
return std::nullopt;
|
||||
else
|
||||
return responseCode;
|
||||
}
|
||||
|
||||
@@ -55,42 +55,42 @@ namespace hex::pl {
|
||||
base = 16;
|
||||
|
||||
if (Token::isFloatingPoint(type))
|
||||
return {};
|
||||
return std::nullopt;
|
||||
|
||||
if (numberData.find_first_not_of("0123456789ABCDEFabcdef") != std::string_view::npos)
|
||||
return {};
|
||||
return std::nullopt;
|
||||
} else if (numberData.starts_with("0b")) {
|
||||
numberData = numberData.substr(2);
|
||||
base = 2;
|
||||
|
||||
if (Token::isFloatingPoint(type))
|
||||
return {};
|
||||
return std::nullopt;
|
||||
|
||||
if (numberData.find_first_not_of("01") != std::string_view::npos)
|
||||
return {};
|
||||
return std::nullopt;
|
||||
} else if (numberData.find('.') != std::string_view::npos || Token::isFloatingPoint(type)) {
|
||||
base = 10;
|
||||
if (type == Token::ValueType::Any)
|
||||
type = Token::ValueType::Double;
|
||||
|
||||
if (std::count(numberData.begin(), numberData.end(), '.') > 1 || numberData.find_first_not_of("0123456789.") != std::string_view::npos)
|
||||
return {};
|
||||
return std::nullopt;
|
||||
|
||||
if (numberData.ends_with('.'))
|
||||
return {};
|
||||
return std::nullopt;
|
||||
} else if (isdigit(numberData[0])) {
|
||||
base = 10;
|
||||
|
||||
if (numberData.find_first_not_of("0123456789") != std::string_view::npos)
|
||||
return {};
|
||||
} else return {};
|
||||
return std::nullopt;
|
||||
} else return std::nullopt;
|
||||
|
||||
if (type == Token::ValueType::Any)
|
||||
type = Token::ValueType::Signed128Bit;
|
||||
|
||||
|
||||
if (numberData.length() == 0)
|
||||
return {};
|
||||
return std::nullopt;
|
||||
|
||||
if (Token::isUnsigned(type) || Token::isSigned(type)) {
|
||||
u128 integer = 0;
|
||||
@@ -103,7 +103,7 @@ namespace hex::pl {
|
||||
integer += 10 + (c - 'A');
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
integer += 10 + (c - 'a');
|
||||
else return {};
|
||||
else return std::nullopt;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
@@ -112,7 +112,7 @@ namespace hex::pl {
|
||||
case Token::ValueType::Signed128Bit:
|
||||
return { i128(integer) };
|
||||
default:
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
} else if (Token::isFloatingPoint(type)) {
|
||||
double floatingPoint = strtod(numberData.data(), nullptr);
|
||||
@@ -123,24 +123,23 @@ namespace hex::pl {
|
||||
case Token::ValueType::Double:
|
||||
return { double(floatingPoint) };
|
||||
default:
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<std::pair<char, size_t>> getCharacter(const std::string &string) {
|
||||
|
||||
if (string.length() < 1)
|
||||
return {};
|
||||
return std::nullopt;
|
||||
|
||||
// Escape sequences
|
||||
if (string[0] == '\\') {
|
||||
|
||||
if (string.length() < 2)
|
||||
return {};
|
||||
return std::nullopt;
|
||||
|
||||
// Handle simple escape sequences
|
||||
switch (string[1]) {
|
||||
@@ -189,10 +188,10 @@ namespace hex::pl {
|
||||
// Hexadecimal number
|
||||
if (string[1] == 'x') {
|
||||
if (string.length() != 4)
|
||||
return {};
|
||||
return std::nullopt;
|
||||
|
||||
if (!isxdigit(string[2]) || !isxdigit(string[3]))
|
||||
return {};
|
||||
return std::nullopt;
|
||||
|
||||
return {
|
||||
{std::strtoul(&string[2], nullptr, 16), 4}
|
||||
@@ -212,7 +211,7 @@ namespace hex::pl {
|
||||
};
|
||||
}
|
||||
|
||||
return {};
|
||||
return std::nullopt;
|
||||
} else return {
|
||||
{string[0], 1}
|
||||
};
|
||||
|
||||
@@ -98,19 +98,19 @@ namespace hex::pl {
|
||||
auto preprocessedCode = this->m_preprocessor->preprocess(code);
|
||||
if (!preprocessedCode.has_value()) {
|
||||
this->m_currError = this->m_preprocessor->getError();
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto tokens = this->m_lexer->lex(preprocessedCode.value());
|
||||
if (!tokens.has_value()) {
|
||||
this->m_currError = this->m_lexer->getError();
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto ast = this->m_parser->parse(tokens.value());
|
||||
if (!ast.has_value()) {
|
||||
this->m_currError = this->m_parser->getError();
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return ast;
|
||||
@@ -136,14 +136,14 @@ namespace hex::pl {
|
||||
|
||||
auto ast = this->parseString(code);
|
||||
if (!ast)
|
||||
return {};
|
||||
return std::nullopt;
|
||||
|
||||
this->m_currAST = ast.value();
|
||||
|
||||
auto patterns = this->m_evaluator->evaluate(ast.value());
|
||||
if (!patterns.has_value()) {
|
||||
this->m_currError = this->m_evaluator->getConsole().getLastHardError();
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return patterns;
|
||||
|
||||
@@ -212,7 +212,7 @@ namespace hex::pl {
|
||||
}
|
||||
} catch (PreprocessorError &e) {
|
||||
this->m_error = e;
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace hex::prv {
|
||||
u32 page = std::floor((address - this->getBaseAddress()) / double(PageSize));
|
||||
|
||||
if (page >= this->getPageCount())
|
||||
return {};
|
||||
return std::nullopt;
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user