summaryrefslogtreecommitdiff
path: root/util.hpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2020-12-18 01:13:31 -0500
committerouwou <26526779+ouwou@users.noreply.github.com>2020-12-18 01:13:31 -0500
commit3916a50bf9a7b49a77d7c76b1e41a7773a04f53f (patch)
treefaa5decb5593b27686c7c1d4ff1c37305d634b1f /util.hpp
parent776c350eb654c78a21a6163dcc82d802039c76e6 (diff)
downloadabaddon-portaudio-3916a50bf9a7b49a77d7c76b1e41a7773a04f53f.tar.gz
abaddon-portaudio-3916a50bf9a7b49a77d7c76b1e41a7773a04f53f.zip
add prefetch (default off)
Diffstat (limited to 'util.hpp')
-rw-r--r--util.hpp28
1 files changed, 28 insertions, 0 deletions
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<std::string> StringSplit(const std::string &str, const char *delim) {
+ std::vector<std::string> parts;
+ char *token = std::strtok(const_cast<char *>(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;
+}