Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-06 09:59:31

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_ENCODED_BASE_HPP
0012 #define BOOST_URL_SEGMENTS_ENCODED_BASE_HPP
0013 
0014 #include <boost/url/detail/config.hpp>
0015 #include <boost/url/ignore_case.hpp>
0016 #include <boost/url/pct_string_view.hpp>
0017 #include <boost/url/detail/url_impl.hpp>
0018 #include <iosfwd>
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_encoded_base
0038 {
0039     detail::path_ref ref_;
0040 
0041     friend class url_view_base;
0042     friend class segments_encoded_ref;
0043     friend class segments_encoded_view;
0044 
0045     segments_encoded_base(
0046         detail::path_ref const& ref) noexcept;
0047     segments_encoded_base() = default;
0048     segments_encoded_base(
0049         segments_encoded_base const&) = default;
0050     segments_encoded_base& operator=(
0051         segments_encoded_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         Strings returned by iterators may
0059         contain percent escapes.
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
0068         are dereferenced refer to the underlying
0069         character buffer.
0070         Ownership is not transferred; the caller
0071         is responsible for ensuring that the
0072         lifetime of the buffer extends until
0073         it is no longer referenced by any
0074         container or iterator.
0075     */
0076 #ifdef BOOST_URL_DOCS
0077     using iterator = __see_below__;
0078 #else
0079 
0080     /** A Bidirectional iterator to a path segment
0081 
0082         Objects of this type allow iteration
0083         through the segments in the path.
0084         Strings returned by iterators may
0085         contain percent escapes.
0086         The values returned are read-only;
0087         changes to segments must be made
0088         through the container instead, if the
0089         container supports modification.
0090 
0091         <br>
0092 
0093         The strings produced when iterators
0094         are dereferenced refer to the underlying
0095         character buffer.
0096         Ownership is not transferred; the caller
0097         is responsible for ensuring that the
0098         lifetime of the buffer extends until
0099         it is no longer referenced by any
0100         container or iterator.
0101     */
0102     class iterator;
0103 #endif
0104 
0105     /// @copydoc iterator
0106     using const_iterator = iterator;
0107 
0108     /** The value type
0109 
0110         Values of this type represent a segment
0111         where unique ownership is retained by
0112         making a copy.
0113 
0114         @par Example
0115         @code
0116         segments_encoded_base::value_type ps( url_view( "/path/to/file.txt" ).encoded_segments().back() );
0117         @endcode
0118     */
0119     using value_type = std::string;
0120 
0121     /** The reference type
0122 
0123         This is the type of value returned when
0124         iterators of the view are dereferenced.
0125     */
0126     using reference = pct_string_view;
0127 
0128     /// @copydoc reference
0129     using const_reference = pct_string_view;
0130 
0131     /** An unsigned integer type used to represent size.
0132     */
0133     using size_type = std::size_t;
0134 
0135     /** A signed integer type used to represent differences.
0136     */
0137     using difference_type = std::ptrdiff_t;
0138 
0139     //--------------------------------------------
0140     //
0141     // Observers
0142     //
0143     //--------------------------------------------
0144 
0145     /** Return the maximum number of characters possible
0146 
0147         This represents the largest number of
0148         characters that are possible in a path,
0149         not including any null terminator.
0150 
0151         @par Exception Safety
0152         Throws nothing.
0153 
0154         @return The maximum number of characters possible.
0155     */
0156     static
0157     constexpr
0158     std::size_t
0159     max_size() noexcept
0160     {
0161         return BOOST_URL_MAX_SIZE;
0162     }
0163 
0164     /** Return the referenced character buffer.
0165 
0166         This function returns the character
0167         buffer referenced by the view.
0168         The returned string may contain
0169         percent escapes.
0170 
0171         @par Example
0172         @code
0173         assert( url_view( "/path/to/file.txt" ).encoded_segments().buffer() == "/path/to/file.txt" );
0174         @endcode
0175 
0176         @par Complexity
0177         Constant.
0178 
0179         @par Exception Safety
0180         Throws nothing.
0181 
0182         @return A string view of the buffer.
0183     */
0184     BOOST_URL_DECL
0185     pct_string_view
0186     buffer() const noexcept;
0187 
0188     /** Returns true if this references an absolute path.
0189 
0190         Absolute paths always start with a
0191         forward slash ('/').
0192 
0193         @par Example
0194         @code
0195         assert( url_view( "/path/to/file.txt" ).encoded_segments().is_absolute() == true );
0196         @endcode
0197 
0198         @par Complexity
0199         Constant.
0200 
0201         @par Exception Safety
0202         Throws nothing.
0203 
0204         @return `true` if the path is absolute, otherwise `false`.
0205     */
0206     BOOST_URL_DECL
0207     bool
0208     is_absolute() const noexcept;
0209 
0210     /** Return true if there are no segments
0211 
0212         @par Example
0213         @code
0214         assert( ! url_view( "/index.htm" ).encoded_segments().empty() );
0215         @endcode
0216 
0217         @par Complexity
0218         Constant.
0219 
0220         @par Exception Safety
0221         Throws nothing.
0222 
0223         @return `true` if there are no segments, otherwise `false`.
0224     */
0225     BOOST_URL_DECL
0226     bool
0227     empty() const noexcept;
0228 
0229     /** Return the number of segments
0230     
0231         @par Example
0232         @code
0233         assert( url_view( "/path/to/file.txt" ).encoded_segments().size() == 3 );
0234         @endcode
0235 
0236         @par Complexity
0237         Constant.
0238 
0239         @par Exception Safety
0240         Throws nothing.
0241 
0242         @return The number of segments.
0243     */
0244     BOOST_URL_DECL
0245     std::size_t
0246     size() const noexcept;
0247 
0248     /** Return the first segment
0249 
0250         This function returns a string with the
0251         first segment of the path without any
0252         leading or trailing '/' separators.
0253         The returned string may contain
0254         percent escapes.
0255 
0256         @par Preconditions
0257         @code
0258         this->empty() == false
0259         @endcode
0260 
0261         @par Effects
0262         @code
0263         return *begin();
0264         @endcode
0265 
0266         @par Example
0267         @code
0268         assert( url_view( "/path/to/file.txt" ).encoded_segments().front() == "path" );
0269         @endcode
0270 
0271         @par Complexity
0272         Constant.
0273 
0274         @par Exception Safety
0275         Throws nothing.
0276 
0277         @return The first segment.
0278     */
0279     pct_string_view
0280     front() const noexcept;
0281 
0282     /** Return the last segment
0283 
0284         This function returns a string with the
0285         last segment of the path without any
0286         leading or trailing '/' separators.
0287         The returned string may contain
0288         percent escapes.
0289 
0290         @par Preconditions
0291         @code
0292         this->empty() == false
0293         @endcode
0294 
0295         @par Example
0296         @code
0297         assert( url_view( "/path/to/file.txt" ).encoded_segments().back() == "file.txt" );
0298         @endcode
0299 
0300         @par Preconditions
0301         @code
0302         this->empty() == false
0303         @endcode
0304 
0305         @par Effects
0306         @code
0307         return *--end();
0308         @endcode
0309 
0310         @par Complexity
0311         Constant.
0312 
0313         @par Exception Safety
0314         Throws nothing.
0315 
0316         @return The last segment.
0317     */
0318     pct_string_view
0319     back() const noexcept;
0320 
0321     /** Return an iterator to the beginning
0322 
0323         @par Complexity
0324         Linear in `this->front().size()` or
0325         constant if `this->empty()`.
0326 
0327         @par Exception Safety
0328         Throws nothing.
0329 
0330         @return An iterator to the first segment.
0331     */
0332     BOOST_URL_DECL
0333     iterator
0334     begin() const noexcept;
0335 
0336     /** Return an iterator to the end
0337 
0338         @par Complexity
0339         Constant.
0340 
0341         @par Exception Safety
0342         Throws nothing.
0343 
0344         @return An iterator to one past the last segment.
0345     */
0346     BOOST_URL_DECL
0347     iterator
0348     end() const noexcept;
0349 };
0350 
0351 //------------------------------------------------
0352 
0353 /** Format to an output stream
0354 
0355     Any percent-escapes are emitted as-is;
0356     no decoding is performed.
0357 
0358     @par Complexity
0359     Linear in `ps.buffer().size()`.
0360 
0361     @par Effects
0362     @code
0363     return os << ps.buffer();
0364     @endcode
0365 
0366     @param os The output stream to write to.
0367     @param ps The object to format.
0368     @return A reference to the output stream.
0369 */
0370 BOOST_URL_DECL
0371 std::ostream&
0372 operator<<(
0373     std::ostream& os,
0374     segments_encoded_base const& ps);
0375 
0376 } // urls
0377 } // boost
0378 
0379 #include <boost/url/impl/segments_encoded_base.hpp>
0380 
0381 #endif