Skip to content

Commit b063472

Browse files
committed
Refactor out uri_parser, moving it into the underlying uri implementation
1 parent 8ccd130 commit b063472

File tree

12 files changed

+888
-1073
lines changed

12 files changed

+888
-1073
lines changed

Release/include/cpprest/asyncrt_utils.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,16 @@ namespace conversions
269269
return val;
270270
}
271271

272+
template<typename Source>
273+
utf8string print_utf8string(const Source& val)
274+
{
275+
return conversions::to_utf8string(print_string(val));
276+
}
277+
inline const utf8string& print_utf8string(const utf8string& val)
278+
{
279+
return val;
280+
}
281+
272282
template <typename Target>
273283
Target scan_string(const utility::string_t &str)
274284
{
@@ -407,9 +417,9 @@ class windows_category_impl : public std::error_category
407417
public:
408418
virtual const char *name() const CPPREST_NOEXCEPT { return "windows"; }
409419

410-
_ASYNCRTIMP virtual std::string message(int errorCode) const CPPREST_NOEXCEPT;
420+
virtual std::string message(int errorCode) const CPPREST_NOEXCEPT;
411421

412-
_ASYNCRTIMP virtual std::error_condition default_error_condition(int errorCode) const CPPREST_NOEXCEPT;
422+
virtual std::error_condition default_error_condition(int errorCode) const CPPREST_NOEXCEPT;
413423
};
414424

415425
/// <summary>

Release/include/cpprest/base_uri.h

