File: Extensions.cc

package info (click to toggle)
htmlcxx 0.87-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,412 kB
  • sloc: sh: 4,380; cpp: 4,355; yacc: 526; ansic: 205; lex: 159; makefile: 47; perl: 27
file content (42 lines) | stat: -rw-r--r-- 721 bytes parent folder | download | duplicates (8)
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();
}