The class that supports URI Template (RFC 6570, Level 3).
More...
#include "nn/nlib/UriTemplate.h"
|
errno_t | SetTemplate (const char *str) noexcept |
| Sets a template. More...
|
|
errno_t | SetParameter (const char *param, const char *value) noexcept |
| Sets parameters and their values. More...
|
|
void | ResetParameter () noexcept |
| Clears all settings for parameters and their values.
|
|
errno_t | Resolve (size_t *written, char *str, size_t n) const noexcept |
| Takes the string with assigned values in the template and writes it to str. More...
|
|
template<size_t N> |
errno_t | Resolve (size_t *written, char(&str)[N]) const noexcept |
| Calls Resolve(written, str, N) .
|
|
The class that supports URI Template (RFC 6570, Level 3).
- Description
- A URI template refers to text that consists of a URI string, as defined in RFC 6570, and variables each enclosed in braces ( { } ). Creating the actual URI is a simple task of instantiating the variables.
- The
UriTemplate
class supports RFC 6570 Level 1, Level 2, and Level 3.
- Sample usage is shown below.
UriTemplate tmpl;
errno_t e = templ.SetTemplate(
"http://www.example.com/foo{?query,number}");
e = templ.SetParameter("query", "mycelium");
e = templ.SetParameter("number", "100");
char str[256];
e = templ.Resolve(str);
- For more information about URI Template, see the RFC 6570 documentation.
- See also
- https://tools.ietf.org/html/rfc6570 (RFC6570)
- Examples:
- misc/uri/uri.cpp.
Definition at line 13 of file UriTemplate.h.
§ Resolve()
nn::nlib::UriTemplate::Resolve |
( |
size_t * |
written, |
|
|
char * |
str, |
|
|
size_t |
n |
|
) |
| const |
|
noexcept |
Takes the string with assigned values in the template and writes it to str.
- Parameters
-
[out] | written | The number of written characters (not including the null character). |
[out] | str | The buffer to which the string is stored. |
[in] | n | The size of the buffer. |
- Returns
- Returns
0
on success.
§ SetParameter()
nn::nlib::UriTemplate::SetParameter |
( |
const char * |
param, |
|
|
const char * |
value |
|
) |
| |
|
noexcept |
Sets parameters and their values.
- Parameters
-
[in] | param | A variable name. |
[in] | value | A value. |
- Return values
-
0 | No error occurred. |
EINVAL | param is NULL or an empty string. |
- Description
- An empty string entered for the value results in different behavior than
NULL
. If NULL
, the value is undefined.
§ SetTemplate()
nn::nlib::UriTemplate::SetTemplate |
( |
const char * |
str | ) |
|
|
noexcept |
Sets a template.
- Parameters
-
[in] | str | The template string. |
- Return values
-
0 | No error occurred. |
EINVAL | Indicates that str is NULL . |
EILSEQ | A variable list inside braces ( { } ) is invalid. |
EIO | The template string is too long. |
ENOMEM | Indicates that internal memory allocation failed. |
- Description
- Sets a template. Characters that require percent-encoding are percent-encoded as appropriate.
The documentation for this class was generated from the following files: