Make assignment to _max_chars clearer.

This commit is contained in:
tastytea 2020-01-05 20:10:54 +01:00
parent be2f00faae
commit b8802d3674
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07

View File

@ -23,6 +23,7 @@
namespace mastodonpp namespace mastodonpp
{ {
using std::stoull;
using std::move; using std::move;
Instance::Instance(string hostname, string access_token) Instance::Instance(string hostname, string access_token)
@ -38,19 +39,22 @@ Instance::Instance(string hostname, string access_token)
if (answer) if (answer)
{ {
debuglog << "Querying instance for max_toot_chars…\n"; debuglog << "Querying instance for max_toot_chars…\n";
auto &body{answer.body}; _max_chars = [&answer]
size_t pos_start{body.find("max_toot_chars")};
if (pos_start == string::npos)
{ {
debuglog << "max_toot_chars not found."; auto &body{answer.body};
return; size_t pos_start{body.find("max_toot_chars")};
} if (pos_start == string::npos)
pos_start = body.find(':', pos_start) + 1; {
const size_t pos_end{body.find(',', pos_start)}; debuglog << "max_toot_chars not found.\n";
return static_cast<uint64_t>(500);
}
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, const auto max_toot_chars{body.substr(pos_start,
pos_end - pos_start)}; pos_end - pos_start)};
_max_chars = std::stoull(max_toot_chars); return static_cast<uint64_t>(stoull(max_toot_chars));
}();
debuglog << "Set _max_chars to: " << _max_chars << '\n'; debuglog << "Set _max_chars to: " << _max_chars << '\n';
} }
} }