From 366a8063730aa7ae696bcb9cf56eafd13d43dfc0 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 8 Feb 2009 00:44:10 +0000 Subject: So many updates. I recommend using the new FString iterators instead of direct indexing. It is now many times faster, and requires less overhead. Also, more stuff iterator related in every class. More on that later. --- src/url.h | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/url.h (limited to 'src/url.h') diff --git a/src/url.h b/src/url.h new file mode 100644 index 0000000..861bb9f --- /dev/null +++ b/src/url.h @@ -0,0 +1,74 @@ +#ifndef BU_URL_H +#define BU_URL_H + +#include "bu/fstring.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::FString &n, const Bu::FString &v ) : + sName( n ), sValue( v ) { } + Bu::FString sName; + Bu::FString sValue; + } Param; + typedef Bu::List ParamList; + + public: + Url(); + Url( const Bu::FString &sUrl ); + virtual ~Url(); + + void parseUrl( const Bu::FString &sUrl ); + void parseParams( Bu::FString::const_iterator &i ); + void clear(); + + Bu::FString getUrl(); + + const Bu::FString &getProtocol() { return sProtocol; } + const Bu::FString &getUser() { return sUser; } + const Bu::FString &getPass() { return sPass; } + const Bu::FString &getHost() { return sHost; } + const Bu::FString &getPath() { return sPath; } + int getPort() { return iPort; } + ParamList::const_iterator getParamBegin() { return lParam.begin(); } + + void setProtocol( const Bu::FString &sNewHost, bool bAutoSetPort=true ); + void setUser( const Bu::FString &s ) { sUser = s; } + void setPass( const Bu::FString &s ) { sPass = s; } + void setHost( const Bu::FString &s ) { sHost = s; } + void setPath( const Bu::FString &s ) { sPath = s; } + void setPort( int i ) { iPort = i; } + void addParam( const Bu::FString &n, const Bu::FString &v ); + + bool hasPort() { return iPort.has(); } + + static Bu::FString decode( const Bu::FString &sStr ); + static Bu::FString encode( const Bu::FString &sStr ); + + private: // Parsing code + void parseProtocol( Bu::FString::const_iterator &i ); + void parseUserPass( Bu::FString::const_iterator &i ); + void parseHost( Bu::FString::const_iterator &i ); + void parsePath( Bu::FString::const_iterator &i ); + + private: + Bu::FString sProtocol; + Bu::FString sUser; + Bu::FString sPass; + Bu::FString sHost; + Bu::FString sPath; + Bu::Atom iPort; + ParamList lParam; + + static char hexcode[16]; + }; +}; + +#endif -- cgit v1.2.3