diff options
Diffstat (limited to 'src/NetUtils.cpp')
-rw-r--r-- | src/NetUtils.cpp | 28 |
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 |