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 (OutputStream *os) const noexcept |
| Takes the string with assigned values in the template and writes it to os. More...
|
|
bool | Resolve (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> |
bool | Resolve (char(&str)[N]) const noexcept |
|
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 (https://tools.ietf.org/html/rfc6570), 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}");
if (e != 0) { ERROR; }
e = templ.SetParameter("query", "mycelium");
if (e != 0) { ERROR; }
e = templ.SetParameter("number", "100");
if (e != 0) { ERROR; }
char str[256];
e = templ.Resolve(str);
if (e != 0) { ERROR; }
- For more information about URI Template, see the RFC 6570 documentation.
- Examples:
- misc/uri/uri.cpp.
Definition at line 15 of file UriTemplate.h.
Takes the string with assigned values in the template and writes it to os.
- Parameters
-
- Return values
-
0 | No error occurred. |
EIO | An error occurred writing to the stream. |
nn::nlib::UriTemplate::Resolve |
( |
char * |
str, |
|
|
size_t |
n |
|
) |
| const |
|
noexcept |
Takes the string with assigned values in the template and writes it to str.
- Parameters
-
[out] | str | The buffer to which the string is stored. |
[in] | n | The size of the buffer. |
- Returns
- Returns
true
on success.
template<size_t N>
nn::nlib::UriTemplate::Resolve |
( |
char(&) |
str[N] | ) |
const |
|
inlinenoexcept |
- Template Parameters
-
- Parameters
-
[out] | str | The buffer array to which the string is stored. |
- Returns
- Returns
true
on success.
Definition at line 29 of file UriTemplate.h.
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.
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: