aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-10-17 17:19:31 +0000
committerrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-10-17 17:19:31 +0000
commit7673e5c24ac11e48cb3c10d8831813bdac19a5bf (patch)
tree23846cff1d51b31a4fe494099083607c8d91d009
parentba83221f3e175909d45f31f09d4d74b49369e7bd (diff)
document xml_copy_escape() and add an extra function, namely
replace non-alphanum chars with underscore. This is useful when building field names in xml formatting. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@45325 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--main/manager.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/main/manager.c b/main/manager.c
index 532ceb87e..45cdd6e6b 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -240,9 +240,19 @@ static char *complete_show_mancmd(const char *line, const char *word, int pos, i
return ret;
}
-static void xml_copy_escape(char **dst, size_t *maxlen, const char *src, int lower)
+/*
+ * convert to xml with various conversion:
+ * mode & 1 -> lowercase;
+ * mode & 2 -> replace non-alphanumeric chars with underscore
+ */
+static void xml_copy_escape(char **dst, size_t *maxlen, const char *src, int mode)
{
- while (*src && (*maxlen > 6)) {
+ for ( ; *src && *maxlen > 6; src++) {
+ if ( (mode & 2) && !isalnum(*src)) {
+ *(*dst)++ = '_';
+ (*maxlen)--;
+ continue;
+ }
switch (*src) {
case '<':
strcpy(*dst, "&lt;");
@@ -269,11 +279,11 @@ static void xml_copy_escape(char **dst, size_t *maxlen, const char *src, int low
(*dst) += 5;
*maxlen -= 5;
break;
+
default:
- *(*dst)++ = lower ? tolower(*src) : *src;
+ *(*dst)++ = mode ? tolower(*src) : *src;
(*maxlen)--;
}
- src++;
}
}