Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:29

0001 //
0002 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
0003 // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
0004 //
0005 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0006 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 // Official repository: https://github.com/boostorg/url
0009 //
0010 
0011 #ifndef BOOST_URL_SEGMENTS_BASE_HPP
0012 #define BOOST_URL_SEGMENTS_BASE_HPP
0013 
0014 #include <boost/url/detail/config.hpp>
0015 #include <boost/url/ignore_case.hpp>
0016 #include <boost/url/detail/url_impl.hpp>
0017 #include <iosfwd>
0018 #include <string>
0019 
0020 namespace boost {
0021 namespace urls {
0022 
0023 /** Common functionality for containers
0024 
0025     This base class is used by the library
0026     to provide common member functions for
0027     containers. This cannot be instantiated
0028     directly; Instead, use one of the
0029     containers or functions:
0030 
0031     @par Containers
0032     @li @ref segments_ref
0033     @li @ref segments_view
0034     @li @ref segments_encoded_ref
0035     @li @ref segments_encoded_view
0036 */
0037 class segments_base
0038 {
0039     detail::path_ref ref_;
0040 
0041     friend class url_view_base;
0042     friend class segments_ref;
0043     friend class segments_view;
0044 
0045     segments_base(
0046         detail::path_ref const& ref) noexcept;
0047     segments_base() = default;
0048     segments_base(
0049         segments_base const&) = default;
0050     segments_base& operator=(
0051         segments_base const&) = default;
0052 
0053 public:
0054     /** A Bidirectional iterator to a path segment
0055 
0056         Objects of this type allow iteration
0057         through the segments in the path.
0058         Any percent-escapes in returned strings
0059         are decoded first.
0060         The values returned are read-only;
0061         changes to segments must be made
0062         through the container instead, if the
0063         container supports modification.
0064 
0065         <br>
0066 
0067         The strings produced when iterators are
0068         dereferenced belong to the iterator and
0069         become invalidated when that particular
0070         iterator is incremented, decremented,
0071         or destroyed.
0072     */
0073 #ifdef BOOST_URL_DOCS
0074     using iterator = __see_below__;
0075 #else
0076     class iterator;
0077 #endif
0078 
0079     /// @copydoc iterator
0080     using const_iterator = iterator;
0081 
0082     /** The value type
0083 
0084         Values of this type represent a segment
0085         where unique ownership is retained by
0086         making a copy.
0087 
0088         @par Example
0089         @code
0090         segments_base::value_type ps( url_view( "/path/to/file.txt" ).segments().back() );
0091         @endcode
0092     */
0093     using value_type = std::string;
0094 
0095     /** The reference type
0096 
0097         This is the type of value returned when
0098         iterators of the view are dereferenced.
0099     */
0100     using reference = std::string;
0101 
0102     /// @copydoc reference
0103     using const_reference = std::string;
0104 
0105     /** An unsigned integer type used to represent size.
0106     */
0107     using size_type = std::size_t;
0108 
0109     /** A signed integer type used to represent differences.
0110     */
0111     using difference_type = std::ptrdiff_t;
0112 
0113     //--------------------------------------------
0114     //
0115     // Observers
0116     //
0117     //--------------------------------------------
0118 
0119     /** Return the maximum number of characters possible
0120 
0121         This represents the largest number of
0122         characters that are possible in a path,
0123         not including any null terminator.
0124 
0125         @par Exception Safety
0126         Throws nothing.
0127     */
0128     static
0129     constexpr
0130     std::size_t
0131     max_size() noexcept
0132     {
0133         return BOOST_URL_MAX_SIZE;
0134     }
0135 
0136     /** Return the referenced character buffer.
0137 
0138         This function returns the character
0139         buffer referenced by the view.
0140         The returned string may contain
0141         percent escapes.
0142 
0143         @par Example
0144         @code
0145         assert( url_view( "/path/to/file.txt" ).segments().buffer() == "/path/to/file.txt" );
0146         @endcode
0147 
0148         @par Complexity
0149         Constant.
0150 
0151         @par Exception Safety
0152         Throws nothing.
0153     */
0154     BOOST_URL_DECL
0155     pct_string_view
0156     buffer() const noexcept;
0157 
0158     /** Returns true if this references an absolute path.
0159 
0160         Absolute paths always start with a
0161         forward slash ('/').
0162 
0163         @par Example
0164         @code
0165         assert( url_view( "/path/to/file.txt" ).segments().is_absolute() == true );
0166         @endcode
0167 
0168         @par Complexity
0169         Constant.
0170 
0171         @par Exception Safety
0172         Throws nothing.
0173     */
0174     BOOST_URL_DECL
0175     bool
0176     is_absolute() const noexcept;
0177 
0178     /** Return true if there are no segments
0179 
0180         @par Example
0181         @code
0182         assert( ! url_view( "/index.htm" ).segments().empty() );
0183         @endcode
0184 
0185         @par Complexity
0186         Constant.
0187 
0188         @par Exception Safety
0189         Throws nothing.
0190     */
0191     BOOST_URL_DECL
0192     bool
0193     empty() const noexcept;
0194 
0195     /** Return the number of segments
0196     
0197         @par Example
0198         @code
0199         assert( url_view( "/path/to/file.txt" ).segments().size() == 3 );
0200         @endcode
0201 
0202         @par Complexity
0203         Constant.
0204 
0205         @par Exception Safety
0206         Throws nothing.
0207     */
0208     BOOST_URL_DECL
0209     std::size_t
0210     size() const noexcept;
0211 
0212     /** Return the first segment
0213 
0214         This function returns a string with the
0215         first segment of the path without any
0216         leading or trailing '/' separators.
0217         Any percent-escapes in the string are
0218         decoded first.
0219 
0220         @par Preconditions
0221         @code
0222         this->empty() == false
0223         @endcode
0224 
0225         @par Effects
0226         @code
0227         return *begin();
0228         @endcode
0229 
0230         @par Example
0231         @code
0232         assert( url_view( "/path/to/file.txt" ).segments().front() == "path" );
0233         @endcode
0234 
0235         @par Complexity
0236         Linear in `this->front().size()`.
0237 
0238         @par Exception Safety
0239         Calls to allocate may throw.
0240     */
0241     std::string
0242     front() const noexcept;
0243 
0244     /** Return the last segment
0245 
0246         @par Preconditions
0247         @code
0248         this->empty() == false
0249         @endcode
0250 
0251         @par Example
0252         @code
0253         assert( url_view( "/path/to/file.txt" ).segments().back() == "file.txt" );
0254         @endcode
0255 
0256         @par Preconditions
0257         @code
0258         this->empty() == false
0259         @endcode
0260 
0261         @par Effects
0262         @code
0263         return *--end();
0264         @endcode
0265 
0266         @par Complexity
0267         Linear in `this->back().size()`.
0268 
0269         @par Exception Safety
0270         Calls to allocate may throw.
0271     */
0272     std::string
0273     back() const noexcept;
0274 
0275     /** Return an iterator to the beginning
0276 
0277         @par Complexity
0278         Linear in `this->front().size()` or
0279         constant if `this->empty()`.
0280 
0281         @par Exception Safety
0282         Throws nothing.
0283     */
0284     BOOST_URL_DECL
0285     iterator
0286     begin() const noexcept;
0287 
0288     /** Return an iterator to the end
0289 
0290         @par Complexity
0291         Constant.
0292 
0293         @par Exception Safety
0294         Throws nothing.
0295     */
0296     BOOST_URL_DECL
0297     iterator
0298     end() const noexcept;
0299 };
0300 
0301 //------------------------------------------------
0302 
0303 /** Format to an output stream
0304 
0305     Any percent-escapes are emitted as-is;
0306     no decoding is performed.
0307 
0308     @par Complexity
0309     Linear in `ps.buffer().size()`.
0310 
0311     @par Effects
0312     @code
0313     return os << ps.buffer();
0314     @endcode
0315 */
0316 BOOST_URL_DECL
0317 std::ostream&
0318 operator<<(
0319     std::ostream& os,
0320     segments_base const& ps);
0321 
0322 } // urls
0323 } // boost
0324 
0325 #include <boost/url/impl/segments_base.hpp>
0326 
0327 #endif