1
0
mirror of https://github.com/anope/anope.git synced 2026-06-29 17:56:37 +02:00

Replace convertTo/stringify with non-throwing alternatives.

Having these throw is terrible for ergonomics and there are loads
of places where the exception was either silently ignored or not
handled at all. Having a function which returns an optional and
another that returns a default works a lot better imo.
This commit is contained in:
Sadie Powell
2024-03-11 13:53:05 +00:00
parent e2df7d4d01
commit 29e7674e56
76 changed files with 572 additions and 810 deletions
+24 -17
View File
@@ -38,28 +38,35 @@ struct Rewrite final
else
{
int num = -1, end = -1;
try
Anope::string num_str = token.substr(1);
size_t hy = num_str.find('-');
if (hy == Anope::string::npos)
{
Anope::string num_str = token.substr(1);
size_t hy = num_str.find('-');
if (hy == Anope::string::npos)
{
num = convertTo<int>(num_str);
end = num + 1;
}
auto n = Anope::TryConvert<int>(num_str);
if (!n.has_value())
continue;
num = n.value();
end = num + 1;
}
else
{
auto n = Anope::TryConvert<int>(num_str.substr(0, hy));
if (!n.has_value())
continue;
num = n.value();
if (hy == num_str.length() - 1)
end = params.size();
else
{
num = convertTo<int>(num_str.substr(0, hy));
if (hy == num_str.length() - 1)
end = params.size();
else
end = convertTo<int>(num_str.substr(hy + 1)) + 1;
n = Anope::TryConvert<int>(num_str.substr(hy + 1));
if (!n.has_value())
continue;
end = n.value() + 1;
}
}
catch (const ConvertException &)
{
continue;
}
for (int i = num; i < end && static_cast<unsigned>(i) < params.size(); ++i)
message += " " + params[i];