libfilezilla
Toggle main menu visibility
Loading...
Searching...
No Matches
lib
libfilezilla
uri.hpp
Go to the documentation of this file.
1
#ifndef LIBFILEZILLA_URI_HEADER
2
#define LIBFILEZILLA_URI_HEADER
3
4
#include "
libfilezilla.hpp
"
5
6
#include <initializer_list>
7
#include <map>
8
#include <string>
9
13
14
namespace
fz
{
15
16
enum class
uri_parsing_flags
17
{
18
normal
,
19
21
assume_authority
22
};
23
29
class
FZ_PUBLIC_SYMBOL uri final
30
{
31
public
:
32
uri()
noexcept
=
default
;
33
explicit
uri(std::string_view
const
& in,
uri_parsing_flags
flags = {});
34
35
void
clear();
36
43
bool
parse
(std::string_view in,
uri_parsing_flags
flags = {});
44
51
std::string
to_string
(
bool
with_query =
true
)
const
;
52
54
std::string
get_request
(
bool
with_query =
true
)
const
;
55
57
std::string
get_authority
(
bool
with_userinfo)
const
;
58
59
bool
empty()
const
;
60
explicit
operator
bool()
const
{
return
!empty(); }
61
63
std::string
scheme_
;
64
66
std::string
user_
;
67
69
std::string
pass_
;
70
72
std::string
host_
;
73
75
unsigned
short
port_
{};
76
78
std::string
path_
;
79
87
std::string
query_
;
88
94
std::string
fragment_
;
95
97
bool
is_absolute
()
const
{
return
path_
[0] ==
'/'
; }
98
104
void
resolve
(uri
const
& base);
105
106
bool
operator==(uri
const
& arg)
const
;
107
108
bool
operator!=(uri
const
& arg)
const
{
return
!(*
this
== arg); }
109
110
private
:
111
bool
FZ_PRIVATE_SYMBOL parse_authority(std::string_view authority);
112
};
113
119
class
FZ_PUBLIC_SYMBOL query_string final
120
{
121
public
:
122
explicit
query_string() =
default
;
123
explicit
query_string(std::string_view
const
& raw,
bool
plus_is_space =
false
);
124
explicit
query_string(std::pair<std::string, std::string>
const
& segment);
125
explicit
query_string(std::initializer_list<std::pair<std::string, std::string>>
const
& segments);
126
bool
set(std::string_view
const
& raw,
bool
plus_is_space =
false
);
127
128
std::string to_string(
bool
encode_slashes)
const
;
129
130
void
remove(std::string
const
& key);
131
std::string& operator[](std::string
const
& key);
132
133
std::map<std::string, std::string, less_insensitive_ascii>
const
& pairs()
const
{
return
segments_; }
134
135
bool
empty()
const
{
return
segments_.empty(); }
136
137
private
:
138
std::map<std::string, std::string, less_insensitive_ascii> segments_;
139
};
140
141
}
142
143
#endif
fz::uri::get_authority
std::string get_authority(bool with_userinfo) const
Returns [user[:pass]]host[:port].
fz::uri::user_
std::string user_
Optional user part of the authority.
Definition
uri.hpp:66
fz::uri::query_
std::string query_
The part of a URI after ? but before #.
Definition
uri.hpp:87
fz::uri::get_request
std::string get_request(bool with_query=true) const
Returns path and query, separated by question mark.
fz::uri::pass_
std::string pass_
Optional password part of the authority.
Definition
uri.hpp:69
fz::uri::to_string
std::string to_string(bool with_query=true) const
Assembles components into string.
fz::uri::scheme_
std::string scheme_
Often referred to as the protocol prefix, e.g. ftp://.
Definition
uri.hpp:63
fz::uri::path_
std::string path_
Optional path, must start with a slash if set.
Definition
uri.hpp:78
fz::uri::fragment_
std::string fragment_
The part of a URI after #.
Definition
uri.hpp:94
fz::uri::port_
unsigned short port_
Optional Port if non-zero.
Definition
uri.hpp:75
fz::uri::resolve
void resolve(uri const &base)
Resolve a relative URI reference into an absolute URI given a base URL.
fz::uri::is_absolute
bool is_absolute() const
Checks that the URI is absolute, that is the path starting with a slash.
Definition
uri.hpp:97
fz::uri::parse
bool parse(std::string_view in, uri_parsing_flags flags={})
Splits uri into components.
fz::uri::host_
std::string host_
Hostname, or IP address literal.
Definition
uri.hpp:72
libfilezilla.hpp
Sets some global macros and further includes string.hpp.
fz
The namespace used by libfilezilla.
Definition
apply.hpp:17
fz::mkdir_permissions::normal
@ normal
Definition
local_filesys.hpp:153
fz::uri_parsing_flags
uri_parsing_flags
Definition
uri.hpp:17
fz::uri_parsing_flags::assume_authority
@ assume_authority
If parsing a schemeless URI, assume it has an authority, otherwise it's all seen as path.
Definition
uri.hpp:21
Generated by
1.17.0