Lines changed: 25 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -27,58 +27,13 @@ namespace web {
2727
{
2828
struct uri_components
2929
{
30-
uri_components() : m_path(_XPLATSTR("/")), m_port(-1)
31-
{}
32-
33-
uri_components(const uri_components &other) :
34-
m_scheme(other.m_scheme),
35-
m_host(other.m_host),
36-
m_user_info(other.m_user_info),
37-
m_path(other.m_path),
38-
m_query(other.m_query),
39-
m_fragment(other.m_fragment),
40-
m_port(other.m_port)
41-
{}
42-
43-
uri_components & operator=(const uri_components &other)
44-
{
45-
if (this != &other)
46-
{
47-
m_scheme = other.m_scheme;
48-
m_host = other.m_host;
49-
m_user_info = other.m_user_info;
50-
m_path = other.m_path;
51-
m_query = other.m_query;
52-
m_fragment = other.m_fragment;
53-
m_port = other.m_port;
54-
}
55-
return *this;
56-
}
57-
58-
uri_components(uri_components &&other) CPPREST_NOEXCEPT :
59-
m_scheme(std::move(other.m_scheme)),
60-
m_host(std::move(other.m_host)),
61-
m_user_info(std::move(other.m_user_info)),
62-
m_path(std::move(other.m_path)),
63-
m_query(std::move(other.m_query)),
64-
m_fragment(std::move(other.m_fragment)),
65-
m_port(other.m_port)
66-
{}
67-
68-
uri_components & operator=(uri_components &&other) CPPREST_NOEXCEPT
69-
{
70-
if (this != &other)
71-
{
72-
m_scheme = std::move(other.m_scheme);
73-
m_host = std::move(other.m_host);
74-
m_user_info = std::move(other.m_user_info);
75-
m_path = std::move(other.m_path);
76-
m_query = std::move(other.m_query);
77-
m_fragment = std::move(other.m_fragment);
78-
m_port = other.m_port;
79-
}
80-
return *this;
81-
}
30+
uri_components() : m_path(_XPLATSTR("/")), m_port(-1) {}
31+
32+
uri_components(const uri_components &other) = default;
33+
uri_components & operator=(const uri_components &other) = default;
34+
35+
uri_components(uri_components &&other) = default;
36+
uri_components & operator=(uri_components &&other) = default;
8237

8338
_ASYNCRTIMP utility::string_t join();
8439

@@ -174,9 +129,8 @@ namespace web {
174129
/// Encodes a string by converting all characters except for RFC 3986 unreserved characters to their
175130
/// hexadecimal representation.
176131
/// </summary>
177-
/// <param name="utf8data">The UTF-8 string data.</param>
178132
/// <returns>The encoded string.</returns>
179-
_ASYNCRTIMP static utility::string_t __cdecl encode_data_string(const utility::string_t &utf8data);
133+
_ASYNCRTIMP static utility::string_t __cdecl encode_data_string(const utility::string_t &data);
180134

181135
/// <summary>
182136
/// Decodes an encoded string.
@@ -202,20 +156,17 @@ namespace web {
202156
/// <summary>
203157
/// Validates a string as a URI.
204158
/// </summary>
159+
/// <remarks>
160+
/// This function accepts both uris ('http://msn.com') and uri relative-references ('path1/path2?query').
161+
/// </remarks>
205162
/// <param name="uri_string">The URI string to be validated.</param>
206163
/// <returns><c>true</c> if the given string represents a valid URI, <c>false</c> otherwise.</returns>
207164
_ASYNCRTIMP static bool __cdecl validate(const utility::string_t &uri_string);
208165

209166
/// <summary>
210167
/// Creates an empty uri
211168
/// </summary>
212-
uri() { m_uri = _XPLATSTR("/");};
213-
214-
/// <summary>
215-
/// Creates a URI from the given URI components.
216-
/// </summary>
217-
/// <param name="components">A URI components object to create the URI instance.</param>
218-
_ASYNCRTIMP uri(const details::uri_components &components);
169+
uri() : m_uri(_XPLATSTR("/")) {}
219170

220171
/// <summary>
221172
/// Creates a URI from the given encoded string. This will throw an exception if the string
@@ -234,44 +185,22 @@ namespace web {
234185
/// <summary>
235186
/// Copy constructor.
236187
/// </summary>
237-
uri(const uri &other) :
238-
m_uri(other.m_uri),
239-
m_components(other.m_components)
240-
{}
188+
uri(const uri &other) = default;
241189

242190
/// <summary>
243191
/// Copy assignment operator.
244192
/// </summary>
245-
uri & operator=(const uri &other)
246-
{
247-
if (this != &other)
248-
{
249-
m_uri = other.m_uri;
250-
m_components = other.m_components;
251-
}
252-
return *this;
253-
}
193+
uri & operator=(const uri &other) = default;
254194

255195
/// <summary>
256196
/// Move constructor.
257197
/// </summary>
258-
uri(uri &&other) CPPREST_NOEXCEPT :
259-
m_uri(std::move(other.m_uri)),
260-
m_components(std::move(other.m_components))
261-
{}
198+
uri(uri &&other) = default;
262199

263200
/// <summary>
264201
/// Move assignment operator
265202
/// </summary>
266-
uri & operator=(uri &&other) CPPREST_NOEXCEPT
267-
{
268-
if (this != &other)
269-
{
270-
m_uri = std::move(other.m_uri);
271-
m_components = std::move(other.m_components);
272-
}
273-
return *this;
274-
}
203+
uri & operator=(uri &&other) = default;
275204

276205
/// <summary>
277206
/// Get the scheme component of the URI as an encoded string.
@@ -372,7 +301,7 @@ namespace web {
372301
return !(is_empty() || is_host_loopback() || is_host_wildcard());
373302
}
374303

375-
// <summary>
304+
/// <summary>
376305
/// A default port is one where the port is unspecified, and will be determined by the operating system.
377306
/// The choice of default port may be dictated by the scheme (http -> 80) or not.
378307
/// </summary>
@@ -434,8 +363,14 @@ namespace web {
434363
private:
435364
friend class uri_builder;
436365

437-
// Encodes all characters not in given set determined by given function.
438-
_ASYNCRTIMP static utility::string_t __cdecl encode_impl(const utility::string_t &raw, const std::function<bool __cdecl(int)>& should_encode);
366+
/// <summary>
367+
/// Creates a URI from the given URI components.
368+
/// </summary>
369+
/// <param name="components">A URI components object to create the URI instance.</param>
370+
_ASYNCRTIMP uri(const details::uri_components &components);
371+
372+
// Used by uri_builder
373+
static utility::string_t __cdecl encode_query_impl(const utf8string& raw);
439374

440375
utility::string_t m_uri;
441376
details::uri_components m_components;

0 commit comments

Comments
 (0)