|
||||
File indexing completed on 2025-01-30 10:02:05
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 segments_view( 0112 segments_view const& other) = default; 0113 0114 /** Constructor 0115 0116 This function constructs segments from 0117 a valid path string, which can contain 0118 percent escapes. 0119 Upon construction, the view references 0120 the character buffer pointed to by `s`. 0121 caller is responsible for ensuring 0122 that the lifetime of the buffer 0123 extends until the view is destroyed. 0124 0125 @par Example 0126 @code 0127 segments_view ps( "/path/to/file.txt" ); 0128 @endcode 0129 0130 @par Effects 0131 @code 0132 return parse_path( s ).value(); 0133 @endcode 0134 0135 @par Postconditions 0136 @code 0137 this->buffer().data() == s.data() 0138 @endcode 0139 0140 @par Complexity 0141 Linear in `s`. 0142 0143 @par Exception Safety 0144 Exceptions thrown on invalid input. 0145 0146 @throw system_error 0147 `s` contains an invalid path. 0148 0149 @param s The string to parse. 0150 0151 @par BNF 0152 @code 0153 path = [ "/" ] [ segment *( "/" segment ) ] 0154 0155 segment = *pchar 0156 @endcode 0157 0158 @par Specification 0159 @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3" 0160 >3.3. Path</a> 0161 */ 0162 BOOST_URL_DECL 0163 segments_view( 0164 core::string_view s); 0165 0166 /** Assignment 0167 0168 After assignment, both views 0169 reference the same underlying character 0170 buffer. 0171 0172 Ownership is not transferred; the caller 0173 is responsible for ensuring the lifetime 0174 of the buffer extends until it is no 0175 longer referenced. 0176 0177 @par Postconditions 0178 @code 0179 this->buffer().data() == other.buffer().data() 0180 @endcode 0181 0182 @par Complexity 0183 Constant 0184 0185 @par Exception Safety 0186 Throws nothing 0187 */ 0188 segments_view& 0189 operator=(segments_view const& other) = default; 0190 }; 0191 0192 } // urls 0193 } // boost 0194 0195 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |