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