26 #include "rcl/error_handling.h"
27 #include "rcutils/isalnum_no_locale.h"
31 const char * topic_name,
32 int * validation_result,
33 size_t * invalid_index)
37 topic_name, strlen(topic_name), validation_result, invalid_index);
42 const char * topic_name,
43 size_t topic_name_length,
44 int * validation_result,
45 size_t * invalid_index)
50 if (topic_name_length == 0) {
58 if (isdigit(topic_name[0]) != 0) {
68 if (topic_name[topic_name_length - 1] ==
'/') {
72 *invalid_index = topic_name_length - 1;
77 bool in_open_curly_brace =
false;
78 size_t opening_curly_brace_index = 0;
79 for (
size_t i = 0; i < topic_name_length; ++i) {
80 if (rcutils_isalnum_no_locale(topic_name[i])) {
84 isdigit(topic_name[i]) != 0 &&
85 in_open_curly_brace &&
87 (i - 1 == opening_curly_brace_index))
97 }
else if (topic_name[i] ==
'_') {
100 }
else if (topic_name[i] ==
'/') {
102 if (in_open_curly_brace) {
111 }
else if (topic_name[i] ==
'~') {
122 }
else if (topic_name[i] ==
'{') {
123 opening_curly_brace_index = i;
127 if (in_open_curly_brace) {
134 in_open_curly_brace =
true;
137 }
else if (topic_name[i] ==
'}') {
139 if (!in_open_curly_brace) {
146 in_open_curly_brace =
false;
151 if (in_open_curly_brace) {
163 if (in_open_curly_brace) {
167 *invalid_index = opening_curly_brace_index;
172 for (
size_t i = 0; i < topic_name_length; ++i) {
173 if (i == topic_name_length - 1) {
178 if (topic_name[i] ==
'/') {
179 if (isdigit(topic_name[i + 1]) != 0) {
183 *invalid_index = i + 1;
187 }
else if (i == 1 && topic_name[0] ==
'~') {
205 switch (validation_result) {
209 return "topic name must not be empty string";
211 return "topic name must not end with a forward slash";
214 "topic name must not contain characters other than alphanumerics, '_', '~', '{', or '}'";
216 return "topic name token must not start with a number";
218 return "topic name must not have unmatched (unbalanced) curly braces '{}'";
220 return "topic name must not have tilde '~' unless it is the first character";
222 return "topic name must not have a tilde '~' that is not followed by a forward slash '/'";
224 return "substitution name must not contain characters other than alphanumerics or '_'";
226 return "substitution name must not start with a number";
228 return "unknown result code for rcl topic name validation";
#define RCL_RET_OK
Success return code.
#define RCL_RET_INVALID_ARGUMENT
Invalid argument return code.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
#define RCL_TOPIC_NAME_INVALID_ENDS_WITH_FORWARD_SLASH
The topic name is invalid because it ends with a forward slash.
#define RCL_TOPIC_NAME_INVALID_MISPLACED_TILDE
The topic name is invalid because it has a misplaced tilde in it.
#define RCL_TOPIC_NAME_INVALID_NAME_TOKEN_STARTS_WITH_NUMBER
The topic name is invalid because one of the tokens starts with a number.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_validate_topic_name(const char *topic_name, int *validation_result, size_t *invalid_index)
Validate a given topic name.
#define RCL_TOPIC_NAME_INVALID_CONTAINS_UNALLOWED_CHARACTERS
The topic name is invalid because it has characters that are not allowed.
#define RCL_TOPIC_NAME_INVALID_IS_EMPTY_STRING
The topic name is invalid because it is an empty string.
#define RCL_TOPIC_NAME_INVALID_TILDE_NOT_FOLLOWED_BY_FORWARD_SLASH
The topic name is invalid because a tilde is not directly followed by a forward slash.
#define RCL_TOPIC_NAME_INVALID_SUBSTITUTION_CONTAINS_UNALLOWED_CHARACTERS
The topic name is invalid because one of the substitutions has characters that are not allowed.
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)
Validate a given topic name.
#define RCL_TOPIC_NAME_VALID
The topic name is valid.
#define RCL_TOPIC_NAME_INVALID_UNMATCHED_CURLY_BRACE
The topic name is invalid because it has an unmatched curly brace.
RCL_PUBLIC RCL_WARN_UNUSED const char * rcl_topic_name_validation_result_string(int validation_result)
Return a validation result description, or NULL if unknown or RCL_TOPIC_NAME_VALID.
#define RCL_TOPIC_NAME_INVALID_SUBSTITUTION_STARTS_WITH_NUMBER
The topic name is invalid because one of the substitutions starts with a number.