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