Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:07:57

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_VIEW_HPP
0012 #define BOOST_URL_SEGMENTS_VIEW_HPP
0013 
0014 #include <boost/url/detail/config.hpp>
0015 #include <boost/url/segments_base.hpp>
0016 #include <boost/core/detail/string_view.hpp>
0017 
0018 namespace boost {
0019 namespace urls {
0020 
0021 /** A view representing path segments in a URL
0022 
0023     Objects of this type are used to interpret
0024     the path as a bidirectional view of segment
0025     strings.
0026 
0027     The view does not retain ownership of the
0028     elements and instead references the original
0029     character buffer. The caller is responsible
0030     for ensuring that the lifetime of the buffer
0031     extends until it is no longer referenced.
0032 
0033     @par Example
0034     @code
0035     url_view u( "/path/to/file.txt" );
0036 
0037     segments_view ps = u.segments();
0038 
0039     assert( ps.buffer().data() == u.buffer().data() );
0040     @endcode
0041 
0042     Percent escapes in strings returned when
0043     dereferencing iterators are automatically
0044     decoded.
0045 
0046     @par Iterator Invalidation
0047     Changes to the underlying character buffer
0048     can invalidate iterators which reference it.
0049 
0050     @see
0051         @ref segments_encoded_view,
0052         @ref segments_encoded_ref,
0053         @ref segments_ref.
0054 */
0055 class segments_view
0056     : public segments_base
0057 {
0058     friend class url_view_base;
0059     friend class segments_encoded_view;
0060     friend class segments_ref;
0061 
0062     segments_view(
0063         detail::path_ref const& ref) noexcept;
0064 
0065 public:
0066     /** Constructor
0067 
0068         Default-constructed segments have
0069         zero elements.
0070 
0071         @par Example
0072         @code
0073         segments_view ps;
0074         @endcode
0075 
0076         @par Effects
0077         @code
0078         return segments_view( "" );
0079         @endcode
0080 
0081         @par Complexity
0082         Constant.
0083 
0084         @par Exception Safety
0085         Throws nothing.
0086     */
0087     segments_view() = default;
0088 
0089     /** Constructor
0090 
0091         After construction, viewss
0092         reference the same underlying character
0093         buffer.
0094 
0095         Ownership is not transferred; the caller
0096         is responsible for ensuring the lifetime
0097         of the buffer extends until it is no
0098         longer referenced.
0099 
0100         @par Postconditions
0101         @code
0102         this->buffer().data() == other.buffer().data()
0103         @endcode
0104 
0105         @par Complexity
0106         Constant
0107 
0108         @par Exception Safety
0109         Throws nothing
0110 
0111         @param other The other view.
0112     */
0113     segments_view(
0114         segments_view const& other) = default;
0115 
0116     /** Constructor
0117 
0118         This function constructs segments from
0119         a valid path string, which can contain
0120         percent escapes.
0121         Upon construction, the view references
0122         the character buffer pointed to by `s`.
0123         caller is responsible for ensuring
0124         that the lifetime of the buffer
0125         extends until the view is destroyed.
0126 
0127         @par Example
0128         @code
0129         segments_view ps( "/path/to/file.txt" );
0130         @endcode
0131 
0132         @par Effects
0133         @code
0134         return parse_path( s ).value();
0135         @endcode
0136 
0137         @par Postconditions
0138         @code
0139         this->buffer().data() == s.data()
0140         @endcode
0141 
0142         @par Complexity
0143         Linear in `s`.
0144 
0145         @par Exception Safety
0146         Exceptions thrown on invalid input.
0147 
0148         @throw system_error
0149         `s` contains an invalid path.
0150 
0151         @param s The string to parse.
0152 
0153         @par BNF
0154         @code
0155         path = [ "/" ] [ segment *( "/" segment ) ]
0156 
0157         segment = *pchar
0158         @endcode
0159 
0160         @par Specification
0161         @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3"
0162             >3.3.  Path</a>
0163     */
0164     BOOST_URL_DECL
0165     segments_view(
0166         core::string_view s);
0167 
0168     /** Assignment
0169 
0170         After assignment, both views
0171         reference the same underlying character
0172         buffer.
0173 
0174         Ownership is not transferred; the caller
0175         is responsible for ensuring the lifetime
0176         of the buffer extends until it is no
0177         longer referenced.
0178 
0179         @par Postconditions
0180         @code
0181         this->buffer().data() == other.buffer().data()
0182         @endcode
0183 
0184         @par Complexity
0185         Constant
0186 
0187         @par Exception Safety
0188         Throws nothing
0189 
0190         @param other The other view.
0191         @return A reference to this object.
0192     */
0193     segments_view&
0194     operator=(segments_view const& other) = default;
0195 };
0196 
0197 } // urls
0198 } // boost
0199 
0200 #endif