Back to home page

EIC code displayed by LXR

 
 

    


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_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     params_view(
0104         params_view const& other) = default;
0105 
0106     /** Constructor
0107 
0108         After construction both views will
0109         reference the same character buffer
0110         but this instance will use the specified
0111         @ref encoding_opts when the values
0112         are decoded.
0113 
0114         Ownership is not transferred; the caller
0115         is responsible for ensuring the lifetime
0116         of the buffer extends until it is no
0117         longer referenced.
0118 
0119         @par Postconditions
0120         @code
0121         this->buffer().data() == other.buffer().data()
0122         @endcode
0123 
0124         @par Complexity
0125         Constant.
0126 
0127         @par Exception Safety
0128         Throws nothing
0129     */
0130     params_view(
0131         params_view const& other,
0132         encoding_opts opt) noexcept;
0133 
0134     /** Constructor
0135 
0136         This function constructs params from
0137         a valid query parameter string, which
0138         can contain percent escapes. Unlike
0139         the parameters in URLs, the string
0140         passed here should not start with "?".
0141         Upon construction, the view references
0142         the character buffer pointed to by `s`.
0143         The caller is responsible for ensuring
0144         that the lifetime of the buffer extends
0145         until it is no longer referenced.
0146 
0147         @par Example
0148         @code
0149         params_view qp( "first=John&last=Doe" );
0150         @endcode
0151 
0152         @par Effects
0153         @code
0154         return parse_query( s ).value();
0155         @endcode
0156 
0157         @par Postconditions
0158         @code
0159         this->buffer().data() == s.data()
0160         @endcode
0161 
0162         @par Complexity
0163         Linear in `s`.
0164 
0165         @par Exception Safety
0166         Exceptions thrown on invalid input.
0167 
0168         @throw system_error
0169         `s` contains an invalid query parameter
0170         string.
0171 
0172         @param s The string to parse.
0173 
0174         @par BNF
0175         @code
0176         query-params    = [ query-param ] *( "&" query-param )
0177 
0178         query-param     = key [ "=" value ]
0179         @endcode
0180 
0181         @par Specification
0182         @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4"
0183             >3.4.  Query</a>
0184     */
0185     BOOST_URL_DECL
0186     params_view(
0187         core::string_view s);
0188 
0189     /** Constructor
0190 
0191         This function constructs params from
0192         a valid query parameter string, which
0193         can contain percent escapes.
0194 
0195         This instance will use the specified
0196         @ref encoding_opts when the values
0197         are decoded.
0198 
0199         Unlike the parameters in URLs, the string
0200         passed here should not start with "?".
0201         Upon construction, the view will
0202         reference the character buffer pointed
0203         to by `s`. The caller is responsible
0204         for ensuring that the lifetime of the
0205         buffer extends until it is no longer
0206         referenced.
0207 
0208         @par Example
0209         @code
0210         encoding_opts opt;
0211         opt.space_as_plus = true;
0212         params_view qp( "name=John+Doe", opt );
0213         @endcode
0214 
0215         @par Effects
0216         @code
0217         return params_view(parse_query( s ).value(), opt);
0218         @endcode
0219 
0220         @par Postconditions
0221         @code
0222         this->buffer().data() == s.data()
0223         @endcode
0224 
0225         @par Complexity
0226         Linear in `s`.
0227 
0228         @par Exception Safety
0229         Exceptions thrown on invalid input.
0230 
0231         @throw system_error
0232         `s` contains an invalid query parameter
0233         string.
0234 
0235         @param s The string to parse.
0236 
0237         @param opt The options for decoding. If
0238         this parameter is omitted, `space_as_plus`
0239         is used.
0240 
0241         @par BNF
0242         @code
0243         query-params    = [ query-param ] *( "&" query-param )
0244 
0245         query-param     = key [ "=" value ]
0246         @endcode
0247 
0248         @par Specification
0249         @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4"
0250             >3.4.  Query</a>
0251     */
0252     BOOST_URL_DECL
0253     params_view(
0254         core::string_view s,
0255         encoding_opts opt);
0256 
0257     /** Assignment
0258 
0259         After assignment, both views reference
0260         the same underlying character buffer.
0261 
0262         Ownership is not transferred; the caller
0263         is responsible for ensuring the lifetime
0264         of the buffer extends until it is no
0265         longer referenced.
0266 
0267         @par Postconditions
0268         @code
0269         this->buffer().data() == other.buffer().data()
0270         @endcode
0271 
0272         @par Complexity
0273         Constant
0274 
0275         @par Exception Safety
0276         Throws nothing
0277     */
0278     params_view&
0279     operator=(
0280         params_view const&) = default;
0281 };
0282 
0283 } // urls
0284 } // boost
0285 
0286 #endif