diff options
author | Richard Walters <rwalters@digitalstirling.com> | 2018-07-04 16:30:34 -0700 |
---|---|---|
committer | Richard Walters <rwalters@digitalstirling.com> | 2018-07-04 16:30:34 -0700 |
commit | 872905197e3dbcdf0041930fda67cbd371c240ac (patch) | |
tree | 0f3c694e2b65eea87d0e6d3403353f0ef8f9b23e /src | |
parent | 4603102722e1cc2abc3494c9446bc576d008e7fa (diff) |
Add GenerateString (incomplete)
Add methods to set scheme, host, and query elements.
Add ability to generate URI strings out of scheme,
host, and query elements.
This does not yet support userinfo, port, or fragment elements.
Diffstat (limited to 'src')
-rw-r--r-- | src/Uri.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Uri.cpp b/src/Uri.cpp index dbc9ff6..5d36a9d 100644 --- a/src/Uri.cpp +++ b/src/Uri.cpp @@ -14,6 +14,7 @@ #include <functional> #include <inttypes.h> #include <memory> +#include <sstream> #include <string> #include <Uri/Uri.hpp> #include <vector> @@ -1243,4 +1244,35 @@ namespace Uri { target.impl_->CopyFragment(relativeReference); return target; } + + void Uri::SetScheme(const std::string& scheme) { + impl_->scheme = scheme; + } + + void Uri::SetHost(const std::string& host) { + impl_->host = host; + } + + void Uri::SetQuery(const std::string& query) { + impl_->query = query; + } + + std::string Uri::GenerateString() const { + std::ostringstream buffer; + if (!impl_->scheme.empty()) { + buffer << impl_->scheme << ':'; + } + if (!impl_->host.empty()) { + buffer << "//"; + if (ValidateIpv6Address(impl_->host)) { + buffer << '[' << impl_->host << ']'; + } else { + buffer << impl_->host; + } + } + if (!impl_->query.empty()) { + buffer << '?' << impl_->query; + } + return buffer.str(); + } } |