From 872905197e3dbcdf0041930fda67cbd371c240ac Mon Sep 17 00:00:00 2001 From: Richard Walters Date: Wed, 4 Jul 2018 16:30:34 -0700 Subject: 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. --- src/Uri.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src') 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 #include #include +#include #include #include #include @@ -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(); + } } -- cgit v1.2.3