mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 11:58:52 +00:00
Geolocation: Base Asterisk Prereqs
* Added ast_variable_list_from_quoted_string() Parse a quoted string into an ast_variable list. * Added ast_str_substitute_variables_full2() Perform variable/function/expression substitution on an ast_str. * Added ast_strsep_quoted() Like ast_strsep except you can specify a specific quote character. Also added unit test. * Added ast_xml_find_child_element() Find a direct child element by name. * Added ast_xml_doc_dump_memory() Dump the specified document to a buffer * ast_datastore_free() now checks for a NULL datastore before attempting to destroy it. Change-Id: I5dcefed2f5f93a109e8b489e18d80d42e45244ec
This commit is contained in:
61
main/utils.c
61
main/utils.c
@@ -1859,6 +1859,67 @@ char *ast_strsep(char **iss, const char sep, uint32_t flags)
|
||||
return st;
|
||||
}
|
||||
|
||||
char *ast_strsep_quoted(char **iss, const char sep, const char quote, uint32_t flags)
|
||||
{
|
||||
char *st = *iss;
|
||||
char *is;
|
||||
int inquote = 0;
|
||||
int found = 0;
|
||||
char stack[8];
|
||||
const char qstr[] = { quote };
|
||||
|
||||
if (ast_strlen_zero(st)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(stack, 0, sizeof(stack));
|
||||
|
||||
for(is = st; *is; is++) {
|
||||
if (*is == '\\') {
|
||||
if (*++is != '\0') {
|
||||
is++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (*is == quote) {
|
||||
if (*is == stack[inquote]) {
|
||||
stack[inquote--] = '\0';
|
||||
} else {
|
||||
if (++inquote >= sizeof(stack)) {
|
||||
return NULL;
|
||||
}
|
||||
stack[inquote] = *is;
|
||||
}
|
||||
}
|
||||
|
||||
if (*is == sep && !inquote) {
|
||||
*is = '\0';
|
||||
found = 1;
|
||||
*iss = is + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
*iss = NULL;
|
||||
}
|
||||
|
||||
if (flags & AST_STRSEP_STRIP) {
|
||||
st = ast_strip_quoted(st, qstr, qstr);
|
||||
}
|
||||
|
||||
if (flags & AST_STRSEP_TRIM) {
|
||||
st = ast_strip(st);
|
||||
}
|
||||
|
||||
if (flags & AST_STRSEP_UNESCAPE) {
|
||||
ast_unescape_quoted(st);
|
||||
}
|
||||
|
||||
return st;
|
||||
}
|
||||
|
||||
char *ast_unescape_semicolon(char *s)
|
||||
{
|
||||
char *e;
|
||||
|
Reference in New Issue
Block a user