summaryrefslogtreecommitdiff
path: root/src/url.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/url.h')
-rw-r--r--src/url.h74
1 files changed, 74 insertions, 0 deletions
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 @@
1#ifndef BU_URL_H
2#define BU_URL_H
3
4#include "bu/fstring.h"
5#include "bu/atom.h"
6
7namespace Bu
8{
9 class Url
10 {
11 public:
12 typedef struct Param
13 {
14 Param() { }
15 Param( const Param &r ) : sName( r.sName ), sValue( r.sValue ) { }
16 Param( const Bu::FString &n, const Bu::FString &v ) :
17 sName( n ), sValue( v ) { }
18 Bu::FString sName;
19 Bu::FString sValue;
20 } Param;
21 typedef Bu::List<Param> ParamList;
22
23 public:
24 Url();
25 Url( const Bu::FString &sUrl );
26 virtual ~Url();
27
28 void parseUrl( const Bu::FString &sUrl );
29 void parseParams( Bu::FString::const_iterator &i );
30 void clear();
31
32 Bu::FString getUrl();
33
34 const Bu::FString &getProtocol() { return sProtocol; }
35 const Bu::FString &getUser() { return sUser; }
36 const Bu::FString &getPass() { return sPass; }
37 const Bu::FString &getHost() { return sHost; }
38 const Bu::FString &getPath() { return sPath; }
39 int getPort() { return iPort; }
40 ParamList::const_iterator getParamBegin() { return lParam.begin(); }
41
42 void setProtocol( const Bu::FString &sNewHost, bool bAutoSetPort=true );
43 void setUser( const Bu::FString &s ) { sUser = s; }
44 void setPass( const Bu::FString &s ) { sPass = s; }
45 void setHost( const Bu::FString &s ) { sHost = s; }
46 void setPath( const Bu::FString &s ) { sPath = s; }
47 void setPort( int i ) { iPort = i; }
48 void addParam( const Bu::FString &n, const Bu::FString &v );
49
50 bool hasPort() { return iPort.has(); }
51
52 static Bu::FString decode( const Bu::FString &sStr );
53 static Bu::FString encode( const Bu::FString &sStr );
54
55 private: // Parsing code
56 void parseProtocol( Bu::FString::const_iterator &i );
57 void parseUserPass( Bu::FString::const_iterator &i );
58 void parseHost( Bu::FString::const_iterator &i );
59 void parsePath( Bu::FString::const_iterator &i );
60
61 private:
62 Bu::FString sProtocol;
63 Bu::FString sUser;
64 Bu::FString sPass;
65 Bu::FString sHost;
66 Bu::FString sPath;
67 Bu::Atom<int> iPort;
68 ParamList lParam;
69
70 static char hexcode[16];
71 };
72};
73
74#endif