mario-dns/funcs.cpp

36 lines
921 B
C++

#include "funcs.h"
#include "HTTPheaders.h"
QString http::HTML_PAGE;
void funcs::createHtmlPage(bool no_favicon)
{
http::HTML_PAGE = http::HTML_PAGE_SRC_1;
if (no_favicon) {
http::HTML_PAGE += http::NO_FAVICON;
} else {
http::HTML_PAGE += http::FAVICON;
}
http::HTML_PAGE += http::HTML_PAGE_SRC_2;
}
QString funcs::getValue(const QString &string, const QString &key)
{
if (key.isEmpty())
return QString();
const QString keyPattern = key + "=";
size_t valueStart = string.indexOf(keyPattern);
if (valueStart == std::string::npos) {
return QString();
}
valueStart += keyPattern.length();
size_t valueEnd = string.indexOf(' ', valueStart);
if (valueEnd == std::string::npos) {
valueEnd = string.size();
}
std::string result = string.toStdString().substr(valueStart, valueEnd - valueStart);
return result.c_str();
}