40
40
namespace web {
41
41
namespace details
42
42
{
43
- struct _uri_components
43
+ struct uri_components
44
44
{
45
- _uri_components ()
45
+ uri_components () : m_path(_XPLATSTR(" /" )), m_port(-1 )
46
+ {}
47
+
48
+ uri_components (const uri_components &other) :
49
+ m_scheme (other.m_scheme),
50
+ m_host (other.m_host),
51
+ m_user_info (other.m_user_info),
52
+ m_path (other.m_path),
53
+ m_query (other.m_query),
54
+ m_fragment (other.m_fragment),
55
+ m_port (other.m_port)
56
+ {}
57
+
58
+ uri_components & operator =(const uri_components &other)
46
59
{
47
- m_path = _XPLATSTR (" /" );
48
- m_port = -1 ;
60
+ if (this != &other)
61
+ {
62
+ m_scheme = other.m_scheme ;
63
+ m_host = other.m_host ;
64
+ m_user_info = other.m_user_info ;
65
+ m_path = other.m_path ;
66
+ m_query = other.m_query ;
67
+ m_fragment = other.m_fragment ;
68
+ m_port = other.m_port ;
69
+ }
70
+ return *this ;
49
71
}
50
72
73
+ uri_components (uri_components &&other) _noexcept :
74
+ m_scheme (std::move(other.m_scheme)),
75
+ m_host (std::move(other.m_host)),
76
+ m_user_info (std::move(other.m_user_info)),
77
+ m_path (std::move(other.m_path)),
78
+ m_query (std::move(other.m_query)),
79
+ m_fragment (std::move(other.m_fragment)),
80
+ m_port (other.m_port)
81
+ {}
82
+
83
+ uri_components & operator =(uri_components &&other) _noexcept
84
+ {
85
+ if (this != &other)
86
+ {
87
+ m_scheme = std::move (other.m_scheme );
88
+ m_host = std::move (other.m_host );
89
+ m_user_info = std::move (other.m_user_info );
90
+ m_path = std::move (other.m_path );
91
+ m_query = std::move (other.m_query );
92
+ m_fragment = std::move (other.m_fragment );
93
+ m_port = other.m_port ;
94
+ }
95
+ return *this ;
96
+ }
97
+
51
98
_ASYNCRTIMP utility::string_t join ();
52
99
53
100
utility::string_t m_scheme;
@@ -81,25 +128,25 @@ namespace web {
81
128
};
82
129
83
130
// / <summary>
84
- // / A flexible, protocol independent uri implementation.
131
+ // / A flexible, protocol independent URI implementation.
85
132
// /
86
- // / URI instances are immutable. Querying the various fields on an emtpy uri will return empty strings. Querying
87
- // / various diagnostic members on an empty uri will return false.
133
+ // / URI instances are immutable. Querying the various fields on an emtpy URI will return empty strings. Querying
134
+ // / various diagnostic members on an empty URI will return false.
88
135
// / </summary>
89
136
// / <remarks>
90
- // / This implementation accepts both uris ('http://msn.com/path') and uri relative-references
137
+ // / This implementation accepts both URIs ('http://msn.com/path') and URI relative-references
91
138
// / ('/path?query#frag').
92
139
// /
93
140
// / This implementation does not provide any scheme-specific handling -- an example of this
94
- // / would be the following: 'http://path1/path'. This is a valid uri , but it's not a valid
141
+ // / would be the following: 'http://path1/path'. This is a valid URI , but it's not a valid
95
142
// / http-uri -- that is, it's syntactically correct but does not conform to the requirements
96
143
// / of the http scheme (http requires a host).
97
144
// / We could provide this by allowing a pluggable 'scheme' policy-class, which would provide
98
- // / extra capability for validating and canonicalizing a uri according to scheme, and would
99
- // / introduce a layer of type-safety for uris of differing schemes, and thus differing semantics.
145
+ // / extra capability for validating and canonicalizing a URI according to scheme, and would
146
+ // / introduce a layer of type-safety for URIs of differing schemes, and thus differing semantics.
100
147
// /
101
- // / One issue with implementing a scheme-independent uri facility is that of comparing for equality.
102
- // / For instance, these uris are considered equal 'http://msn.com', 'http://msn.com:80'. That is --
148
+ // / One issue with implementing a scheme-independent URI facility is that of comparing for equality.
149
+ // / For instance, these URIs are considered equal 'http://msn.com', 'http://msn.com:80'. That is --
103
150
// / the 'default' port can be either omitted or explicit. Since we don't have a way to map a scheme
104
151
// / to it's default port, we don't have a way to know these are equal. This is just one of a class of
105
152
// / issues with regard to scheme-specific behavior.
@@ -168,9 +215,9 @@ namespace web {
168
215
_ASYNCRTIMP static std::map<utility::string_t , utility::string_t > __cdecl split_query (const utility::string_t &query);
169
216
170
217
// / <summary>
171
- // / Validates a string as a uri .
218
+ // / Validates a string as a URI .
172
219
// / </summary>
173
- // / <param name="uri_string">The uri string to be validated.</param>
220
+ // / <param name="uri_string">The URI string to be validated.</param>
174
221
// / <returns><c>true</c> if the given string represents a valid URI, <c>false</c> otherwise.</returns>
175
222
_ASYNCRTIMP static bool __cdecl validate (const utility::string_t &uri_string);
176
223
@@ -180,19 +227,61 @@ namespace web {
180
227
uri () { m_uri = _XPLATSTR (" /" );};
181
228
182
229
// / <summary>
183
- // / Creates a uri from the given encoded string. This will throw an exception if the string
184
- // / does not contain a valid uri . Use uri::validate if processing user-input.
230
+ // / Creates a URI from the given encoded string. This will throw an exception if the string
231
+ // / does not contain a valid URI . Use uri::validate if processing user-input.
185
232
// / </summary>
186
233
// / <param name="uri_string">A pointer to an encoded string to create the URI instance.</param>
187
234
_ASYNCRTIMP uri (const utility::char_t *uri_string);
188
235
189
236
// / <summary>
190
- // / Creates a uri from the given encoded string. This will throw an exception if the string
191
- // / does not contain a valid uri . Use uri::validate if processing user-input.
237
+ // / Creates a URI from the given encoded string. This will throw an exception if the string
238
+ // / does not contain a valid URI . Use uri::validate if processing user-input.
192
239
// / </summary>
193
- // / <param name="uri_string">An encoded uri string to create the URI instance.</param>
240
+ // / <param name="uri_string">An encoded URI string to create the URI instance.</param>
194
241
_ASYNCRTIMP uri (const utility::string_t &uri_string);
195
242
243
+ // / <summary>
244
+ // / Copy constructor.
245
+ // / </summary>
246
+ uri (const uri &other) :
247
+ m_uri (other.m_uri),
248
+ m_components (other.m_components)
249
+ {}
250
+
251
+ // / <summary>
252
+ // / Copy assignment operator.
253
+ // / </summary>
254
+ uri & operator =(const uri &other)
255
+ {
256
+ if (this != &other)
257
+ {
258
+ m_uri = other.m_uri ;
259
+ m_components = other.m_components ;
260
+ }
261
+ return *this ;
262
+ }
263
+
264
+ // / <summary>
265
+ // / Move constructor.
266
+ // / </summary>
267
+ uri (uri &&other) _noexcept :
268
+ m_uri (std::move(other.m_uri)),
269
+ m_components (std::move(other.m_components))
270
+ {}
271
+
272
+ // / <summary>
273
+ // / Move assignment operator
274
+ // / </summary>
275
+ uri & operator =(uri &&other) _noexcept
276
+ {
277
+ if (this != &other)
278
+ {
279
+ m_uri = std::move (other.m_uri );
280
+ m_components = std::move (other.m_components );
281
+ }
282
+ return *this ;
283
+ }
284
+
196
285
// / <summary>
197
286
// / Get the scheme component of the URI as an encoded string.
198
287
// / </summary>
@@ -244,11 +333,11 @@ namespace web {
244
333
// / <summary>
245
334
// / Gets the path, query, and fragment portion of this uri, which may be empty.
246
335
// / </summary>
247
- // / <returns>The new uri object with the path, query and fragment portion of this uri .</returns>
336
+ // / <returns>The new URI object with the path, query and fragment portion of this URI .</returns>
248
337
_ASYNCRTIMP uri resource () const ;
249
338
250
339
// / <summary>
251
- // / An empty uri specifies no components, and serves as a default value
340
+ // / An empty URI specifies no components, and serves as a default value
252
341
// / </summary>
253
342
bool is_empty () const
254
343
{
@@ -303,37 +392,37 @@ namespace web {
303
392
}
304
393
305
394
// / <summary>
306
- // / An "authority" uri is one with only a scheme, optional userinfo, hostname, and (optional) port.
395
+ // / An "authority" URI is one with only a scheme, optional userinfo, hostname, and (optional) port.
307
396
// / </summary>
308
- // / <returns><c>true</c> if this is an "authority" uri , <c>false</c> otherwise.</returns>
397
+ // / <returns><c>true</c> if this is an "authority" URI , <c>false</c> otherwise.</returns>
309
398
bool is_authority () const
310
399
{
311
400
return !is_empty () && is_path_empty () && query ().empty () && fragment ().empty ();
312
401
}
313
402
314
403
// / <summary>
315
- // / Returns whether the other uri has the same authority as this one
404
+ // / Returns whether the other URI has the same authority as this one
316
405
// / </summary>
317
- // / <param name="other">The uri to compare the authority with.</param>
318
- // / <returns><c>true</c> if both the uri 's have the same authority, <c>false</c> otherwise.</returns>
406
+ // / <param name="other">The URI to compare the authority with.</param>
407
+ // / <returns><c>true</c> if both the URI 's have the same authority, <c>false</c> otherwise.</returns>
319
408
bool has_same_authority (const uri &other) const
320
409
{
321
410
return !is_empty () && this ->authority () == other.authority ();
322
411
}
323
412
324
413
// / <summary>
325
- // / Returns whether the path portion of this uri is empty
414
+ // / Returns whether the path portion of this URI is empty
326
415
// / </summary>
327
- // / <returns><c>true</c> if the path portion of this uri is empty, <c>false</c> otherwise.</returns>
416
+ // / <returns><c>true</c> if the path portion of this URI is empty, <c>false</c> otherwise.</returns>
328
417
bool is_path_empty () const
329
418
{
330
419
return path ().empty () || path () == _XPLATSTR (" /" );
331
420
}
332
421
333
422
// / <summary>
334
- // / Returns the full (encoded) uri as a string.
423
+ // / Returns the full (encoded) URI as a string.
335
424
// / </summary>
336
- // / <returns>The full encoded uri string.</returns>
425
+ // / <returns>The full encoded URI string.</returns>
337
426
utility::string_t to_string () const
338
427
{
339
428
return m_uri;
@@ -358,7 +447,7 @@ namespace web {
358
447
static utility::string_t encode_impl (const utility::string_t &raw, const std::function<bool (int )>& should_encode);
359
448
360
449
utility::string_t m_uri;
361
- details::_uri_components m_components;
450
+ details::uri_components m_components;
362
451
};
363
452
364
453
} // namespace web
0 commit comments