Loading...
Searching...
No Matches
url.h
Go to the documentation of this file.
#ifndef ADA_URL_H
#define ADA_URL_H
#include <algorithm>
#include <optional>
#include <ostream>
#include <string>
#include <string_view>
#include "ada/checkers.h"
#include "ada/common_defs.h"
#include "ada/url_base.h"
#include "ada/url_components.h"
#include "ada/helpers.h"
namespace ada {
struct url_aggregator;
// namespace parser {
// template <typename result_type>
// result_type parse_url(std::string_view user_input,
// const result_type* base_url = nullptr);
// template <typename result_type, bool store_values>
// result_type parse_url_impl(std::string_view user_input,
// const result_type* base_url = nullptr);
// }
struct url : url_base {
url() = default;
url(const url &u) = default;
url(url &&u) noexcept = default;
url &operator=(url &&u) noexcept = default;
url &operator=(const url &u) = default;
~url() override = default;
std::string username{};
std::string password{};
std::optional<std::string> host{};
std::optional<uint16_t> port{};
std::string path{};
std::optional<std::string> query{};
std::optional<std::string> hash{};
[[nodiscard]] inline bool has_empty_hostname() const noexcept;
[[nodiscard]] inline bool has_port() const noexcept;
[[nodiscard]] inline bool has_hostname() const noexcept;
[[nodiscard]] bool has_valid_domain() const noexcept override;
[[nodiscard]] std::string to_string() const override;
[[nodiscard]] ada_really_inline std::string get_href() const;
[[nodiscard]] std::string get_origin() const override;
[[nodiscard]] std::string get_protocol() const;
[[nodiscard]] std::string get_host() const;
[[nodiscard]] std::string get_hostname() const;
[[nodiscard]] constexpr std::string_view get_pathname() const noexcept;
[[nodiscard]] ada_really_inline size_t get_pathname_length() const noexcept;
[[nodiscard]] std::string get_search() const;
[[nodiscard]] const std::string &get_username() const noexcept;
bool set_username(std::string_view input);
bool set_password(std::string_view input);
bool set_port(std::string_view input);
void set_hash(std::string_view input);
void set_search(std::string_view input);
bool set_pathname(std::string_view input);
bool set_host(std::string_view input);
bool set_hostname(std::string_view input);
bool set_protocol(std::string_view input);
bool set_href(std::string_view input);
[[nodiscard]] const std::string &get_password() const noexcept;
[[nodiscard]] std::string get_port() const;
[[nodiscard]] std::string get_hash() const;
[[nodiscard]] ada_really_inline bool has_credentials() const noexcept;
[[nodiscard]] ada_really_inline ada::url_components get_components()
const noexcept;
[[nodiscard]] constexpr bool has_hash() const noexcept override;
[[nodiscard]] constexpr bool has_search() const noexcept override;
private:
friend ada::url ada::parser::parse_url<ada::url>(std::string_view,
const ada::url *);
friend ada::url_aggregator ada::parser::parse_url<ada::url_aggregator>(
std::string_view, const ada::url_aggregator *);
friend void ada::helpers::strip_trailing_spaces_from_opaque_path<ada::url>(
ada::url &url);
friend ada::url ada::parser::parse_url_impl<ada::url, true>(std::string_view,
const ada::url *);
friend ada::url_aggregator ada::parser::parse_url_impl<
ada::url_aggregator, true>(std::string_view, const ada::url_aggregator *);
inline void update_unencoded_base_hash(std::string_view input);
inline void update_base_hostname(std::string_view input);
inline void update_base_search(std::string_view input,
const uint8_t query_percent_encode_set[]);
inline void update_base_search(std::optional<std::string> &&input);
inline void update_base_pathname(std::string_view input);
inline void update_base_username(std::string_view input);
inline void update_base_password(std::string_view input);
inline void update_base_port(std::optional<uint16_t> input);
template <bool override_hostname = false>
bool set_host_or_hostname(std::string_view input);
[[nodiscard]] bool parse_ipv4(std::string_view input);
[[nodiscard]] bool parse_ipv6(std::string_view input);
[[nodiscard]] bool parse_opaque_host(std::string_view input);
std::string non_special_scheme{};
[[nodiscard]] inline bool cannot_have_credentials_or_port() const;
ada_really_inline size_t parse_port(
std::string_view view, bool check_trailing_content) noexcept override;
ada_really_inline size_t parse_port(std::string_view view) noexcept override {
return this->parse_port(view, false);
}
[[nodiscard]] ada_really_inline bool parse_host(std::string_view input);
template <bool has_state_override = false>
[[nodiscard]] ada_really_inline bool parse_scheme(std::string_view input);
constexpr void clear_pathname() override;
constexpr void clear_search() override;
constexpr void set_protocol_as_file();
ada_really_inline void parse_path(std::string_view input);
inline void set_scheme(std::string &&new_scheme) noexcept;
constexpr void copy_scheme(ada::url &&u);
constexpr void copy_scheme(const ada::url &u);
}; // struct url
inline std::ostream &operator<<(std::ostream &out, const ada::url &u);
} // namespace ada
#endif // ADA_URL_H
checkers.h
Declarations for URL specific checkers used within Ada.
common_defs.h
Cross-platform compiler macros and common definitions.
ada_really_inline
#define ada_really_inline
Definition common_defs.h:85
helpers.h
Definitions for helper functions used within Ada.
ada::helpers
Includes the definitions for helper functions.
ada::parser
Internal URL parsing implementation.
Definition parser-inl.h:16
ada
Definition ada_idna.h:13
ada::operator<<
std::ostream & operator<<(std::ostream &out, const ada::url &u)
Definition url-inl.h:38
ada::url_aggregator
Memory-efficient URL representation using a single buffer.
Definition url_aggregator.h:46
ada::url_base
Abstract base class for URL representations.
Definition url_base.h:49
ada::url
Represents a parsed URL with individual string components.
Definition url.h:62
ada::url::set_hash
void set_hash(std::string_view input)
Definition url.cpp:864
ada::url::set_hostname
bool set_hostname(std::string_view input)
Definition url.cpp:803
ada::url::set_host
bool set_host(std::string_view input)
Definition url.cpp:799
ada::url::get_components
ada_really_inline ada::url_components get_components() const noexcept
Definition url-inl.h:50
ada::url::url
url(url &&u) noexcept=default
ada::url::has_empty_hostname
bool has_empty_hostname() const noexcept
Definition url-inl.h:29
ada::url::has_port
bool has_port() const noexcept
Definition url-inl.h:22
ada::url::has_credentials
ada_really_inline bool has_credentials() const noexcept
Definition url-inl.h:19
ada::url::parse_url
friend ada::url ada::parser::parse_url(std::string_view, const ada::url *)
ada::url::set_password
bool set_password(std::string_view input)
Definition url.cpp:816
ada::url::operator=
url & operator=(url &&u) noexcept=default
ada::url::operator=
url & operator=(const url &u)=default
ada::url::set_search
void set_search(std::string_view input)
Definition url.cpp:878
ada::url::get_pathname_length
ada_really_inline size_t get_pathname_length() const noexcept
Definition url-inl.h:42
ada::url::get_search
std::string get_search() const
Definition url.cpp:659
ada::url::set_href
bool set_href(std::string_view input)
Definition url.cpp:929
ada::url::get_port
std::string get_port() const
Definition url.cpp:674
ada::url::get_protocol
std::string get_protocol() const
Definition url.cpp:633
ada::url::has_hostname
bool has_hostname() const noexcept
Definition url-inl.h:35
ada::url::get_host
std::string get_host() const
Definition url.cpp:641
ada::url::set_username
bool set_username(std::string_view input)
Definition url.cpp:807
ada::url::get_pathname
constexpr std::string_view get_pathname() const noexcept
Definition url-inl.h:46
ada::url::url
url(const url &u)=default
ada::url::~url
~url() override=default
ada::url::url
url()=default
ada::url::set_pathname
bool set_pathname(std::string_view input)
Definition url.cpp:896
ada::url::get_hostname
std::string get_hostname() const
Definition url.cpp:655
ada::url::get_href
ada_really_inline std::string get_href() const
Definition url-inl.h:188
ada::url::parse_url_impl
friend ada::url ada::parser::parse_url_impl(std::string_view, const ada::url *)
ada::url::get_origin
std::string get_origin() const override
Definition url.cpp:607
ada::url::get_password
const std::string & get_password() const noexcept
Definition url.cpp:670
ada::url::set_protocol
bool set_protocol(std::string_view input)
Definition url.cpp:905
ada::url::get_username
const std::string & get_username() const noexcept
Definition url.cpp:666
ada::url::strip_trailing_spaces_from_opaque_path
friend void ada::helpers::strip_trailing_spaces_from_opaque_path(ada::url &url)
ada::url::set_port
bool set_port(std::string_view input)
Definition url.cpp:825
ada::url::has_search
constexpr bool has_search() const noexcept override
Definition url-inl.h:164
ada::url::to_string
std::string to_string() const override
Definition url.cpp:550
ada::url::get_hash
std::string get_hash() const
Definition url.cpp:678
ada::url::has_hash
constexpr bool has_hash() const noexcept override
Definition url-inl.h:160
ada::url::has_valid_domain
bool has_valid_domain() const noexcept override
Definition url.cpp:600
url_base.h
Base class and common definitions for URL types.
url_components.h
Declaration for the URL Components.