Add rcl_validate_topic_name_with_size (#220)
This commit is contained in:
parent
beee7c22ee
commit
7008a7d6e7
2 changed files with 29 additions and 1 deletions
|
@ -94,6 +94,22 @@ rcl_validate_topic_name(
|
|||
int * validation_result,
|
||||
size_t * invalid_index);
|
||||
|
||||
/// Validate a given topic name.
|
||||
/**
|
||||
* This is an overload with an extra parameter for the length of topic_name.
|
||||
* \param[in] topic_name_length The number of characters in topic_name.
|
||||
*
|
||||
* \sa rcl_validate_topic_name(const char *, int *, size_t *)
|
||||
*/
|
||||
RCL_PUBLIC
|
||||
RCL_WARN_UNUSED
|
||||
rcl_ret_t
|
||||
rcl_validate_topic_name_with_size(
|
||||
const char * topic_name,
|
||||
size_t topic_name_length,
|
||||
int * validation_result,
|
||||
size_t * invalid_index);
|
||||
|
||||
/// Return a validation result description, or NULL if unknown or RCL_TOPIC_NAME_VALID.
|
||||
RCL_PUBLIC
|
||||
RCL_WARN_UNUSED
|
||||
|
|
|
@ -31,12 +31,24 @@ rcl_validate_topic_name(
|
|||
const char * topic_name,
|
||||
int * validation_result,
|
||||
size_t * invalid_index)
|
||||
{
|
||||
rcl_allocator_t allocator = rcutils_get_default_allocator();
|
||||
RCL_CHECK_ARGUMENT_FOR_NULL(topic_name, RCL_RET_INVALID_ARGUMENT, allocator)
|
||||
return rcl_validate_topic_name_with_size(
|
||||
topic_name, strlen(topic_name), validation_result, invalid_index);
|
||||
}
|
||||
|
||||
rcl_ret_t
|
||||
rcl_validate_topic_name_with_size(
|
||||
const char * topic_name,
|
||||
size_t topic_name_length,
|
||||
int * validation_result,
|
||||
size_t * invalid_index)
|
||||
{
|
||||
rcl_allocator_t allocator = rcutils_get_default_allocator();
|
||||
RCL_CHECK_ARGUMENT_FOR_NULL(topic_name, RCL_RET_INVALID_ARGUMENT, allocator)
|
||||
RCL_CHECK_ARGUMENT_FOR_NULL(validation_result, RCL_RET_INVALID_ARGUMENT, allocator)
|
||||
|
||||
size_t topic_name_length = strlen(topic_name);
|
||||
if (topic_name_length == 0) {
|
||||
*validation_result = RCL_TOPIC_NAME_INVALID_IS_EMPTY_STRING;
|
||||
if (invalid_index) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue