diff options
author | tastytea | 2020-01-14 20:44:08 +0100 |
---|---|---|
committer | tastytea | 2020-01-14 20:44:08 +0100 |
commit | a8e342202d7f429446a7193fc86ccbc0d0438820 (patch) | |
tree | 64dac8952eefefee783446b5ec0a9fb42626e31a /src | |
parent | bd490e788cbe17c86777e353f815d1a573163ba5 (diff) | |
download | mastodonpp-a8e342202d7f429446a7193fc86ccbc0d0438820.tar mastodonpp-a8e342202d7f429446a7193fc86ccbc0d0438820.tar.gz mastodonpp-a8e342202d7f429446a7193fc86ccbc0d0438820.zip |
Move types into types.hpp and add answer_type::next() and prev().
Diffstat (limited to 'src')
-rw-r--r-- | src/instance.cpp | 1 | ||||
-rw-r--r-- | src/types.cpp (renamed from src/answer.cpp) | 39 |
2 files changed, 38 insertions, 2 deletions
diff --git a/src/instance.cpp b/src/instance.cpp index cd99645..5e9126d 100644 --- a/src/instance.cpp +++ b/src/instance.cpp @@ -14,7 +14,6 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "answer.hpp" #include "instance.hpp" #include "log.hpp" diff --git a/src/answer.cpp b/src/types.cpp index 0db9176..8c4575c 100644 --- a/src/answer.cpp +++ b/src/types.cpp @@ -14,7 +14,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "answer.hpp" +#include "log.hpp" +#include "types.hpp" #include <algorithm> #include <cctype> @@ -60,4 +61,40 @@ string_view answer_type::get_header(const string_view field) const return {}; } +parametermap answer_type::parse_pagination(const bool next) const +{ + const string_view link{get_header("Link")}; + if (link.empty()) + { + return {}; + } + + const auto direction{next ? R"(rel="next")" : R"(rel="prev")"}; + auto endpos{link.find(direction)}; + endpos = link.rfind('>', endpos); + auto startpos{link.rfind('?', endpos) + 1}; + const string_view paramstr{link.substr(startpos, endpos - startpos)}; + debuglog << "Found parameters in Link header: " << paramstr << '\n'; + + startpos = 0; + parametermap parameters; + while ((endpos = paramstr.find('=', startpos)) != string_view::npos) + { + parameterpair param; + param.first = paramstr.substr(startpos, endpos - startpos); + startpos = endpos + 1; + endpos = paramstr.find('&', startpos); + param.second = paramstr.substr(startpos, endpos - startpos); + parameters.insert(param); + + if (endpos == string_view::npos) + { + break; + } + startpos = endpos + 1; + } + + return parameters; +} + } // namespace mastodonpp |