⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uritests.cc

📁 著名的标准C++的html解析器
💻 CC
字号:
#include "Uri.h"#include <getopt.h>#include <string>#include <iostream>#include <vector>using namespace std;using namespace htmlcxx;//#define DEBUG#include "debug.h"#define myassert(x) \	do {\		if(!(x)) {\			fprintf(stderr, "Test at %s:%d failed!\n", __FILE__, __LINE__);\			exit(1);\		}\	} while(0)void usage(const char *prg) {	cerr << "usage: " <<  prg << " [-d maxdepth] uri1 [uri2 ...]"  << endl;}int main(int argc, char **argv) {	try 	{		int flags = Uri::REMOVE_WWW_PREFIX | Uri::REMOVE_TRAILING_BAR | Uri::REMOVE_DEFAULT_FILENAMES | Uri::REMOVE_SCHEME;		unsigned int maxDepth = UINT_MAX;		vector<string> tests;		tests.push_back("http://www.slashdot.org");		tests.push_back("http://www.embratel.net.br:80/Embratel02/cda/portal/0,2297,RE_P_371,00.html");		tests.push_back("http://www.embratel.net.br:80/jo鉶.html");		tests.push_back("http://www.embratel.net.br:80/superjo鉶! .html");		while(1) {			signed char c = getopt(argc, argv, "hd:");			if(c == -1) break;			switch(c) {				case 'd':					{ 						char *end;						maxDepth = strtoul(optarg, &end, 10);						if (*end != 0) 						{							usage(argv[0]);							exit(1);						}					}					break;				case 'h':					usage(argv[0]);					exit(0);				default:					usage(argv[0]);					exit(1);			}		}		if(optind < argc) {			for(int i = optind; i < argc; ++i) {				Uri uri(argv[i]);				DEBUGP("Created uri object for %s\n", argv[i]);				cerr << uri.unparse(flags) << endl;				cerr << " -> " << uri.canonicalHostname(maxDepth) <<  endl;			}		} else {			for(unsigned int i = 0; i < tests.size(); ++i) 			{				Uri uri(tests[i].c_str());				DEBUGP("Created uri object\n");				cerr << uri.unparse(flags) << " -> " << uri.canonicalHostname() <<  endl;			}			for (unsigned int i = 0; i < tests.size(); ++i)			{				std::string e = Uri::encode(tests[i]);				cerr << "Encoded: " << e << endl;				cerr << "Decoded: " << Uri::decode(e) << endl;				myassert(Uri::decode(e) == tests[i]);			}		}	} catch (exception &e) {		cerr << e.what() << endl;		exit(1);	} catch (...) {		cerr << "Unknow object thrown" << endl;	}	exit(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -