libcommonc++  0.7
URL.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_URL_hxx
24 #define __ccxx_URL_hxx
25 
26 #include <memory>
27 
28 #include <commonc++/Common.h++>
30 #include <commonc++/RegExp.h++>
31 #include <commonc++/String.h++>
32 
33 namespace ccxx {
34 
42 {
43  public:
44 
46  URL();
47 
49  URL(const String& url);
50 
52  URL(const URL& other);
53 
55  ~URL();
56 
58  inline void setScheme(const String& scheme)
59  { _scheme = scheme; _url = String::null; }
60 
62  inline String getScheme() const
63  { return(_scheme); }
64 
66  inline void setHost(const String& host)
67  { _host = host; _url = String::null; }
68 
70  inline String getHost() const
71  { return(_host); }
72 
76  inline void setPort(uint16_t port)
77  { _port = port; _url = String::null; }
78 
83  inline uint16_t getPort() const
84  { return(_port); }
85 
87  void setPath(const String& path);
88 
90  inline String getPath() const
91  { return(_path); }
92 
94  inline String getCanonicalPath() const
95  { return(_canonicalPath); }
96 
102  inline void setQuery(const String& query)
103  { _query = query; _url = String::null; }
104 
110  inline String getQuery() const
111  { return(_query); }
112 
114  bool isValid() const;
115 
117  String toString() const;
118 
120  bool operator==(const URL& other) const;
121 
123  inline bool operator!=(const URL& other) const
124  { return(! operator==(other)); }
125 
127  URL& operator=(const String& other);
128 
130  URL& operator=(const URL& other);
131 
138  static String encode(const String& str);
139 
146  static String decode(const String& str);
147 
148  private:
149 
150  void _init();
151  void _parseURL(const String& url);
152  String _canonicalizePath(const String& path);
153 
154  String _scheme;
155  String _host;
156  uint16_t _port;
157  String _path;
158  String _canonicalPath;
159  String _query;
160  mutable String _url;
161  RegExp _re;
162 };
163 
164 } // namespace ccxx
165 
166 #endif // __ccxx_URL_hxx
String getScheme() const
Get the scheme component of the URL.
Definition: URL.h++:62
bool operator==(const Blob &b1, const Blob &b2)
Definition: Blob.h++:344
A regular expression.
Definition: RegExp.h++:75
String getCanonicalPath() const
Get the path component of the URL, in canonicalized form.
Definition: URL.h++:94
A class representing a URL (Uniform Resource Locator).
Definition: URL.h++:41
String getHost() const
Get the hostname component of the URL.
Definition: URL.h++:70
String getQuery() const
Get the query component of the URL.
Definition: URL.h++:110
void setScheme(const String &scheme)
Set the scheme component of the URL.
Definition: URL.h++:58
#define COMMONCPP_API
Definition: Common.h++:126
uint16_t getPort() const
Get the port number for the URL.
Definition: URL.h++:83
void setHost(const String &host)
Set the hostname component of the URL.
Definition: URL.h++:66
A flexible, reference counted, copy-on-write, thread-safe, nullable string.
Definition: String.h++:50
bool operator!=(const URL &other) const
Inequality operator.
Definition: URL.h++:123
void setQuery(const String &query)
Set the query component of the URL.
Definition: URL.h++:102
String getPath() const
Get the path component of the URL.
Definition: URL.h++:90
void setPort(uint16_t port)
Set the port number for the URL.
Definition: URL.h++:76
static const String null
The null string.
Definition: String.h++:1128
Definition: AllocationMap.c++:25