|
|
|||
File indexing completed on 2025-10-30 08:36:47
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_BASE_HPP 0012 #define BOOST_URL_SEGMENTS_BASE_HPP 0013 0014 #include <boost/url/detail/config.hpp> 0015 #include <boost/url/ignore_case.hpp> 0016 #include <boost/url/detail/url_impl.hpp> 0017 #include <iosfwd> 0018 #include <string> 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_base 0038 { 0039 detail::path_ref ref_; 0040 0041 friend class url_view_base; 0042 friend class segments_ref; 0043 friend class segments_view; 0044 0045 segments_base( 0046 detail::path_ref const& ref) noexcept; 0047 segments_base() = default; 0048 segments_base( 0049 segments_base const&) = default; 0050 segments_base& operator=( 0051 segments_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 Any percent-escapes in returned strings 0059 are decoded first. 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 are 0068 dereferenced belong to the iterator and 0069 become invalidated when that particular 0070 iterator is incremented, decremented, 0071 or destroyed. 0072 */ 0073 #ifdef BOOST_URL_DOCS 0074 using iterator = __see_below__; 0075 #else 0076 0077 /** A Bidirectional iterator to a path segment 0078 0079 Objects of this type allow iteration 0080 through the segments in the path. 0081 Any percent-escapes in returned strings 0082 are decoded first. 0083 The values returned are read-only; 0084 changes to segments must be made 0085 through the container instead, if the 0086 container supports modification. 0087 0088 <br> 0089 0090 The strings produced when iterators are 0091 dereferenced belong to the iterator and 0092 become invalidated when that particular 0093 iterator is incremented, decremented, 0094 or destroyed. 0095 */ 0096 class iterator; 0097 #endif 0098 0099 /// @copydoc iterator 0100 using const_iterator = iterator; 0101 0102 /** The value type 0103 0104 Values of this type represent a segment 0105 where unique ownership is retained by 0106 making a copy. 0107 0108 @par Example 0109 @code 0110 segments_base::value_type ps( url_view( "/path/to/file.txt" ).segments().back() ); 0111 @endcode 0112 */ 0113 using value_type = std::string; 0114 0115 /** The reference type 0116 0117 This is the type of value returned when 0118 iterators of the view are dereferenced. 0119 */ 0120 using reference = std::string; 0121 0122 /// @copydoc reference 0123 using const_reference = std::string; 0124 0125 /** An unsigned integer type used to represent size. 0126 */ 0127 using size_type = std::size_t; 0128 0129 /** A signed integer type used to represent differences. 0130 */ 0131 using difference_type = std::ptrdiff_t; 0132 0133 //-------------------------------------------- 0134 // 0135 // Observers 0136 // 0137 //-------------------------------------------- 0138 0139 /** Return the maximum number of characters possible 0140 0141 This represents the largest number of 0142 characters that are possible in a path, 0143 not including any null terminator. 0144 0145 @par Exception Safety 0146 Throws nothing. 0147 0148 @return The maximum number of characters possible. 0149 */ 0150 static 0151 constexpr 0152 std::size_t 0153 max_size() noexcept 0154 { 0155 return BOOST_URL_MAX_SIZE; 0156 } 0157 0158 /** Return the referenced character buffer. 0159 0160 This function returns the character 0161 buffer referenced by the view. 0162 The returned string may contain 0163 percent escapes. 0164 0165 @par Example 0166 @code 0167 assert( url_view( "/path/to/file.txt" ).segments().buffer() == "/path/to/file.txt" ); 0168 @endcode 0169 0170 @par Complexity 0171 Constant. 0172 0173 @par Exception Safety 0174 Throws nothing. 0175 0176 @return A string containing the path. 0177 */ 0178 BOOST_URL_DECL 0179 pct_string_view 0180 buffer() const noexcept; 0181 0182 /** Returns true if this references an absolute path. 0183 0184 Absolute paths always start with a 0185 forward slash ('/'). 0186 0187 @par Example 0188 @code 0189 assert( url_view( "/path/to/file.txt" ).segments().is_absolute() == true ); 0190 @endcode 0191 0192 @par Complexity 0193 Constant. 0194 0195 @par Exception Safety 0196 Throws nothing. 0197 0198 @return `true` if the path is absolute, otherwise `false`. 0199 */ 0200 BOOST_URL_DECL 0201 bool 0202 is_absolute() const noexcept; 0203 0204 /** Return true if there are no segments 0205 0206 @par Example 0207 @code 0208 assert( ! url_view( "/index.htm" ).segments().empty() ); 0209 @endcode 0210 0211 @par Complexity 0212 Constant. 0213 0214 @par Exception Safety 0215 Throws nothing. 0216 0217 @return `true` if there are no segments, otherwise `false`. 0218 */ 0219 BOOST_URL_DECL 0220 bool 0221 empty() const noexcept; 0222 0223 /** Return the number of segments 0224 0225 @par Example 0226 @code 0227 assert( url_view( "/path/to/file.txt" ).segments().size() == 3 ); 0228 @endcode 0229 0230 @par Complexity 0231 Constant. 0232 0233 @par Exception Safety 0234 Throws nothing. 0235 0236 @return The number of segments. 0237 */ 0238 BOOST_URL_DECL 0239 std::size_t 0240 size() const noexcept; 0241 0242 /** Return the first segment 0243 0244 This function returns a string with the 0245 first segment of the path without any 0246 leading or trailing '/' separators. 0247 Any percent-escapes in the string are 0248 decoded first. 0249 0250 @par Preconditions 0251 @code 0252 this->empty() == false 0253 @endcode 0254 0255 @par Effects 0256 @code 0257 return *begin(); 0258 @endcode 0259 0260 @par Example 0261 @code 0262 assert( url_view( "/path/to/file.txt" ).segments().front() == "path" ); 0263 @endcode 0264 0265 @par Complexity 0266 Linear in `this->front().size()`. 0267 0268 @par Exception Safety 0269 Calls to allocate may throw. 0270 0271 @return The first segment. 0272 */ 0273 std::string 0274 front() const noexcept; 0275 0276 /** Return the last segment 0277 0278 @par Preconditions 0279 @code 0280 this->empty() == false 0281 @endcode 0282 0283 @par Example 0284 @code 0285 assert( url_view( "/path/to/file.txt" ).segments().back() == "file.txt" ); 0286 @endcode 0287 0288 @par Preconditions 0289 @code 0290 this->empty() == false 0291 @endcode 0292 0293 @par Effects 0294 @code 0295 return *--end(); 0296 @endcode 0297 0298 @par Complexity 0299 Linear in `this->back().size()`. 0300 0301 @par Exception Safety 0302 Calls to allocate may throw. 0303 0304 @return The last segment. 0305 */ 0306 std::string 0307 back() const noexcept; 0308 0309 /** Return an iterator to the beginning 0310 0311 @par Complexity 0312 Linear in `this->front().size()` or 0313 constant if `this->empty()`. 0314 0315 @par Exception Safety 0316 Throws nothing. 0317 0318 @return An iterator to the first segment. 0319 */ 0320 BOOST_URL_DECL 0321 iterator 0322 begin() const noexcept; 0323 0324 /** Return an iterator to the end 0325 0326 @par Complexity 0327 Constant. 0328 0329 @par Exception Safety 0330 Throws nothing. 0331 0332 @return An iterator to one past the last segment. 0333 */ 0334 BOOST_URL_DECL 0335 iterator 0336 end() const noexcept; 0337 }; 0338 0339 //------------------------------------------------ 0340 0341 /** Format to an output stream 0342 0343 Any percent-escapes are emitted as-is; 0344 no decoding is performed. 0345 0346 @par Complexity 0347 Linear in `ps.buffer().size()`. 0348 0349 @par Effects 0350 @code 0351 return os << ps.buffer(); 0352 @endcode 0353 0354 @param os The output stream to write to. 0355 @param ps The segments to write. 0356 @return A reference to the output stream. 0357 */ 0358 BOOST_URL_DECL 0359 std::ostream& 0360 operator<<( 0361 std::ostream& os, 0362 segments_base const& ps); 0363 0364 } // urls 0365 } // boost 0366 0367 #include <boost/url/impl/segments_base.hpp> 0368 0369 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|