diff --git a/include/fc/url.hpp b/include/fc/url.hpp new file mode 100644 index 0000000..a1bfc91 --- /dev/null +++ b/include/fc/url.hpp @@ -0,0 +1,40 @@ +#pragma once +#include +#include +#include + +namespace fc { + + typedef fc::optional ostring; + + struct url { + url(){} + url( const string& url ); + /* + url( const url& u ); + + url( url&& u ); + url& operator=(url&& c); + url& operator=(const url& c); + */ + + operator string()const { return to_string(); } + string to_string()const; + url& from_string( const string& s ); + + bool operator==( const url& cmp )const; + + string proto; // file, ssh, tcp, http, ssl, etc... + ostring host; + ostring user; + ostring pass; + ostring path; + ostring args; + fc::optional port; + }; + +} // namespace fc + +#include +FC_REFLECT( fc::url, (proto)(host)(user)(pass)(path)(args)(port) ) + diff --git a/src/url.cpp b/src/url.cpp new file mode 100644 index 0000000..32208f1 --- /dev/null +++ b/src/url.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include + +namespace fc { + +// url::url( const url& u ); +#if 0 + url::url( url&& u ) + :proto(fc::move(u.proto)), + host(fc::move(u.host)), + user(fc::move(u.user)), + pass(fc::move(u.pass)), + path(fc::move(u.path)), + args(fc::move(u.args)), + port(u.port){} + + url& url::operator=(url&& c) + { + fc::swap(*this,c); + return *this; + } + + // url::url& operator=(const url& c) { + // } +#endif + url::url( const string& s ) { + from_string(s); + } + string url::to_string()const { + fc::stringstream ss; + ss<( host_port.substr( pos+1 ) ); + } catch ( ... ) { + FC_THROW_REPORT( "Unable to parse port field in url", value().set( "url", s ) ); + } + host = host_port.substr(0,pos); + } else { + host = fc::move(host_port); + } + fc::getline( ss, _path, '?' ); + fc::getline( ss, _args ); + path = fc::move(_path); + if( _args.size() ) args = fc::move(_args); + + return *this; + } + + bool url::operator==( const url& cmp )const { + return cmp.proto == proto && + cmp.host == host && + cmp.user == user && + cmp.pass == pass && + cmp.path == path && + cmp.args == args && + cmp.port == port; + } + +} // namespace fc