]> git.saurik.com Git - wxWidgets.git/blob - include/wx/uri.h
assert that wxRound() argument is in the supported range
[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 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_URI_H_
13 #define _WX_URI_H_
14
15 #include "wx/defs.h"
16 #include "wx/object.h"
17 #include "wx/string.h"
18
19 // Host Type that the server component can be
20 enum wxURIHostType
21 {
22 wxURI_REGNAME, // Host is a normal register name (www.mysite.com etc.)
23 wxURI_IPV4ADDRESS, // Host is a version 4 ip address (192.168.1.100)
24 wxURI_IPV6ADDRESS, // Host is a version 6 ip address [aa:aa:aa:aa::aa:aa]:5050
25 wxURI_IPVFUTURE // Host is a future ip address (wxURI is unsure what kind)
26 };
27
28 // Component Flags
29 enum wxURIFieldType
30 {
31 wxURI_SCHEME = 1,
32 wxURI_USERINFO = 2,
33 wxURI_SERVER = 4,
34 wxURI_PORT = 8,
35 wxURI_PATH = 16,
36 wxURI_QUERY = 32,
37 wxURI_FRAGMENT = 64
38 };
39
40 // Miscellaneous other flags
41 enum wxURIFlags
42 {
43 wxURI_STRICT = 1
44 };
45
46
47 // Generic class for parsing URIs.
48 //
49 // See RFC 3986
50 class WXDLLIMPEXP_BASE wxURI : public wxObject
51 {
52 public:
53 wxURI();
54 wxURI(const wxString& uri);
55 wxURI(const wxURI& uri);
56
57 virtual ~wxURI();
58
59 const wxChar* Create(const wxString& uri);
60
61 bool HasScheme() const { return (m_fields & wxURI_SCHEME) == wxURI_SCHEME; }
62 bool HasUserInfo() const { return (m_fields & wxURI_USERINFO) == wxURI_USERINFO; }
63 bool HasServer() const { return (m_fields & wxURI_SERVER) == wxURI_SERVER; }
64 bool HasPort() const { return (m_fields & wxURI_PORT) == wxURI_PORT; }
65 bool HasPath() const { return (m_fields & wxURI_PATH) == wxURI_PATH; }
66 bool HasQuery() const { return (m_fields & wxURI_QUERY) == wxURI_QUERY; }
67 bool HasFragment() const { return (m_fields & wxURI_FRAGMENT) == wxURI_FRAGMENT; }
68
69 const wxString& GetScheme() const { return m_scheme; }
70 const wxString& GetPath() const { return m_path; }
71 const wxString& GetQuery() const { return m_query; }
72 const wxString& GetFragment() const { return m_fragment; }
73 const wxString& GetPort() const { return m_port; }
74 const wxString& GetUserInfo() const { return m_userinfo; }
75 const wxString& GetServer() const { return m_server; }
76 const wxURIHostType& GetHostType() const { return m_hostType; }
77
78 //Note that the following two get functions are explicitly depreciated by RFC 2396
79 wxString GetUser() const;
80 wxString GetPassword() const;
81
82 wxString BuildURI() const;
83 wxString BuildUnescapedURI() 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 static wxString Unescape (const wxString& szEscapedURI);
93
94 protected:
95 wxURI& Assign(const wxURI& uri);
96
97 void Clear();
98
99 const wxChar* Parse (const wxChar* uri);
100 const wxChar* ParseAuthority (const wxChar* uri);
101 const wxChar* ParseScheme (const wxChar* uri);
102 const wxChar* ParseUserInfo (const wxChar* uri);
103 const wxChar* ParseServer (const wxChar* uri);
104 const wxChar* ParsePort (const wxChar* uri);
105 const wxChar* ParsePath (const wxChar* uri,
106 bool bReference = false,
107 bool bNormalize = true);
108 const wxChar* ParseQuery (const wxChar* uri);
109 const wxChar* ParseFragment (const wxChar* uri);
110
111
112 static bool ParseH16(const wxChar*& uri);
113 static bool ParseIPv4address(const wxChar*& uri);
114 static bool ParseIPv6address(const wxChar*& uri);
115 static bool ParseIPvFuture(const wxChar*& uri);
116
117 static void Normalize(wxChar* uri, bool bIgnoreLeads = false);
118 static void UpTree(const wxChar* uristart, const wxChar*& uri);
119 static void UpTree(wxString::const_iterator uristart,
120 wxString::const_iterator& uri);
121
122 static wxUniChar TranslateEscape(const wxString::const_iterator& s);
123 static void Escape(wxString& s, const wxChar& c);
124 static bool IsEscape(const wxChar*& uri);
125
126 static wxChar CharToHex(const wxChar& c);
127
128 static bool IsUnreserved (const wxChar& c);
129 static bool IsReserved (const wxChar& c);
130 static bool IsGenDelim (const wxChar& c);
131 static bool IsSubDelim (const wxChar& c);
132 static bool IsHex(const wxChar& c);
133 static bool IsAlpha(const wxChar& c);
134 static bool IsDigit(const wxChar& c);
135
136 wxString m_scheme;
137 wxString m_path;
138 wxString m_query;
139 wxString m_fragment;
140
141 wxString m_userinfo;
142 wxString m_server;
143 wxString m_port;
144
145 wxURIHostType m_hostType;
146
147 size_t m_fields;
148
149 DECLARE_DYNAMIC_CLASS(wxURI)
150 };
151
152 #endif // _WX_URI_H_
153