1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include <cstring>
#include "Extensions.h"
using namespace std;
using namespace htmlcxx;
Extensions::Extensions(const string &exts)
{
const char *begin = exts.c_str();
while (*begin)
{
while (*begin == ' ') ++begin;
if (*begin == 0) break;
const char *end = begin + 1;
while (*end && *end != ' ') ++end;
insert(ci_string(begin, end));
begin = end;
}
}
bool Extensions::check(const string &url)
{
const char *slash;
const char *dot;
const char *question;
question = strchr(url.c_str(), '?');
if (question) return false;
slash = strrchr(url.c_str(), '/');
dot = strrchr(url.c_str(), '.');
if (slash >= dot) return false;
ci_string ext(dot);
return mExts.find(ext) != mExts.end();
}
|