Add rcl_validate_topic_name_with_size (#220)

This commit is contained in:
Shane Loretz 2018-03-15 16:38:57 -07:00 committed by GitHub
parent beee7c22ee
commit 7008a7d6e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View file

@ -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

View file

@ -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) {