Use regex to extract max_toot_chars.
This commit is contained in:
parent
aafb55e7eb
commit
223db7b255
|
@ -53,19 +53,16 @@ uint64_t Instance::get_max_chars() noexcept
|
||||||
|
|
||||||
_max_chars = [&answer]
|
_max_chars = [&answer]
|
||||||
{
|
{
|
||||||
auto &body{answer.body};
|
const regex re_chars{R"("max_toot_chars"\s*:\s*([^"]+))"};
|
||||||
size_t pos_start{body.find("max_toot_chars")};
|
smatch match;
|
||||||
if (pos_start == string::npos)
|
|
||||||
{
|
|
||||||
debuglog << "max_toot_chars not found.\n";
|
|
||||||
return default_max_chars;
|
|
||||||
}
|
|
||||||
pos_start = body.find(':', pos_start) + 1;
|
|
||||||
const size_t pos_end{body.find(',', pos_start)};
|
|
||||||
|
|
||||||
const auto max_toot_chars{body.substr(pos_start,
|
if (regex_search(answer.body, match, re_chars))
|
||||||
pos_end - pos_start)};
|
{
|
||||||
return static_cast<uint64_t>(stoull(max_toot_chars));
|
return static_cast<uint64_t>(stoull(match[1].str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
debuglog << "max_toot_chars not found.\n";
|
||||||
|
return default_max_chars;
|
||||||
}();
|
}();
|
||||||
debuglog << "Set _max_chars to: " << _max_chars << '\n';
|
debuglog << "Set _max_chars to: " << _max_chars << '\n';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user