26 #include "rcl/error_handling.h"
28 #include "rcutils/isalnum_no_locale.h"
32 const char * topic_name,
33 int * validation_result,
34 size_t * invalid_index)
38 topic_name, strlen(topic_name), validation_result, invalid_index);
43 const char * topic_name,
44 size_t topic_name_length,
45 int * validation_result,
46 size_t * invalid_index)
51 if (topic_name_length == 0) {
59 if (isdigit(topic_name[0]) != 0) {
69 if (topic_name[topic_name_length - 1] ==
'/') {
73 *invalid_index = topic_name_length - 1;
78 bool in_open_curly_brace =
false;
79 size_t opening_curly_brace_index = 0;
80 for (
size_t i = 0; i < topic_name_length; ++i) {
81 if (rcutils_isalnum_no_locale(topic_name[i])) {
85 isdigit(topic_name[i]) != 0 &&
86 in_open_curly_brace &&
88 (i - 1 == opening_curly_brace_index))
98 }
else if (topic_name[i] ==
'_') {
101 }
else if (topic_name[i] ==
'/') {
103 if (in_open_curly_brace) {
112 }
else if (topic_name[i] ==
'~') {
123 }
else if (topic_name[i] ==
'{') {
124 opening_curly_brace_index = i;
128 if (in_open_curly_brace) {
135 in_open_curly_brace =
true;
138 }
else if (topic_name[i] ==
'}') {
140 if (!in_open_curly_brace) {
147 in_open_curly_brace =
false;
152 if (in_open_curly_brace) {
164 if (in_open_curly_brace) {
168 *invalid_index = opening_curly_brace_index;
173 for (
size_t i = 0; i < topic_name_length; ++i) {
174 if (i == topic_name_length - 1) {
179 if (topic_name[i] ==
'/') {
180 if (isdigit(topic_name[i + 1]) != 0) {
184 *invalid_index = i + 1;
188 }
else if (i == 1 && topic_name[0] ==
'~') {
206 switch (validation_result) {
210 return "topic name must not be empty string";
212 return "topic name must not end with a forward slash";
215 "topic name must not contain characters other than alphanumerics, '_', '~', '{', or '}'";
217 return "topic name token must not start with a number";
219 return "topic name must not have unmatched (unbalanced) curly braces '{}'";
221 return "topic name must not have tilde '~' unless it is the first character";
223 return "topic name must not have a tilde '~' that is not followed by a forward slash '/'";
225 return "substitution name must not contain characters other than alphanumerics or '_'";
227 return "substitution name must not start with a number";
229 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.