From 469bbcf0701e1eb8a6670c23145b0da87357e178 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 25 Mar 2012 20:00:08 +0000 Subject: Code is all reorganized. We're about ready to release. I should write up a little explenation of the arrangement. --- src/unstable/url.h | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/unstable/url.h (limited to 'src/unstable/url.h') diff --git a/src/unstable/url.h b/src/unstable/url.h new file mode 100644 index 0000000..d751578 --- /dev/null +++ b/src/unstable/url.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2007-2011 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#ifndef BU_URL_H +#define BU_URL_H + +#include "bu/string.h" +#include "bu/atom.h" + +namespace Bu +{ + class Url + { + public: + typedef struct Param + { + Param() { } + Param( const Param &r ) : sName( r.sName ), sValue( r.sValue ) { } + Param( const Bu::String &n, const Bu::String &v ) : + sName( n ), sValue( v ) { } + Bu::String sName; + Bu::String sValue; + } Param; + typedef Bu::List ParamList; + + public: + Url(); + Url( const Bu::String &sUrl ); + virtual ~Url(); + + void parseUrl( const Bu::String &sUrl ); + void parseParams( const Bu::String &sQuery ); + void parseParams( Bu::String::const_iterator &i ); + void parsePath( const Bu::String &sPath ); + void parsePath( Bu::String::const_iterator &i ); + void clear(); + + Bu::String getUrl() const; + Bu::String getFullPath() const; + + const Bu::String &getProtocol() const { return sProtocol; } + const Bu::String &getUser() const { return sUser; } + const Bu::String &getPass() const { return sPass; } + const Bu::String &getHost() const { return sHost; } + const Bu::String &getPath() const { return sPath; } + int getPort() const { return iPort; } + ParamList::const_iterator getParamBegin() const + { return lParam.begin(); } + + void setProtocol( const Bu::String &sNewHost, bool bAutoSetPort=true ); + void setUser( const Bu::String &s ) { sUser = s; } + void setPass( const Bu::String &s ) { sPass = s; } + void setHost( const Bu::String &s ) { sHost = s; } + void setPath( const Bu::String &s ) { sPath = s; } + void setPort( int i ) { iPort = i; } + void addParam( const Bu::String &n, const Bu::String &v ); + + bool hasPort() const { return iPort.has(); } + + static Bu::String decode( const Bu::String &sStr ); + static Bu::String encode( const Bu::String &sStr ); + + private: // Parsing code + void parseProtocol( Bu::String::const_iterator &i ); + void parseUserPass( Bu::String::const_iterator &i ); + void parseHost( Bu::String::const_iterator &i ); + + private: + Bu::String sProtocol; + Bu::String sUser; + Bu::String sPass; + Bu::String sHost; + Bu::String sPath; + Bu::Atom iPort; + ParamList lParam; + + static char hexcode[16]; + }; +}; + +#endif -- cgit v1.2.3