[svn-commits] rizzo: trunk r45325 - /trunk/main/manager.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Oct 17 10:19:31 MST 2006


Author: rizzo
Date: Tue Oct 17 12:19:31 2006
New Revision: 45325

URL: http://svn.digium.com/view/asterisk?rev=45325&view=rev
Log:
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.


Modified:
    trunk/main/manager.c

Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?rev=45325&r1=45324&r2=45325&view=diff
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Tue Oct 17 12:19:31 2006
@@ -240,9 +240,19 @@
 	return ret;
 }
 
-static void xml_copy_escape(char **dst, size_t *maxlen, const char *src, int lower)
-{
-	while (*src && (*maxlen > 6)) {
+/*
+ * 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)
+{
+	for ( ; *src && *maxlen > 6; src++) {
+		if ( (mode & 2) && !isalnum(*src)) {
+			*(*dst)++ = '_';
+			(*maxlen)--;
+			continue;
+		}
 		switch (*src) {
 		case '<':
 			strcpy(*dst, "&lt;");
@@ -269,11 +279,11 @@
 			(*dst) += 5;
 			*maxlen -= 5;
 			break;		
+
 		default:
-			*(*dst)++ = lower ? tolower(*src) : *src;
+			*(*dst)++ = mode ? tolower(*src) : *src;
 			(*maxlen)--;
 		}
-		src++;
 	}
 }
 



More information about the svn-commits mailing list