Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
url.hpp
Go to the documentation of this file.
1#pragma once
2
18
19#include <cstdint>
20#include <optional>
21#include <string>
22#include <string_view>
23#include <utility>
24#include <vector>
25
26namespace pulp::runtime {
27
30struct Url {
31 std::string scheme; // "http", "https", "file", ...
32 std::string user; // userinfo before optional :password
33 std::string password; // userinfo after optional :password (rare)
34 std::string host; // hostname or bracketed IPv6 literal
35 uint16_t port = 0; // 0 if not specified
36 std::string path; // includes leading '/' if any
37 std::string query; // raw query string, NOT decoded, no '?'
38 std::string fragment; // raw fragment, NOT decoded, no '#'
39
41 bool empty() const {
42 return scheme.empty() && host.empty() && path.empty()
43 && query.empty() && fragment.empty();
44 }
45
48 uint16_t default_port() const;
49
51 uint16_t effective_port() const {
52 return port != 0 ? port : default_port();
53 }
54
57 std::string to_string() const;
58
62 static std::optional<Url> parse(std::string_view text);
63
65 static bool is_valid(std::string_view text) {
66 auto u = parse(text);
67 return u.has_value() && !u->scheme.empty();
68 }
69};
70
75std::string percent_encode(std::string_view s);
76
79std::string percent_decode(std::string_view s);
80
83std::string form_encode(std::string_view s);
84
86std::string form_decode(std::string_view s);
87
92std::vector<std::pair<std::string, std::string>>
93parse_query(std::string_view query);
94
97std::string build_query(
98 const std::vector<std::pair<std::string, std::string>>& params);
99
100} // namespace pulp::runtime
Definition generated_event_source.hpp:33
std::string form_encode(std::string_view s)
application/x-www-form-urlencoded style — space → +, then percent-encode everything else.
std::string percent_decode(std::string_view s)
Decode percent-escapes — %20 → space, %2F → /.
std::string form_decode(std::string_view s)
Reverse of form_encode. + decodes to space.
std::string percent_encode(std::string_view s)
Percent-encode s per RFC 3986 — unreserved characters (A-Z a-z 0-9 - _ .
std::string build_query(const std::vector< std::pair< std::string, std::string > > &params)
Build a query string from key/value pairs.
std::vector< std::pair< std::string, std::string > > parse_query(std::string_view query)
Parse a URL query string into key/value pairs.
Parsed URL components.
Definition url.hpp:30
std::string to_string() const
Serialize back to text form.
uint16_t port
Definition url.hpp:35
bool empty() const
True when all components are empty / default.
Definition url.hpp:41
std::string password
Definition url.hpp:33
std::string user
Definition url.hpp:32
std::string scheme
Definition url.hpp:31
std::string path
Definition url.hpp:36
uint16_t effective_port() const
Effective port — port if non-zero, otherwise default_port().
Definition url.hpp:51
static std::optional< Url > parse(std::string_view text)
Parse a URL string.
std::string query
Definition url.hpp:37
uint16_t default_port() const
Default port for the scheme — e.g.
static bool is_valid(std::string_view text)
True if text parses as a URL with at least a scheme.
Definition url.hpp:65
std::string fragment
Definition url.hpp:38
std::string host
Definition url.hpp:34