Skip to content

Commit

Permalink
uri doc
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Dec 4, 2024
1 parent 1335609 commit 11f52df
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 7 deletions.
89 changes: 89 additions & 0 deletions doc/ref/corelib/uri.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
### jsoncons::uri

```cpp
#include <jsoncons/utility/uri.hpp>

```
The class `uri` represents a Uniform Resource Identifier (URI) reference.

#### Constructor

uri();

uri(const std::string& uri);
Constructs a URI by parsing the given string.

uri(jsoncons::string_view scheme,
jsoncons::string_view userinfo,
jsoncons::string_view host,
jsoncons::string_view port,
jsoncons::string_view path,
jsoncons::string_view query,
jsoncons::string_view fragment)
Constructs a URI from the given components.

uri(const uri& other);

uri(uri&& other) noexcept;

#### Assignment

uri& operator=(const uri& other);

uri& operator=(uri&& other) noexcept;

#### Member functions

bool is_absolute() const noexcept;
Returns true if this URI is absolute, false otherwise.

bool is_opaque() const noexcept;
Returns true if this URI is opaque, false otherwise.

uri base() const noexcept;

const std::string& string() const;

jsoncons::string_view scheme() const noexcept;

jsoncons::string_view scheme() const noexcept;

jsoncons::string_view encoded_scheme() const noexcept;

std::string userinfo() const;

jsoncons::string_view encoded_userinfo() const noexcept;

jsoncons::string_view host() const noexcept;

jsoncons::string_view encoded_host() const noexcept;

jsoncons::string_view port() const noexcept;

jsoncons::string_view encoded_port() const noexcept;

std::string authority() const;

jsoncons::string_view encoded_authority() const noexcept;

std::string path() const;

jsoncons::string_view encoded_path() const noexcept;

std::string query() const;

jsoncons::string_view encoded_query() const noexcept;

std::string query() const;

jsoncons::string_view encoded_query() const noexcept;

std::string fragment() const;

jsoncons::string_view encoded_fragment() const noexcept;

uri resolve(const uri& base) const;

### Examples


2 changes: 1 addition & 1 deletion doc/ref/jsonschema/make_json_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Returns a [json_schema<Json>](json_schema.md) that represents a compiled JSON Sc
<td>resolve</td>
<td>A function object with the signature of <code>resolve</code> being equivalent to
<pre>
Json fun(const jsoncons::uri& uri)
Json fun(const <a href="../corelib/uri.md">jsoncons::uri</a>& uri)
</pre>
If unable to resolve the resource, it should return <code>Json::null()</code>.
</td>
Expand Down
12 changes: 6 additions & 6 deletions include/jsoncons/utility/uri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ namespace jsoncons {
}
}

uri& operator=(const uri& other) noexcept
uri& operator=(const uri& other)
{
if (&other != this)
{
Expand Down Expand Up @@ -327,6 +327,11 @@ namespace jsoncons {

string_view encoded_port() const noexcept { return string_view(uri_string_.data()+port_.first,(port_.second-port_.first)); }

std::string authority() const
{
return decode_part(encoded_authority());
}

string_view encoded_authority() const noexcept { return string_view(uri_string_.data()+userinfo_.first,(port_.second-userinfo_.first)); }

std::string path() const
Expand All @@ -353,11 +358,6 @@ namespace jsoncons {
return string_view(uri_string_.data()+fragment_.first,(fragment_.second-fragment_.first));
}

std::string authority() const
{
return decode_part(encoded_authority());
}

uri resolve(const uri& base) const
{
// This implementation uses the psuedo-code given in
Expand Down

0 comments on commit 11f52df

Please sign in to comment.