diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-03-03 14:24:42 +0000 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-03-03 16:06:38 +0000 | 
| commit | 49f76accd0a128d37d7ca0886669cfce7cb13bda (patch) | |
| tree | ac80f2ac58017ee6aff97d909f9e298799878424 | |
| parent | Bump to C++17 (diff) | |
| download | icespider-49f76accd0a128d37d7ca0886669cfce7cb13bda.tar.bz2 icespider-49f76accd0a128d37d7ca0886669cfce7cb13bda.tar.xz icespider-49f76accd0a128d37d7ca0886669cfce7cb13bda.zip | |
Replace string/char* quirks with string_view
| -rw-r--r-- | icespider/fcgi/cgiRequest.cpp | 2 | ||||
| -rw-r--r-- | icespider/fcgi/cgiRequestBase.cpp | 33 | ||||
| -rw-r--r-- | icespider/fcgi/cgiRequestBase.h | 9 | 
3 files changed, 22 insertions, 22 deletions
| diff --git a/icespider/fcgi/cgiRequest.cpp b/icespider/fcgi/cgiRequest.cpp index ac61edc..d0c4c83 100644 --- a/icespider/fcgi/cgiRequest.cpp +++ b/icespider/fcgi/cgiRequest.cpp @@ -11,7 +11,7 @@ namespace IceSpider {  	}  	std::istream & -		CgiRequest::getInputStream() const +	CgiRequest::getInputStream() const  	{  		return std::cin;  	} diff --git a/icespider/fcgi/cgiRequestBase.cpp b/icespider/fcgi/cgiRequestBase.cpp index 74f1d1f..0159fcd 100644 --- a/icespider/fcgi/cgiRequestBase.cpp +++ b/icespider/fcgi/cgiRequestBase.cpp @@ -16,7 +16,16 @@ namespace std {  	}  } +#define CGI_CONST(NAME) static const std::string_view NAME(#NAME) +  namespace IceSpider { +	static const std::string HEADER_PREFIX("HTTP_"); +	CGI_CONST(REDIRECT_URL); +	CGI_CONST(SCRIPT_NAME); +	CGI_CONST(QUERY_STRING); +	CGI_CONST(HTTP_COOKIE); +	CGI_CONST(REQUEST_METHOD); +  	CgiRequestBase::CgiRequestBase(Core * c, char ** env) :  		IHttpRequest(c)  	{ @@ -44,21 +53,21 @@ namespace IceSpider {  	CgiRequestBase::initialize()  	{  		namespace ba = boost::algorithm; -		auto path = (optionalLookup("REDIRECT_URL", envmap) / -			[this]() { return optionalLookup("SCRIPT_NAME", envmap); } / +		auto path = (optionalLookup(REDIRECT_URL, envmap) / +			[this]() { return optionalLookup(SCRIPT_NAME, envmap); } /  			[this]() -> std::string { throw std::runtime_error("Couldn't determine request path"); })  			.substr(1);  		if (!path.empty()) {  			ba::split(pathElements, path, ba::is_any_of("/"), ba::token_compress_off);  		} -		auto qs = envmap.find("QUERY_STRING"); +		auto qs = envmap.find(QUERY_STRING);  		if (qs != envmap.end()) {  			XWwwFormUrlEncoded::iterateVars(*qs->second, [this](auto k, auto v) {  				qsmap.insert({ k, v });  			}, "&");  		} -		auto cs = envmap.find("HTTP_COOKIE"); +		auto cs = envmap.find(HTTP_COOKIE);  		if (cs != envmap.end()) {  			XWwwFormUrlEncoded::iterateVars(*cs->second, [this](auto k, auto v) {  				cookiemap.insert({ k, v }); @@ -91,9 +100,9 @@ namespace IceSpider {  	}  	OptionalString -	CgiRequestBase::optionalLookup(const std::string & key, const VarMap & vm) +	CgiRequestBase::optionalLookup(const std::string_view & key, const VarMap & vm)  	{ -		auto i = vm.find(key.c_str()); +		auto i = vm.find(key);  		if (i == vm.end()) {  			return IceUtil::None;  		} @@ -103,7 +112,7 @@ namespace IceSpider {  	OptionalString  	CgiRequestBase::optionalLookup(const std::string & key, const StringMap & vm)  	{ -		auto i = vm.find(key.c_str()); +		auto i = vm.find(key);  		if (i == vm.end()) {  			return IceUtil::None;  		} @@ -126,7 +135,7 @@ namespace IceSpider {  	CgiRequestBase::getRequestMethod() const  	{  		try { -			auto i = envmap.find("REQUEST_METHOD"); +			auto i = envmap.find(REQUEST_METHOD);  			return Slicer::ModelPartForEnum<HttpMethod>::lookup(*i->second);  		}  		catch (const Slicer::InvalidEnumerationSymbol &) { @@ -155,7 +164,7 @@ namespace IceSpider {  	OptionalString  	CgiRequestBase::getHeaderParam(const std::string & key) const  	{ -		return optionalLookup(("HTTP_" + boost::algorithm::to_upper_copy(key)).c_str(), envmap); +		return optionalLookup(HEADER_PREFIX + boost::algorithm::to_upper_copy(key), envmap);  	}  	void @@ -198,11 +207,5 @@ namespace IceSpider {  	{  		HdrFmt::write(getOutputStream(), header, value);  	} - -	bool -	CgiRequestBase::cmp_str::operator()(char const * a, char const * b) const -	{ -		return std::strcmp(a, b) < 0; -	}  } diff --git a/icespider/fcgi/cgiRequestBase.h b/icespider/fcgi/cgiRequestBase.h index 808dd35..4cc6a81 100644 --- a/icespider/fcgi/cgiRequestBase.h +++ b/icespider/fcgi/cgiRequestBase.h @@ -5,21 +5,18 @@  #include <ihttpRequest.h>  #include <map>  #include <tuple> +#include <string_view>  namespace IceSpider {  	class CgiRequestBase : public IHttpRequest {  		protected: -			struct cmp_str { -				bool operator()(char const *a, char const *b) const; -			}; -  			CgiRequestBase(Core * c, char ** env);  			void addenv(char *);  			void initialize();  		public:  			typedef std::tuple<char *, char *> Env; -			typedef std::map<const char *, Env, cmp_str> VarMap; +			typedef std::map<std::string_view, Env> VarMap;  			const PathElements & getRequestPath() const override;  			PathElements & getRequestPath() override; @@ -39,7 +36,7 @@ namespace IceSpider {  			std::ostream & dump(std::ostream & s) const override;  		private: -			static OptionalString optionalLookup(const std::string & key, const VarMap &); +			static OptionalString optionalLookup(const std::string_view & key, const VarMap &);  			static OptionalString optionalLookup(const std::string & key, const StringMap &);  			VarMap envmap; | 
