@@ -119,7 +119,7 @@ class uri {
119
119
120
120
public:
121
121
/* *
122
- * \brief Constructor .
122
+ * \brief Default constructor .
123
123
*/
124
124
uri ();
125
125
@@ -205,78 +205,135 @@ class uri {
205
205
* underlying sequence.
206
206
* \return An iterator starting at the first element.
207
207
*/
208
- const_iterator begin () const ;
208
+ const_iterator begin () const noexcept ;
209
209
210
210
/* *
211
211
* \brief Returns an iterator at the end + 1th element in the
212
212
* underlying sequence.
213
213
* \return An iterator starting at the end + 1th element.
214
214
*/
215
- const_iterator end () const ;
215
+ const_iterator end () const noexcept ;
216
+
217
+ /* *
218
+ * \brief Tests whether this URI has a scheme component.
219
+ * \return \c true if the URI has a scheme, \c false otherwise.
220
+ */
221
+ bool has_scheme () const noexcept ;
216
222
217
223
/* *
218
224
* \brief Returns the URI scheme.
219
- * \return The scheme, if it exists, or nullopt.
225
+ * \return The scheme.
226
+ * \pre has_scheme()
227
+ */
228
+ string_view scheme () const noexcept ;
229
+
230
+ /* *
231
+ * \brief Tests whether this URI has a user info component.
232
+ * \return \c true if the URI has a user info, \c false otherwise.
220
233
*/
221
- optional<string_view> scheme () const ;
234
+ bool has_user_info () const noexcept ;
222
235
223
236
/* *
224
237
* \brief Returns the URI user info.
225
- * \return The user info, if it exists, or nullopt.
238
+ * \return The user info.
239
+ * \pre has_user_info()
226
240
*/
227
- optional<string_view> user_info () const ;
241
+ string_view user_info () const noexcept ;
242
+
243
+ /* *
244
+ * \brief Tests whether this URI has a host component.
245
+ * \return \c true if the URI has a host, \c false otherwise.
246
+ */
247
+ bool has_host () const noexcept ;
228
248
229
249
/* *
230
250
* \brief Returns the URI host.
231
- * \return The host, if it exists, or nullopt.
251
+ * \return The host.
252
+ * \pre has_host()
232
253
*/
233
- optional<string_view> host () const ;
254
+ string_view host () const noexcept ;
255
+
256
+ /* *
257
+ * \brief Tests whether this URI has a port component.
258
+ * \return \c true if the URI has a port, \c false otherwise.
259
+ */
260
+ bool has_port () const noexcept ;
234
261
235
262
/* *
236
263
* \brief Returns the URI port.
237
- * \return The port, if it exists, or nullopt.
264
+ * \return The port.
265
+ * \pre has_port()
238
266
*/
239
- optional< string_view> port () const ;
267
+ string_view port () const noexcept ;
240
268
241
269
/* *
242
270
* \brief Returns the URI port as an integer.
243
- * \return The port, if it exists, or nullopt.
271
+ * \return The port number.
272
+ * \pre has_port()
244
273
*/
245
274
template <typename IntT>
246
- optional<IntT> port (typename std::is_integral<IntT>::type * = 0 ) const {
247
- if (auto p = port ()) {
248
- try {
249
- return std::stoi (string_type (std::begin (*p), std::end (*p)));
250
- } catch (std::exception &) {
251
- return optional<IntT>();
252
- }
275
+ IntT port (typename std::is_integral<IntT>::type * = 0 ) const {
276
+ assert (has_port ());
277
+
278
+ auto p = port ();
279
+ try {
280
+ return std::stoi (port ().to_string ());
281
+ }
282
+ catch (std::exception &) {
283
+ assert (!" Unable to parse port number." );
253
284
}
254
- return optional<IntT>();
255
285
}
256
286
287
+ /* *
288
+ * \brief Tests whether this URI has a path component.
289
+ * \return \c true if the URI has a path, \c false otherwise.
290
+ */
291
+ bool has_path () const noexcept ;
292
+
257
293
/* *
258
294
* \brief Returns the URI path.
259
- * \return The path, if it exists, or nullopt.
295
+ * \return The path.
296
+ * \pre has_path()
297
+ */
298
+ string_view path () const noexcept ;
299
+
300
+ /* *
301
+ * \brief Tests whether this URI has a query component.
302
+ * \return \c true if the URI has a query, \c false otherwise.
260
303
*/
261
- optional<string_view> path () const ;
304
+ bool has_query () const noexcept ;
262
305
263
306
/* *
264
307
* \brief Returns the URI query.
265
- * \return The query, if it exists, or nullopt.
308
+ * \return The query.
309
+ * \pre has_query()
266
310
*/
267
- optional<string_view> query () const ;
311
+ string_view query () const noexcept ;
312
+
313
+ /* *
314
+ * \brief Tests whether this URI has a fragment component.
315
+ * \return \c true if the URI has a fragment, \c false otherwise.
316
+ */
317
+ bool has_fragment () const noexcept ;
268
318
269
319
/* *
270
320
* \brief Returns the URI fragment.
271
- * \return The fragment, if it exists, or nullopt.
321
+ * \return The fragment.
322
+ * \pre has_fragment()
323
+ */
324
+ string_view fragment () const noexcept ;
325
+
326
+ /* *
327
+ * \brief Tests whether this URI has a valid authority.
328
+ * \return \c true if the URI has an authority, \c false otherwise.
272
329
*/
273
- optional<string_view> fragment () const ;
330
+ bool has_authority () const noexcept ;
274
331
275
332
/* *
276
333
* \brief Returns the URI authority.
277
- * \return The authority, if it exists, or nullopt .
334
+ * \return The authority.
278
335
*/
279
- optional< string_view> authority () const ;
336
+ string_view authority () const noexcept ;
280
337
281
338
#if !defined(NETWORK_URI_MSVC)
282
339
/* *
@@ -333,14 +390,14 @@ class uri {
333
390
* \brief Checks if the uri is absolute, i.e. it has a scheme.
334
391
* \returns \c true if it is absolute, \c false if it is relative.
335
392
*/
336
- bool is_absolute () const ;
393
+ bool is_absolute () const noexcept ;
337
394
338
395
/* *
339
396
* \brief Checks if the uri is opaque, i.e. if it doesn't have an
340
397
* authority.
341
398
* \returns \c true if it is opaque, \c false if it is hierarchical.
342
399
*/
343
- bool is_opaque () const ;
400
+ bool is_opaque () const noexcept ;
344
401
345
402
/* *
346
403
* \brief Normalizes a uri object at a given level in the
0 commit comments