|
||||
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_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 /** A view representing query parameters in a URL 0026 0027 Objects of this type are used to interpret 0028 the query parameters as a bidirectional view 0029 of key/value pairs. 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( "?first=John&last=Doe" ); 0040 0041 params_encoded_view p = u.encoded_params(); 0042 @endcode 0043 0044 Strings produced when elements are returned 0045 have type @ref param_pct_view and represent 0046 encoded strings. Strings passed to member 0047 functions may contain percent escapes, and 0048 throw exceptions on invalid inputs. 0049 0050 @par Iterator Invalidation 0051 Changes to the underlying character buffer 0052 can invalidate iterators which reference it. 0053 */ 0054 class BOOST_URL_DECL params_encoded_view 0055 : public params_encoded_base 0056 { 0057 friend class url_view_base; 0058 friend class params_view; 0059 friend class params_encoded_ref; 0060 friend struct query_rule_t; 0061 0062 params_encoded_view( 0063 detail::query_ref const& ref) noexcept; 0064 0065 public: 0066 /** Constructor 0067 0068 Default-constructed params have 0069 zero elements. 0070 0071 @par Example 0072 @code 0073 params_encoded_view qp; 0074 @endcode 0075 0076 @par Effects 0077 @code 0078 return params_encoded_view( "" ); 0079 @endcode 0080 0081 @par Complexity 0082 Constant. 0083 0084 @par Exception Safety 0085 Throws nothing. 0086 */ 0087 params_encoded_view() = default; 0088 0089 /** Constructor 0090 0091 After construction both views 0092 reference the same character buffer. 0093 0094 Ownership is not transferred; the caller 0095 is responsible for ensuring the lifetime 0096 of the buffer extends until it is no 0097 longer referenced. 0098 0099 @par Postconditions 0100 @code 0101 this->buffer().data() == other.buffer().data() 0102 @endcode 0103 0104 @par Complexity 0105 Constant. 0106 0107 @par Exception Safety 0108 Throws nothing 0109 */ 0110 params_encoded_view( 0111 params_encoded_view const& other) = default; 0112 0113 /** Constructor 0114 0115 This function constructs params from 0116 a valid query parameter string, which 0117 can contain percent escapes. Unlike 0118 the parameters in URLs, the string 0119 passed here should not start with "?". 0120 Upon construction, the view 0121 references the character buffer pointed 0122 to by `s`. The caller is responsible 0123 for ensuring that the lifetime of the 0124 buffer extends until it is no longer 0125 referenced. 0126 0127 @par Example 0128 @code 0129 params_encoded_view qp( "first=John&last=Doe" ); 0130 @endcode 0131 0132 @par Effects 0133 @code 0134 return parse_query( 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 query parameter 0150 string. 0151 0152 @param s The string to parse. 0153 0154 @par BNF 0155 @code 0156 query-params = [ query-param ] *( "&" query-param ) 0157 0158 query-param = key [ "=" value ] 0159 @endcode 0160 0161 @par Specification 0162 @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4" 0163 >3.4. Query</a> 0164 */ 0165 params_encoded_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 params_encoded_view& 0191 operator=( 0192 params_encoded_view const&) = default; 0193 0194 /** Conversion 0195 0196 This conversion returns a new view which 0197 references the same underlying character 0198 buffer, and whose iterators and members 0199 return ordinary strings with decoding 0200 applied to any percent escapes. 0201 0202 Ownership is not transferred; the caller 0203 is responsible for ensuring the lifetime 0204 of the buffer extends until it is no 0205 longer referenced. 0206 0207 @par Example 0208 @code 0209 params_view qp = parse_path( "/path/to/file.txt" ).value(); 0210 @endcode 0211 0212 @par Postconditions 0213 @code 0214 params_view( *this ).buffer().data() == this->buffer().data() 0215 @endcode 0216 0217 @par Complexity 0218 Constant 0219 0220 @par Exception Safety 0221 Throws nothing 0222 */ 0223 operator 0224 params_view() const noexcept; 0225 0226 //-------------------------------------------- 0227 0228 friend 0229 BOOST_URL_DECL 0230 system::result<params_encoded_view> 0231 parse_query(core::string_view s) noexcept; 0232 }; 0233 0234 } // urls 0235 } // boost 0236 0237 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |