Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add z_keyexpr_canonize_null_terminated #623

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ Primitives
.. autocfunction:: primitives.h::z_keyexpr_as_view_string
.. autocfunction:: primitives.h::z_keyexpr_is_canon
.. autocfunction:: primitives.h::z_keyexpr_canonize
.. autocfunction:: primitives.h::z_keyexpr_canonize_null_terminated
.. autocfunction:: primitives.h::z_keyexpr_includes
.. autocfunction:: primitives.h::z_keyexpr_intersects
.. autocfunction:: primitives.h::z_keyexpr_equals
Expand Down
13 changes: 13 additions & 0 deletions include/zenoh-pico/api/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,19 @@ int8_t z_keyexpr_is_canon(const char *start, size_t len);
*/
int8_t z_keyexpr_canonize(char *start, size_t *len);

/**
* Canonizes of a given keyexpr in string representation.
* The canonization is performed over the passed string, possibly shortening it by setting null at the end.
*
* Parameters:
* start: Pointer to the keyexpr in its string representation as a null terminated string.
*
* Return:
* ``0`` if canonization successful, or a ``negative value`` otherwise.
* Error codes are defined in :c:enum:`zp_keyexpr_canon_status_t`.
*/
int8_t z_keyexpr_canonize_null_terminated(char *start);

/**
* Checks if a given keyexpr contains another keyexpr in its set.
*
Expand Down
9 changes: 9 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ int8_t z_keyexpr_is_canon(const char *start, size_t len) { return _z_keyexpr_is_

int8_t z_keyexpr_canonize(char *start, size_t *len) { return _z_keyexpr_canonize(start, len); }

int8_t z_keyexpr_canonize_null_terminated(char *start) {
size_t len = (start != NULL) ? strlen(start) : 0;
int8_t res = _z_keyexpr_canonize(start, &len);
if (res == _Z_RES_OK) {
start[len] = '\0';
}
return res;
}

void z_view_keyexpr_from_str_unchecked(z_view_keyexpr_t *keyexpr, const char *name) { keyexpr->_val = _z_rname(name); }

z_result_t z_view_keyexpr_from_substr(z_view_keyexpr_t *keyexpr, const char *name, size_t len) {
Expand Down
Loading