]> git.saurik.com Git - wxWidgets.git/blob - include/wx/uri.h
473ab42e1bd70cc5d401acb50871f0b64f5137fa
[wxWidgets.git] / include / wx / uri.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: uri.h
3 // Purpose: wxURI - Class for parsing URIs
4 // Author: Ryan Norton
5 // Modified By:
6 // Created: 07/01/2004
7 // RCS-ID: $Id$
8 // Licence: wxWindows
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_URI_H_
12 #define _WX_URI_H_
13
14 #if defined(__GNUG__) && !defined(__APPLE__)
15 #pragma interface "uri.h"
16 #endif
17
18 #include "wx/defs.h"
19 #include "wx/object.h"
20 #include "wx/string.h"
21
22 // Host Type that the server can be
23 enum wxURIHostType
24 {
25 wxURI_REGNAME,
26 wxURI_IPV4ADDRESS,
27 wxURI_IPV6ADDRESS,
28 wxURI_IPVFUTURE
29 };
30
31 // Component Flags
32 enum wxURIFieldType
33 {
34 wxURI_SCHEME = 1,
35 wxURI_USER = 2,
36 wxURI_SERVER = 4,
37 wxURI_PORT = 8,
38 wxURI_PATH = 16,
39 wxURI_QUERY = 32,
40 wxURI_FRAGMENT = 64
41 };
42
43 // Miscellaneous other flags
44 enum wxURIFlags
45 {
46 wxURI_STRICT = 1
47 };
48
49
50 // Generic class for parsing URIs.
51 //
52 // Originally based off of RFC 2396 - then
53 // extended to meet the newer RFC 2396.bis
54 // specifications.
55 class wxURI : public wxObject
56 {
57 public:
58 wxURI();
59 wxURI(const wxString& uri);
60 wxURI(const wxURI& uri);
61
62 virtual ~wxURI();
63
64 void Create(const wxString& uri);
65
66 bool HasScheme() const { return (m_fields & wxURI_SCHEME) == wxURI_SCHEME; }
67 bool HasUser() const { return (m_fields & wxURI_USER) == wxURI_USER; }
68 bool HasServer() const { return (m_fields & wxURI_SERVER) == wxURI_SERVER; }
69 bool HasPort() const { return (m_fields & wxURI_PORT) == wxURI_PORT; }
70 bool HasPath() const { return (m_fields & wxURI_PATH) == wxURI_PATH; }
71 bool HasQuery() const { return (m_fields & wxURI_QUERY) == wxURI_QUERY; }
72 bool HasFragment() const { return (m_fields & wxURI_FRAGMENT) == wxURI_FRAGMENT; }
73
74 const wxString& GetScheme() const { return m_scheme; }
75 const wxString& GetPath() const { return m_path; }
76 const wxString& GetQuery() const { return m_query; }
77 const wxString& GetFragment() const { return m_fragment; }
78 const wxString& GetPort() const { return m_port; }
79 const wxString& GetUser() const { return m_user; }
80 const wxString& GetServer() const { return m_server; }
81 const wxURIHostType& GetHostType() const { return m_hostType; }
82
83 wxString Get() const;
84
85 void Resolve(const wxURI& base, int flags = wxURI_STRICT);
86 bool IsReference() const;
87
88 wxURI& operator = (const wxURI& uri);
89 wxURI& operator = (const wxString& string);
90 bool operator == (const wxURI& uri) const;
91
92 protected:
93 wxURI& Assign(const wxURI& uri);
94
95 void Clear();
96
97 const wxChar* Parse (const wxChar* uri);
98 const wxChar* ParseAuthority (const wxChar* uri);
99 const wxChar* ParseScheme (const wxChar* uri);
100 const wxChar* ParseUser (const wxChar* uri);
101 const wxChar* ParseServer (const wxChar* uri);
102 const wxChar* ParsePort (const wxChar* uri);
103 const wxChar* ParsePath (const wxChar* uri,
104 bool bReference = false,
105 bool bNormalize = true);
106 const wxChar* ParseQuery (const wxChar* uri);
107 const wxChar* ParseFragment (const wxChar* uri);
108
109
110 static bool ParseH16(const wxChar*& uri);
111 static bool ParseIPv4address(const wxChar*& uri);
112 static bool ParseIPv6address(const wxChar*& uri);
113 static bool ParseIPvFuture(const wxChar*& uri);
114
115
116 static void Normalize(wxChar* uri, bool bIgnoreLeads = false);
117 static void UpTree(const wxChar* uristart, const wxChar*& uri);
118
119 static wxChar Unescape(const wxChar* s);
120 static void Escape (wxString& s, const wxChar& c);
121 static bool IsEscape(const wxChar*& uri);
122
123 static int CharToHex(const wxChar& c);
124
125
126 static bool IsUnreserved (const wxChar& c);
127 static bool IsReserved (const wxChar& c);
128 static bool IsGenDelim (const wxChar& c);
129 static bool IsSubDelim (const wxChar& c);
130 static bool IsHex(const wxChar& c);
131 static bool IsAlpha(const wxChar& c);
132 static bool IsDigit(const wxChar& c);
133
134 wxString m_scheme;
135 wxString m_path;
136 wxString m_query;
137 wxString m_fragment;
138
139 wxString m_user;
140 wxString m_server;
141 wxString m_port;
142
143 wxURIHostType m_hostType;
144
145 size_t m_fields;
146
147 DECLARE_DYNAMIC_CLASS(wxURI)
148 };
149
150 #endif // _WX_URI_H_
151