diff --git a/docs/api.rst b/docs/api.rst index 1fea537d1..15eb15c5e 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -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 diff --git a/include/zenoh-pico/api/olv_macros.h b/include/zenoh-pico/api/olv_macros.h index 9f535b304..c4f7a9cc7 100644 --- a/include/zenoh-pico/api/olv_macros.h +++ b/include/zenoh-pico/api/olv_macros.h @@ -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); } \ diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 97f50b63e..b02655ac9 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -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``. diff --git a/src/api/api.c b/src/api/api.c index 3c4bf37fa..34f142d4f 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -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); }