aboutsummaryrefslogtreecommitdiff
path: root/src/NetUtils.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-05-10 18:49:44 +0200
committerdec05eba <dec05eba@protonmail.com>2021-05-10 22:41:04 +0200
commitcdf8d103f1ed6a932eb30b589b578d23ca66a514 (patch)
tree0782751764748be50c4203b8e1af14907046e3d2 /src/NetUtils.cpp
parent2eac1e3d3ece90d1c522e15cb57ee41baa3dd822 (diff)
Add downloader, fix room navigation lag
Fix bug where getting next page fails if there is no search bar
Diffstat (limited to 'src/NetUtils.cpp')
-rw-r--r--src/NetUtils.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/NetUtils.cpp b/src/NetUtils.cpp
index 3539d46..dc7c2d2 100644
--- a/src/NetUtils.cpp
+++ b/src/NetUtils.cpp
@@ -4,6 +4,7 @@
#include <sstream>
#include <iomanip>
#include <assert.h>
+#include <string.h>
#include <unordered_set>
namespace QuickMedia {
@@ -1742,4 +1743,31 @@ namespace QuickMedia {
++num_codepoints;
}
}
+
+ std::string header_extract_value(const std::string &header, const std::string &type) {
+ std::string result;
+ string_split(header, '\n', [&type, &result](const char *str, size_t size) {
+ while(size > 0 && (*str == ' ' || *str == '\t')) { ++str; --size; }
+ if(size < type.size() || strncasecmp(str, type.c_str(), type.size()) != 0 || size == type.size())
+ return true;
+
+ str += type.size();
+ size -= type.size();
+
+ const void *colon_ptr = memchr(str, ':', size);
+ if(!colon_ptr)
+ return true;
+
+ const size_t colon_offset = (const char*)colon_ptr - str;
+ str += (colon_offset + 1);
+ size -= (colon_offset + 1);
+
+ while(size > 0 && (*str == ' ' || *str == '\t')) { ++str; --size; }
+ while(size > 0 && (str[size - 1] == ' ' || str[size - 1] == '\t' || str[size - 1] == '\r' || str[size - 1] == '\n')) { --size; }
+
+ result.assign(str, size);
+ return false;
+ });
+ return result;
+ }
} \ No newline at end of file