C++ Essence Library 0.1.0
A Utility Library for Modern C++ Programming
Loading...
Searching...
No Matches
uri.hpp
1/*
2 * Copyright (c) 2024 The RefValue Project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include "../abi/map.hpp"
26#include "../abi/string.hpp"
27#include "../abi/vector.hpp"
28#include "../compat.hpp"
29
30#include <concepts>
31#include <cstdint>
32#include <memory>
33#include <string_view>
34#include <utility>
35
36namespace essence::net {
37 class uri {
38 public:
39 ES_API(CPPESSENCE) uri();
40 ES_API(CPPESSENCE) uri(std::string_view uri_str);
41
42 template <std::convertible_to<std::string_view> S>
43 requires(!std::same_as<std::decay_t<S>, std::string_view>)
44 uri(S&& uri_str) : uri{std::string_view{std::forward<S>(uri_str)}} {}
45
46 ES_API(CPPESSENCE) uri(const uri& other);
47 ES_API(CPPESSENCE) uri(uri&&) noexcept;
48 ES_API(CPPESSENCE) ~uri();
49 ES_API(CPPESSENCE) uri& operator=(const uri& right);
50 ES_API(CPPESSENCE) uri& operator=(uri&&) noexcept;
51 ES_API(CPPESSENCE) bool operator==(const uri& right) const;
52 ES_API(CPPESSENCE) bool operator!=(const uri& right) const;
53 ES_API(CPPESSENCE) abi::string str() const;
54 ES_API(CPPESSENCE) abi::nstring native_str() const;
55 ES_API(CPPESSENCE) bool empty() const;
56 ES_API(CPPESSENCE) abi::string scheme() const;
57 ES_API(CPPESSENCE) abi::string user_info() const;
58 ES_API(CPPESSENCE) abi::string host() const;
59 ES_API(CPPESSENCE) std::int32_t port() const;
60 ES_API(CPPESSENCE) abi::string path() const;
61 ES_API(CPPESSENCE) abi::string query() const;
62 ES_API(CPPESSENCE) abi::string fragment() const;
63 ES_API(CPPESSENCE) abi::vector<abi::string> split_path() const;
64 ES_API(CPPESSENCE) abi::map<abi::string, abi::string> split_query() const;
65 ES_API(CPPESSENCE) abi::string resolve_uri(std::string_view relative_uri) const;
66
67 private:
68 class impl;
69
70 std::unique_ptr<impl> impl_;
71 };
72
73 ES_API(CPPESSENCE) abi::string encode_uri_data_string(std::string_view str);
74 ES_API(CPPESSENCE) abi::string decode_uri_data_string(std::string_view str);
75} // namespace essence::net
Definition uri.hpp:37