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