18 URLSpec(
const std::string &url,
bool server_name_expected) {
19 set_url(url, server_name_expected);
26 operator = (
const std::string &url) {
34 operator == (
const URLSpec &other)
const {
42 operator != (
const URLSpec &other)
const {
50 operator < (
const URLSpec &other)
const {
60 return (_flags & F_has_scheme) != 0;
69 return (_flags & F_has_authority) != 0;
78 return (_flags & F_has_username) != 0;
86 return (_flags & F_has_server) != 0;
94 return (_flags & F_has_port) != 0;
103 return (_flags & F_has_path) != 0;
111 return (_flags & F_has_query) != 0;
118 INLINE std::string URLSpec::
119 get_authority()
const {
120 return _url.substr(_username_start, _port_end - _username_start);
128 INLINE std::string URLSpec::
129 get_username()
const {
130 return _url.substr(_username_start, _username_end - _username_start);
137 INLINE std::string URLSpec::
139 return _url.substr(_server_start, _server_end - _server_start);
149 return _url.substr(_port_start, _port_end - _port_start);
156 INLINE std::string URLSpec::
158 return _url.substr(_query_start);
165 INLINE
bool URLSpec::
170 if (_url.substr(0, _scheme_end) ==
"socks") {
173 return (_url[_scheme_end - 1] ==
's');
192 operator
const std::string & ()
const {
199 INLINE
const char *URLSpec::
218 operator bool()
const {
219 return !_url.empty();
225 INLINE
size_t URLSpec::
227 return _url.length();
233 INLINE
size_t URLSpec::
241 INLINE
char URLSpec::
242 operator [] (
size_t n)
const {
243 nassertr(n < _url.length(),
'\0');
247 INLINE std::istream &
248 operator >> (std::istream &in,
URLSpec &url) {
249 if (!url.input(in)) {
250 in.clear(std::ios::failbit | in.rdstate());
255 INLINE std::ostream &
256 operator << (std::ostream &out,
const URLSpec &url) {
A container for a URL, e.g.
bool has_username() const
Returns true if the URL specifies a username (and/or password), false otherwise.
bool has_authority() const
Returns true if the URL specifies an authority (this includes username, server, and/or port),...
bool has_path() const
Returns true if the URL includes a path specification (that is, the particular filename on the server...
bool empty() const
Returns false if the URLSpec is valid (not empty), or true if it is an empty string.
std::string get_port_str() const
Returns the port specified by the URL as a string, or the empty string if no port is specified.
bool has_scheme() const
Returns true if the URL specifies a scheme (e.g.
bool has_port() const
Returns true if the URL specifies a port number, false otherwise.
bool has_server() const
Returns true if the URL specifies a server name, false otherwise.
bool has_query() const
Returns true if the URL includes a query specification, false otherwise.
int compare_to(const URLSpec &other) const
Returns a number less than zero if this URLSpec sorts before the other one, greater than zero if it s...
void set_url(const std::string &url, bool server_name_expected=false)
Completely replaces the URL with the indicated string.
const std::string & get_url() const
Returns the complete URL specification.