Skip to content

Commit

Permalink
Merge pull request #622 from ZettaScaleLabs/add_z_view_string_from_su…
Browse files Browse the repository at this point in the history
…bstr

Add z_view_string_from_substr and fix z_view_string_empty
  • Loading branch information
milyin authored Sep 4, 2024
2 parents 1e8f3dc + e09e57d commit 8b1e207
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ Primitives
~~~~~~~~~~

.. autocfunction:: primitives.h::z_view_string_from_str
.. autocfunction:: primitives.h::z_view_string_from_substr
.. autocfunction:: primitives.h::z_view_keyexpr_from_str
.. autocfunction:: primitives.h::z_view_keyexpr_from_str_unchecked
.. autocfunction:: primitives.h::z_view_keyexpr_from_str_autocanonize
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/api/olv_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
_Bool z_view_##name##_is_empty(const z_view_##name##_t *obj); \
const z_loaned_##name##_t *z_view_##name##_loan(const z_view_##name##_t *name); \
z_loaned_##name##_t *z_view_##name##_loan_mut(z_view_##name##_t *name); \
void _z_view_##name##_empty(z_view_##name##_t *name);
void z_view_##name##_empty(z_view_##name##_t *name);

#define _Z_OWNED_FUNCTIONS_IMPL_MOVE_TAKE(name) \
z_moved_##name##_t *z_##name##_move(z_owned_##name##_t *obj) { return (z_moved_##name##_t *)(obj); } \
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 @@ -44,6 +44,19 @@ extern "C" {
*/
int8_t z_view_string_from_str(z_view_string_t *str, const char *value);

/**
* Builds a :c:type:`z_view_string_t` by wrapping a ``const char *`` substring.
*
* Parameters:
* str: Pointer to an uninitialized :c:type:`z_view_string_t`.
* value: Pointer to a null terminated string.
* len: Size of the string.
*
* Return:
* ``0`` if creation successful, ``negative value`` otherwise.
*/
int8_t z_view_string_from_substr(z_view_string_t *str, const char *value, size_t len);

/**
* Builds a :c:type:`z_keyexpr_t` from a null-terminated string.
* It is a loaned key expression that aliases ``name``.
Expand Down
5 changes: 5 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ int8_t z_view_string_from_str(z_view_string_t *str, const char *value) {
return _Z_RES_OK;
}

int8_t z_view_string_from_substr(z_view_string_t *str, const char *value, size_t len) {
str->_val = _z_string_alias_substr((char *)value, len);
return _Z_RES_OK;
}

const z_loaned_string_t *z_string_array_get(const z_loaned_string_array_t *a, size_t k) {
return _z_string_svec_get(a, k);
}
Expand Down

0 comments on commit 8b1e207

Please sign in to comment.