![]() |
|
|||
File indexing completed on 2025-09-17 08:52:42
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_PARAMS_VIEW_HPP 0012 #define BOOST_URL_PARAMS_VIEW_HPP 0013 0014 #include <boost/url/detail/config.hpp> 0015 #include <boost/url/params_base.hpp> 0016 0017 namespace boost { 0018 namespace urls { 0019 0020 /** A view representing query parameters in a URL 0021 0022 Objects of this type are used to interpret 0023 the query parameters as a bidirectional view 0024 of key/value pairs. 0025 0026 The view does not retain ownership of the 0027 elements and instead references the original 0028 character buffer. The caller is responsible 0029 for ensuring that the lifetime of the buffer 0030 extends until it is no longer referenced. 0031 0032 @par Example 0033 @code 0034 url_view u( "?first=John&last=Doe" ); 0035 0036 params_view p = u.params(); 0037 @endcode 0038 0039 Percent escapes in strings returned when 0040 dereferencing iterators are automatically 0041 decoded. 0042 0043 @par Iterator Invalidation 0044 Changes to the underlying character buffer 0045 can invalidate iterators which reference it. 0046 */ 0047 class params_view 0048 : public params_base 0049 { 0050 friend class url_view_base; 0051 friend class params_encoded_view; 0052 friend class params_ref; 0053 0054 params_view( 0055 detail::query_ref const& ref, 0056 encoding_opts opt) noexcept; 0057 0058 public: 0059 /** Constructor 0060 0061 Default-constructed params have 0062 zero elements. 0063 0064 @par Example 0065 @code 0066 params_view qp; 0067 @endcode 0068 0069 @par Effects 0070 @code 0071 return params_view( "" ); 0072 @endcode 0073 0074 @par Complexity 0075 Constant. 0076 0077 @par Exception Safety 0078 Throws nothing. 0079 */ 0080 params_view() = default; 0081 0082 /** Constructor 0083 0084 After construction both views reference 0085 the same character buffer. 0086 0087 Ownership is not transferred; the caller 0088 is responsible for ensuring the lifetime 0089 of the buffer extends until it is no 0090 longer referenced. 0091 0092 @par Postconditions 0093 @code 0094 this->buffer().data() == other.buffer().data() 0095 @endcode 0096 0097 @par Complexity 0098 Constant. 0099 0100 @par Exception Safety 0101 Throws nothing 0102 0103 @param other The object to copy 0104 */ 0105 params_view( 0106 params_view const& other) = default; 0107 0108 /** Constructor 0109 0110 After construction both views will 0111 reference the same character buffer 0112 but this instance will use the specified 0113 @ref encoding_opts when the values 0114 are decoded. 0115 0116 Ownership is not transferred; the caller 0117 is responsible for ensuring the lifetime 0118 of the buffer extends until it is no 0119 longer referenced. 0120 0121 @par Postconditions 0122 @code 0123 this->buffer().data() == other.buffer().data() 0124 @endcode 0125 0126 @par Complexity 0127 Constant. 0128 0129 @par Exception Safety 0130 Throws nothing 0131 0132 @param other The object to copy 0133 @param opt The options for decoding 0134 */ 0135 params_view( 0136 params_view const& other, 0137 encoding_opts opt) noexcept; 0138 0139 /** Constructor 0140 0141 This function constructs params from 0142 a valid query parameter string, which 0143 can contain percent escapes. Unlike 0144 the parameters in URLs, the string 0145 passed here should not start with "?". 0146 Upon construction, the view references 0147 the character buffer pointed to by `s`. 0148 The caller is responsible for ensuring 0149 that the lifetime of the buffer extends 0150 until it is no longer referenced. 0151 0152 @par Example 0153 @code 0154 params_view qp( "first=John&last=Doe" ); 0155 @endcode 0156 0157 @par Effects 0158 @code 0159 return parse_query( s ).value(); 0160 @endcode 0161 0162 @par Postconditions 0163 @code 0164 this->buffer().data() == s.data() 0165 @endcode 0166 0167 @par Complexity 0168 Linear in `s`. 0169 0170 @par Exception Safety 0171 Exceptions thrown on invalid input. 0172 0173 @throw system_error 0174 `s` contains an invalid query parameter 0175 string. 0176 0177 @param s The string to parse. 0178 0179 @par BNF 0180 @code 0181 query-params = [ query-param ] *( "&" query-param ) 0182 0183 query-param = key [ "=" value ] 0184 @endcode 0185 0186 @par Specification 0187 @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4" 0188 >3.4. Query</a> 0189 */ 0190 BOOST_URL_DECL 0191 params_view( 0192 core::string_view s); 0193 0194 /** Constructor 0195 0196 This function constructs params from 0197 a valid query parameter string, which 0198 can contain percent escapes. 0199 0200 This instance will use the specified 0201 @ref encoding_opts when the values 0202 are decoded. 0203 0204 Unlike the parameters in URLs, the string 0205 passed here should not start with "?". 0206 Upon construction, the view will 0207 reference the character buffer pointed 0208 to by `s`. The caller is responsible 0209 for ensuring that the lifetime of the 0210 buffer extends until it is no longer 0211 referenced. 0212 0213 @par Example 0214 @code 0215 encoding_opts opt; 0216 opt.space_as_plus = true; 0217 params_view qp( "name=John+Doe", opt ); 0218 @endcode 0219 0220 @par Effects 0221 @code 0222 return params_view(parse_query( s ).value(), opt); 0223 @endcode 0224 0225 @par Postconditions 0226 @code 0227 this->buffer().data() == s.data() 0228 @endcode 0229 0230 @par Complexity 0231 Linear in `s`. 0232 0233 @par Exception Safety 0234 Exceptions thrown on invalid input. 0235 0236 @throw system_error 0237 `s` contains an invalid query parameter 0238 string. 0239 0240 @param s The string to parse. 0241 0242 @param opt The options for decoding. If 0243 this parameter is omitted, `space_as_plus` 0244 is used. 0245 0246 @par BNF 0247 @code 0248 query-params = [ query-param ] *( "&" query-param ) 0249 0250 query-param = key [ "=" value ] 0251 @endcode 0252 0253 @par Specification 0254 @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4" 0255 >3.4. Query</a> 0256 */ 0257 BOOST_URL_DECL 0258 params_view( 0259 core::string_view s, 0260 encoding_opts opt); 0261 0262 /** Assignment 0263 0264 After assignment, both views reference 0265 the same underlying character buffer. 0266 0267 Ownership is not transferred; the caller 0268 is responsible for ensuring the lifetime 0269 of the buffer extends until it is no 0270 longer referenced. 0271 0272 @par Postconditions 0273 @code 0274 this->buffer().data() == other.buffer().data() 0275 @endcode 0276 0277 @par Complexity 0278 Constant 0279 0280 @par Exception Safety 0281 Throws nothing 0282 0283 @param other The object to assign 0284 @return A reference to this object 0285 */ 0286 params_view& 0287 operator=( 0288 params_view const& other) = default; 0289 }; 0290 0291 } // urls 0292 } // boost 0293 0294 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |