[asterisk-commits] eliel: branch group/appdocsxml r151014 - /team/group/appdocsxml/main/pbx.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Oct 18 11:19:28 CDT 2008


Author: eliel
Date: Sat Oct 18 11:19:27 2008
New Revision: 151014

URL: http://svn.digium.com/view/asterisk?view=rev&rev=151014
Log:
Fix a formatting issue while printing the content of a <value> node inside a <variable>.
Also allow to remove last spaces only when needed (on nodes without other content that text).

Modified:
    team/group/appdocsxml/main/pbx.c

Modified: team/group/appdocsxml/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/pbx.c?view=diff&rev=151014&r1=151013&r2=151014
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Sat Oct 18 11:19:27 2008
@@ -3411,16 +3411,18 @@
  *  \brief Cleanup spaces and tabs after a \n
  *  \param text String to be cleaned up.
  *  \param output buffer (not already allocated).
+ *  \param lastspaces Remove last spaces in the string.
  */
-static void xmldoc_string_cleanup(const char *text, struct ast_str **output)
+static void xmldoc_string_cleanup(const char *text, struct ast_str **output, int lastspaces)
 {
 	char *tmp;
-
-	if (!text) {
+	
+	*output = ast_str_create(1);
+	if (!(*output)) {
+		ast_log(LOG_ERROR, "Problem allocating output buffer\n");
 		return;
 	}
 
-	*output = ast_str_create(1);
 	tmp = (char *)text;
 	while (*tmp) {
 		if (*tmp == '\n' || *tmp == '\r') {
@@ -3428,12 +3430,19 @@
 			while (*tmp == '\t' || *tmp == '\r' || *tmp == '\n') {
 				tmp++;
 			}
-			ast_str_append(output, 0, "%c", ' ');
+			ast_str_append(output, 0, " ");
 			continue;
 		} else {
 			ast_str_append(output, 0, "%c", *tmp);
 		}
 		tmp++;
+	}
+	/* remove last spaces (we dont want always to remove the trailing spaces). */
+	if (lastspaces) {
+		while ((*output)->used && (*output)->str[(*output)->used - 1] == ' ') {
+			(*output)->str[(*output)->used - 1] = '\0';
+			(*output)->used--;
+		}
 	}
 }
 
@@ -3852,7 +3861,7 @@
 		tmptext = ast_xml_get_text(tmp);
 		if (tmptext) {
 			/* Strip \n etc. */
-			xmldoc_string_cleanup(tmptext, &tmpstr);
+			xmldoc_string_cleanup(tmptext, &tmpstr, 0);
 			ast_xml_free_text(tmptext);
 			if (tmpstr) {
 				if (strcasecmp((char *)tmp->AST_XML_NAME, "text")) {
@@ -4015,7 +4024,7 @@
 			/* Check inside this node for any explanation about its meaning. */
 			if (tmptext) {
 				/* Cleanup text. */
-				xmldoc_string_cleanup(tmptext, &cleanstr);
+				xmldoc_string_cleanup(tmptext, &cleanstr, 1);
 				ast_xml_free_text(tmptext);
 				if (cleanstr && cleanstr->used > 0) {
 					ast_str_append(buffer, 0, ":%s", cleanstr->str);
@@ -4475,7 +4484,7 @@
 	if (raw_output) {
 		notcleanret = ast_xml_get_text(node);
 		tmpstr = notcleanret;
-		xmldoc_string_cleanup(ast_skip_blanks(notcleanret), &ret);
+		xmldoc_string_cleanup(ast_skip_blanks(notcleanret), &ret, 0);
 		ast_xml_free_text(tmpstr);
 	} else {
 		tmp = node->AST_XML_CHILD;




More information about the asterisk-commits mailing list