|
||||
File indexing completed on 2024-11-15 09:33:34
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_BASE_HPP 0012 #define BOOST_URL_SEGMENTS_ENCODED_BASE_HPP 0013 0014 #include <boost/url/detail/config.hpp> 0015 #include <boost/url/ignore_case.hpp> 0016 #include <boost/url/pct_string_view.hpp> 0017 #include <boost/url/detail/url_impl.hpp> 0018 #include <iosfwd> 0019 0020 namespace boost { 0021 namespace urls { 0022 0023 /** Common functionality for containers 0024 0025 This base class is used by the library 0026 to provide common member functions for 0027 containers. This cannot be instantiated 0028 directly; Instead, use one of the 0029 containers or functions: 0030 0031 @par Containers 0032 @li @ref segments_ref 0033 @li @ref segments_view 0034 @li @ref segments_encoded_ref 0035 @li @ref segments_encoded_view 0036 */ 0037 class segments_encoded_base 0038 { 0039 detail::path_ref ref_; 0040 0041 friend class url_view_base; 0042 friend class segments_encoded_ref; 0043 friend class segments_encoded_view; 0044 0045 segments_encoded_base( 0046 detail::path_ref const& ref) noexcept; 0047 segments_encoded_base() = default; 0048 segments_encoded_base( 0049 segments_encoded_base const&) = default; 0050 segments_encoded_base& operator=( 0051 segments_encoded_base const&) = default; 0052 0053 public: 0054 /** A Bidirectional iterator to a path segment 0055 0056 Objects of this type allow iteration 0057 through the segments in the path. 0058 Strings returned by iterators may 0059 contain percent escapes. 0060 The values returned are read-only; 0061 changes to segments must be made 0062 through the container instead, if the 0063 container supports modification. 0064 0065 <br> 0066 0067 The strings produced when iterators 0068 are dereferenced refer to the underlying 0069 character buffer. 0070 Ownership is not transferred; the caller 0071 is responsible for ensuring that the 0072 lifetime of the buffer extends until 0073 it is no longer referenced by any 0074 container or iterator. 0075 */ 0076 #ifdef BOOST_URL_DOCS 0077 using iterator = __see_below__; 0078 #else 0079 class iterator; 0080 #endif 0081 0082 /// @copydoc iterator 0083 using const_iterator = iterator; 0084 0085 /** The value type 0086 0087 Values of this type represent a segment 0088 where unique ownership is retained by 0089 making a copy. 0090 0091 @par Example 0092 @code 0093 segments_encoded_base::value_type ps( url_view( "/path/to/file.txt" ).encoded_segments().back() ); 0094 @endcode 0095 */ 0096 using value_type = std::string; 0097 0098 /** The reference type 0099 0100 This is the type of value returned when 0101 iterators of the view are dereferenced. 0102 */ 0103 using reference = pct_string_view; 0104 0105 /// @copydoc reference 0106 using const_reference = pct_string_view; 0107 0108 /** An unsigned integer type used to represent size. 0109 */ 0110 using size_type = std::size_t; 0111 0112 /** A signed integer type used to represent differences. 0113 */ 0114 using difference_type = std::ptrdiff_t; 0115 0116 //-------------------------------------------- 0117 // 0118 // Observers 0119 // 0120 //-------------------------------------------- 0121 0122 /** Return the maximum number of characters possible 0123 0124 This represents the largest number of 0125 characters that are possible in a path, 0126 not including any null terminator. 0127 0128 @par Exception Safety 0129 Throws nothing. 0130 */ 0131 static 0132 constexpr 0133 std::size_t 0134 max_size() noexcept 0135 { 0136 return BOOST_URL_MAX_SIZE; 0137 } 0138 0139 /** Return the referenced character buffer. 0140 0141 This function returns the character 0142 buffer referenced by the view. 0143 The returned string may contain 0144 percent escapes. 0145 0146 @par Example 0147 @code 0148 assert( url_view( "/path/to/file.txt" ).encoded_segments().buffer() == "/path/to/file.txt" ); 0149 @endcode 0150 0151 @par Complexity 0152 Constant. 0153 0154 @par Exception Safety 0155 Throws nothing. 0156 */ 0157 BOOST_URL_DECL 0158 pct_string_view 0159 buffer() const noexcept; 0160 0161 /** Returns true if this references an absolute path. 0162 0163 Absolute paths always start with a 0164 forward slash ('/'). 0165 0166 @par Example 0167 @code 0168 assert( url_view( "/path/to/file.txt" ).encoded_segments().is_absolute() == true ); 0169 @endcode 0170 0171 @par Complexity 0172 Constant. 0173 0174 @par Exception Safety 0175 Throws nothing. 0176 */ 0177 BOOST_URL_DECL 0178 bool 0179 is_absolute() const noexcept; 0180 0181 /** Return true if there are no segments 0182 0183 @par Example 0184 @code 0185 assert( ! url_view( "/index.htm" ).encoded_segments().empty() ); 0186 @endcode 0187 0188 @par Complexity 0189 Constant. 0190 0191 @par Exception Safety 0192 Throws nothing. 0193 */ 0194 BOOST_URL_DECL 0195 bool 0196 empty() const noexcept; 0197 0198 /** Return the number of segments 0199 0200 @par Example 0201 @code 0202 assert( url_view( "/path/to/file.txt" ).encoded_segments().size() == 3 ); 0203 @endcode 0204 0205 @par Complexity 0206 Constant. 0207 0208 @par Exception Safety 0209 Throws nothing. 0210 */ 0211 BOOST_URL_DECL 0212 std::size_t 0213 size() const noexcept; 0214 0215 /** Return the first segment 0216 0217 This function returns a string with the 0218 first segment of the path without any 0219 leading or trailing '/' separators. 0220 The returned string may contain 0221 percent escapes. 0222 0223 @par Preconditions 0224 @code 0225 this->empty() == false 0226 @endcode 0227 0228 @par Effects 0229 @code 0230 return *begin(); 0231 @endcode 0232 0233 @par Example 0234 @code 0235 assert( url_view( "/path/to/file.txt" ).encoded_segments().front() == "path" ); 0236 @endcode 0237 0238 @par Complexity 0239 Constant. 0240 0241 @par Exception Safety 0242 Throws nothing. 0243 */ 0244 pct_string_view 0245 front() const noexcept; 0246 0247 /** Return the last segment 0248 0249 This function returns a string with the 0250 last segment of the path without any 0251 leading or trailing '/' separators. 0252 The returned string may contain 0253 percent escapes. 0254 0255 @par Preconditions 0256 @code 0257 this->empty() == false 0258 @endcode 0259 0260 @par Example 0261 @code 0262 assert( url_view( "/path/to/file.txt" ).encoded_segments().back() == "file.txt" ); 0263 @endcode 0264 0265 @par Preconditions 0266 @code 0267 this->empty() == false 0268 @endcode 0269 0270 @par Effects 0271 @code 0272 return *--end(); 0273 @endcode 0274 0275 @par Complexity 0276 Constant. 0277 0278 @par Exception Safety 0279 Throws nothing. 0280 */ 0281 pct_string_view 0282 back() const noexcept; 0283 0284 /** Return an iterator to the beginning 0285 0286 @par Complexity 0287 Linear in `this->front().size()` or 0288 constant if `this->empty()`. 0289 0290 @par Exception Safety 0291 Throws nothing. 0292 */ 0293 BOOST_URL_DECL 0294 iterator 0295 begin() const noexcept; 0296 0297 /** Return an iterator to the end 0298 0299 @par Complexity 0300 Constant. 0301 0302 @par Exception Safety 0303 Throws nothing. 0304 */ 0305 BOOST_URL_DECL 0306 iterator 0307 end() const noexcept; 0308 }; 0309 0310 //------------------------------------------------ 0311 0312 /** Format to an output stream 0313 0314 Any percent-escapes are emitted as-is; 0315 no decoding is performed. 0316 0317 @par Complexity 0318 Linear in `ps.buffer().size()`. 0319 0320 @par Effects 0321 @code 0322 return os << ps.buffer(); 0323 @endcode 0324 */ 0325 BOOST_URL_DECL 0326 std::ostream& 0327 operator<<( 0328 std::ostream& os, 0329 segments_encoded_base const& ps); 0330 0331 } // urls 0332 } // boost 0333 0334 #include <boost/url/impl/segments_encoded_base.hpp> 0335 0336 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |