Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:10:44

0001 //
0002 // Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/url
0008 //
0009 
0010 #ifndef BOOST_URL_DETAIL_URL_IMPL_HPP
0011 #define BOOST_URL_DETAIL_URL_IMPL_HPP
0012 
0013 #include <boost/url/host_type.hpp>
0014 #include <boost/url/pct_string_view.hpp>
0015 #include <boost/url/scheme.hpp>
0016 #include <boost/core/detail/string_view.hpp>
0017 #include <boost/url/detail/parts_base.hpp>
0018 #include <boost/assert.hpp>
0019 #include <cstdint>
0020 
0021 namespace boost {
0022 namespace urls {
0023 
0024 class url_view;
0025 class authority_view;
0026 
0027 namespace detail {
0028 
0029 constexpr char const* const empty_c_str_ = "";
0030 
0031 // This is the private 'guts' of a
0032 // url_view, exposed so different parts
0033 // of the implementation can work on it.
0034 struct BOOST_URL_DECL url_impl : parts_base
0035 {
0036     static
0037     constexpr
0038     std::size_t const zero_ = 0;
0039 
0040     // never nullptr
0041     char const* cs_ = empty_c_str_;
0042 
0043     std::size_t offset_[id_end + 1] = {};
0044     std::size_t decoded_[id_end] = {};
0045     std::size_t nseg_ = 0;
0046     std::size_t nparam_ = 0;
0047     unsigned char ip_addr_[16] = {};
0048     // VFALCO don't we need a bool?
0049     std::uint16_t port_number_ = 0;
0050     host_type host_type_ =
0051         urls::host_type::none;
0052     scheme scheme_ =
0053         urls::scheme::none;
0054 
0055     from from_ = from::string;
0056 
0057     url_impl(
0058         from b) noexcept
0059         : from_(b)
0060     {
0061     }
0062 
0063     // in url_view.ipp
0064     url_view construct() const noexcept;
0065 
0066     // in authority_view.ipp
0067     authority_view
0068     construct_authority() const noexcept;
0069 
0070     std::size_t len(int, int) const noexcept;
0071     std::size_t len(int) const noexcept;
0072     std::size_t offset(int) const noexcept;
0073     core::string_view get(int) const noexcept;
0074     core::string_view get(int, int) const noexcept;
0075     pct_string_view pct_get(int) const noexcept;
0076     pct_string_view pct_get(int, int) const noexcept;
0077     void set_size(int, std::size_t) noexcept;
0078     void split(int, std::size_t) noexcept;
0079     void adjust_right(int first, int last, std::size_t n) noexcept;
0080     void adjust_left(int first, int last, std::size_t n) noexcept;
0081     void collapse(int, int, std::size_t) noexcept;
0082 
0083     void apply_scheme(core::string_view) noexcept;
0084     void apply_userinfo(pct_string_view const&,
0085         pct_string_view const*) noexcept;
0086     void apply_host(host_type, pct_string_view,
0087         unsigned char const*) noexcept;
0088     void apply_port(core::string_view, unsigned short) noexcept;
0089     void apply_authority(authority_view const&) noexcept;
0090     void apply_path(pct_string_view, std::size_t) noexcept;
0091     void apply_query(pct_string_view, std::size_t) noexcept;
0092     void apply_frag(pct_string_view) noexcept;
0093 };
0094 
0095 //------------------------------------------------
0096 
0097 // this allows a path to come from a
0098 // url_impl or a separate core::string_view
0099 class path_ref
0100     : private parts_base
0101 {
0102     url_impl const* impl_ = nullptr;
0103     char const* data_ = nullptr;
0104     std::size_t size_ = 0;
0105     std::size_t nseg_ = 0;
0106     std::size_t dn_ = 0;
0107 
0108 public:
0109     path_ref() = default;
0110     path_ref(url_impl const& impl) noexcept;
0111     path_ref(core::string_view,
0112         std::size_t, std::size_t) noexcept;
0113     pct_string_view buffer() const noexcept;
0114     std::size_t size() const noexcept;
0115     char const* data() const noexcept;
0116     char const* end() const noexcept;
0117     std::size_t nseg() const noexcept;
0118 
0119     bool
0120     alias_of(
0121         url_impl const& impl) const noexcept
0122     {
0123         return impl_ == &impl;
0124     }
0125 
0126     bool
0127     alias_of(
0128         path_ref const& ref) const noexcept
0129     {
0130         if(impl_)
0131             return impl_ == ref.impl_;
0132         BOOST_ASSERT(data_ != ref.data_ || (
0133             size_ == ref.size_ &&
0134             nseg_ == ref.nseg_ &&
0135             dn_ == ref.dn_));
0136         return data_ == ref.data_;
0137     }
0138 };
0139 
0140 //------------------------------------------------
0141 
0142 // this allows a params to come from a
0143 // url_impl or a separate core::string_view
0144 class BOOST_URL_DECL query_ref
0145     : private parts_base
0146 {
0147     url_impl const* impl_ = nullptr;
0148     char const* data_ = nullptr;
0149     std::size_t size_ = 0;
0150     std::size_t nparam_ = 0;
0151     std::size_t dn_ = 0;
0152     bool question_mark_ = false;
0153 
0154 public:
0155     query_ref(
0156         core::string_view s,      // buffer, no '?'
0157         std::size_t dn,     // decoded size
0158         std::size_t nparam
0159             ) noexcept;
0160     query_ref() = default;
0161     query_ref(url_impl const& impl) noexcept;
0162     pct_string_view buffer() const noexcept;
0163     std::size_t size() const noexcept; // with '?'
0164     char const* begin() const noexcept; // no '?'
0165     char const* end() const noexcept;
0166     std::size_t nparam() const noexcept;
0167 
0168     bool
0169     alias_of(
0170         url_impl const& impl) const noexcept
0171     {
0172         return impl_ == &impl;
0173     }
0174 
0175     bool
0176     alias_of(
0177         query_ref const& ref) const noexcept
0178     {
0179         if(impl_)
0180             return impl_ == ref.impl_;
0181         BOOST_ASSERT(data_ != ref.data_ || (
0182             size_ == ref.size_ &&
0183             nparam_ == ref.nparam_ &&
0184             dn_ == ref.dn_));
0185         return data_ == ref.data_;
0186     }
0187 };
0188 
0189 } // detail
0190 
0191 } // urls
0192 } // boost
0193 
0194 #endif