Skip to content

Commit

Permalink
Merge pull request #623 from ZettaScaleLabs/add_z_keyexpr_canonize_nu…
Browse files Browse the repository at this point in the history
…ll_terminated

Add z_keyexpr_canonize_null_terminated
  • Loading branch information
milyin authored Sep 5, 2024
2 parents 8af6e78 + e7b626d commit 10ddde2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,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 @@ -228,6 +228,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 @@ -70,6 +70,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

0 comments on commit 10ddde2

Please sign in to comment.