From 3916a50bf9a7b49a77d7c76b1e41a7773a04f53f Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Fri, 18 Dec 2020 01:13:31 -0500 Subject: add prefetch (default off) --- util.hpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'util.hpp') diff --git a/util.hpp b/util.hpp index 2d455c4..3d8ea20 100644 --- a/util.hpp +++ b/util.hpp @@ -184,3 +184,31 @@ inline void AddWidgetMenuHandler(Gtk::Widget *widget, Gtk::Menu &menu) { }, false); // clang-format on } + +inline std::vector StringSplit(const std::string &str, const char *delim) { + std::vector parts; + char *token = std::strtok(const_cast(str.c_str()), delim); + while (token != nullptr) { + parts.push_back(token); + token = std::strtok(nullptr, delim); + } + return parts; +} + +inline std::string GetExtension(std::string url) { + url = StringSplit(url, "?")[0]; + url = StringSplit(url, "/").back(); + return url.find(".") != std::string::npos ? url.substr(url.find_last_of(".")) : ""; +} + +inline bool IsURLViewableImage(const std::string &url) { + const auto ext = GetExtension(url); + static const char *exts[] = { ".jpeg", + ".jpg", + ".png", nullptr }; + const char *str = ext.c_str(); + for (int i = 0; exts[i] != nullptr; i++) + if (strcmp(str, exts[i]) == 0) + return true; + return false; +} -- cgit v1.2.3