summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortastytea2020-01-14 21:03:04 +0100
committertastytea2020-01-14 21:03:04 +0100
commit223db7b2555958e37ab149303e05e5d54edd81bc (patch)
treed14ba079174136ef4856decd6484568b0bacd246
parentaafb55e7eb9061fa393a029f82d5322e961d0ce4 (diff)
downloadmastodonpp-223db7b2555958e37ab149303e05e5d54edd81bc.tar
mastodonpp-223db7b2555958e37ab149303e05e5d54edd81bc.tar.gz
mastodonpp-223db7b2555958e37ab149303e05e5d54edd81bc.zip
Use regex to extract max_toot_chars.
-rw-r--r--src/instance.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/instance.cpp b/src/instance.cpp
index 5e9126d..7b1d5c1 100644
--- a/src/instance.cpp
+++ b/src/instance.cpp
@@ -53,19 +53,16 @@ uint64_t Instance::get_max_chars() noexcept
_max_chars = [&answer]
{
- auto &body{answer.body};
- size_t pos_start{body.find("max_toot_chars")};
- if (pos_start == string::npos)
+ const regex re_chars{R"("max_toot_chars"\s*:\s*([^"]+))"};
+ smatch match;
+
+ if (regex_search(answer.body, match, re_chars))
{
- debuglog << "max_toot_chars not found.\n";
- return default_max_chars;
+ return static_cast<uint64_t>(stoull(match[1].str()));
}
- 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,
- pos_end - pos_start)};
- return static_cast<uint64_t>(stoull(max_toot_chars));
+ debuglog << "max_toot_chars not found.\n";
+ return default_max_chars;
}();
debuglog << "Set _max_chars to: " << _max_chars << '\n';
}