\param sep A single character delimiter.
\param flags Controls post-processing of the result.
AST_STRSEP_TRIM trims all leading and trailing whitespace from the result.
+ If the result containes only whitespace, it'll be passed through unchanged.
AST_STRSEP_STRIP does a trim then strips the outermost quotes. You may want
to trim again after the strip. Just OR both the TRIM and STRIP flags.
AST_STRSEP_UNESCAPE unescapes '\' sequences.
struct ast_variable *ast_variable_list_append_hint(struct ast_variable **head, struct ast_variable *search_hint, struct ast_variable *newvar)
{
struct ast_variable *curr;
+ struct ast_variable *sh = search_hint;
ast_assert(head != NULL);
if (!*head) {
*head = newvar;
} else {
- if (search_hint == NULL) {
- search_hint = *head;
+ if (sh == NULL) {
+ sh = *head;
}
- for (curr = search_hint; curr->next; curr = curr->next);
+ for (curr = sh; curr->next; curr = curr->next);
curr->next = newvar;
}
}
item_value = ast_strsep_quoted(&item, nv_sep, quote, AST_STRSEP_ALL);
- if (!item_value) {
- ast_variables_destroy(new_list);
- return NULL;
- }
- new_var = ast_variable_new(item_name, item_value, "");
+ new_var = ast_variable_new(item_name, item_value ?: "", "");
if (!new_var) {
ast_variables_destroy(new_list);
return NULL;
}
if (flags & AST_STRSEP_TRIM) {
- st = ast_strip(st);
+ char *trimmed = ast_strip(st);
+ if (!ast_strlen_zero(trimmed)) {
+ st = trimmed;
+ }
}
if (flags & AST_STRSEP_UNESCAPE) {
}
if (flags & AST_STRSEP_TRIM) {
- st = ast_strip(st);
+ char *trimmed = ast_strip(st);
+ if (!ast_strlen_zero(trimmed)) {
+ st = trimmed;
+ }
}
if (flags & AST_STRSEP_UNESCAPE) {
enum ast_geoloc_format format, const char *ref_str)
{
struct ast_variable *list = NULL;
+ struct ast_variable *locinfo_list = NULL;
struct ast_xml_node *container;
struct ast_variable *var = NULL;
const char *attr;
ast_variable_list_append(&list, var);
}
- ast_variable_list_append(&list, var_list_from_node(container, ref_str));
+ locinfo_list = var_list_from_node(container, ref_str);
+ if (locinfo_list == NULL) {
+ ast_log(LOG_WARNING, "%s: There were no elements in the location info\n", ref_str);
+ SCOPE_EXIT_RTN_VALUE(list, "%s: There were no elements in the location info\n", ref_str);
+ }
+ ast_variable_list_append(&list, locinfo_list);
if (TRACE_ATLEAST(5)) {
struct ast_str *buf = NULL;
break;
}
- parse_string = "abc = 'def', ghi = 'j,kl', mno='pq=r', stu = 'vwx=\"yz\", ABC = \"DEF\"'";
+ parse_string = "000= '', 111=, 222 = , 333 = ' ', abc = 'def', ghi = 'j,kl', mno='pq=r', stu = 'vwx=\"yz\", ABC = \"DEF\"'";
list = ast_variable_list_from_quoted_string(parse_string, ",", "=", "'");
ast_test_validate(test, list != NULL);
str = ast_variable_list_join(list, "|", "^", "@", NULL);
ast_test_validate(test,
- strcmp(ast_str_buffer(str), "abc^@def@|ghi^@j,kl@|mno^@pq=r@|stu^@vwx=\"yz\", ABC = \"DEF\"@") == 0);
+ strcmp(ast_str_buffer(str), "000^@@|111^@@|222^@@|333^@ @|abc^@def@|ghi^@j,kl@|mno^@pq=r@|stu^@vwx=\"yz\", ABC = \"DEF\"@") == 0);
return AST_TEST_PASS;
}