1
0
mirror of synced 2024-11-24 15:50:16 +01:00

patterns: Added parse_int and parse_float functions

This commit is contained in:
WerWolv 2021-09-26 02:23:10 +02:00
parent aab865fe25
commit e3dd5900e2

View File

@ -213,6 +213,21 @@ namespace hex::plugin::builtin {
return string.substr(pos, size);
});
/* parse_int(string, base) */
ContentRegistry::PatternLanguageFunctions::add(nsStdString, "parse_int", 2, [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
auto string = Token::literalToString(params[0], false);
auto base = Token::literalToUnsigned(params[1]);
return s128(std::strtoll(string.c_str(), nullptr, base));
});
/* parse_float(string) */
ContentRegistry::PatternLanguageFunctions::add(nsStdString, "parse_float", 1, [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
auto string = Token::literalToString(params[0], false);
return double(std::strtod(string.c_str(), nullptr));
});
}
ContentRegistry::PatternLanguageFunctions::Namespace nsStdHttp = { "std", "http" };