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

📄 test_url.cc

📁 liburl是一个小的C++库
💻 CC
字号:
#include <string>#include <iostream>#include <url/url_string.hh>#include <vector>#include <stdexcept>void display_url(const url_string& url)	{	std::cout << "original:    " << url.get_original() << std::endl;	if(url.get_referrer().size()!=0) {		std::cout << "referrer:    " 					 << url_string(url.get_referrer()).get_url() << std::endl;		}	std::cout << "relative:    " << url.get_relative_path() << std::endl		  << "url:         " << url.get_url() << std::endl		  << "object:      " << url.get_object() << std::endl		  << "["<<url.get_scheme()<<"]"		  << "//["<<url.get_username()<<"]"		  << ":["<<url.get_passwd()<<"]"		  << "@["<<url.get_net_path()<<"]"		  << ":["<<url.get_port()<<"]"		  << "["<<url.get_absolute_path()<<"]"		  << ";["<<url.get_parameters()<<"]"		  << "?["<<url.get_query()<<"]"		  << "#["<<url.get_fragment()<<"]" << std::endl		  << "-----" << std::endl << std::endl;	}int main(int argc, char *argv[]) 	{	try {		std::string urlstr,refstr;				refstr=urlstr="scheme://user:pass@host:999/path/file;param?query#fragment";		url_string url1(urlstr);		std::cout << urlstr << std::endl;		display_url(url1);		urlstr="/path2/file2";		url_string url2(urlstr,url1);		std::cout << urlstr << " " << refstr << std::endl;		display_url(url2);				urlstr="path3/file3";		url2=url_string(urlstr,url1);		std::cout << urlstr << " " << refstr << std::endl;		display_url(url2);				urlstr="file4";		url2=url_string(urlstr, url1);		std::cout << urlstr << " " << refstr << std::endl;		display_url(url2);				urlstr="//host2";		url2=url_string(urlstr, url1);		std::cout<<urlstr<<" "<<refstr<<std::endl;		display_url(url2);				urlstr="#fragment2";		url2=url_string(urlstr, url1);		std::cout << urlstr << " " << refstr << std::endl;		display_url(url2);				urlstr="?query2";		url2=url_string(urlstr, url1);		std::cout << urlstr << " " << refstr << std::endl;		display_url(url2);				urlstr=";param2";		url2=url_string(urlstr, url1);		std::cout << urlstr << " " << refstr << std::endl;		display_url(url2);				urlstr="http://scheme://host/path/file #chap1";		url1=url_string(urlstr);		std::cout << urlstr << std::endl;		display_url(url1);				urlstr="http://host.at.net/./path";		url1=url_string(urlstr);		std::cout << urlstr << std::endl;		display_url(url1);		// Correct: Should work properly		urlstr="http://www.google.com/";		url1=url_string(urlstr);		url2=url_string("/some/relative/url", url1);		url_string url3("one/final/relative/url", url2);		display_url(url3);		bool exception_caught = false;		try {			// Error: Should throw an exception (no referrer)			urlstr="www.google.com";			url1=url_string(urlstr);			std::cout << urlstr << std::endl;			display_url(url1);			}		catch ( std::logic_error& ex ) {			exception_caught = true;			}				if ( ! exception_caught )			throw std::logic_error( "An exception was expected but not caught" );		}	catch(std::exception& ex) {		std::cerr << "exception: " << ex.what() << std::endl;		}	}

⌨️ 快捷键说明

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