[asterisk-commits] eliel: branch group/appdocsxml r139743 - /team/group/appdocsxml/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Aug 25 07:26:14 CDT 2008


Author: eliel
Date: Mon Aug 25 07:26:14 2008
New Revision: 139743

URL: http://svn.digium.com/view/asterisk?view=rev&rev=139743
Log:
- Implement emphasis, literal and replaceable parsing inside para elements.
- Now get the Node content in ast_xml_get_text().
- Don't remove spaces while cleaning up the text elements, just tabs (be sure while formatting the
  xml, that spaces wont be removed!).


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

Modified: team/group/appdocsxml/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/pbx.c?view=diff&rev=139743&r1=139742&r2=139743
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Mon Aug 25 07:26:14 2008
@@ -2967,19 +2967,19 @@
 static char *xmldoc_string_cleanup(const char *text)
 {
 	int retlen=0, c;
-	char *rettmp, *rettext, *tmp, *trim;
+	char *rettmp, *rettext, *tmp;
 
 	/* Alloc a buffer of at least the same size as 'text' */
 	if (!text || !(rettmp = calloc(1, strlen(text) + 1))) {
 		return NULL;
 	}
 
-	tmp = ast_skip_blanks(text);
+	tmp = (char *)text;
 	while (*tmp) {
 		if (*tmp == '\n' || *tmp == '\r') {
 			tmp++;
 			c = 0;
-			while (*tmp == ' ' || *tmp == '\t' || *tmp == '\r' || *tmp == '\n') {
+			while (*tmp == '\t' || *tmp == '\r' || *tmp == '\n') {
 				tmp++, c++;
 			}
 			if (c) {
@@ -2992,9 +2992,7 @@
 		tmp++;
 	}
 
-	trim = ast_trim_blanks(rettmp);
-	
-	rettext = ast_strdup(trim);
+	rettext = ast_strdup(rettmp);
 	ast_free(rettmp);
 
 	return rettext;
@@ -3352,7 +3350,9 @@
 static int xmldoc_parse_para(ast_xml_node *node, const char *tabs, const char *posttabs, int *len, char **buffer)
 {
 	ast_xml_text *tmptext;
+	ast_xml_node *tmp;
 	char *cleantext;
+	char *sepinit, *sepend;
 	int ret = 0;
 
 	if (!node || !node->AST_XML_CHILD) {
@@ -3363,20 +3363,42 @@
 		return ret;
 	}
 
+        *buffer = ast_realloc(*buffer, *len + xmldoc_postbrlen(tabs) + 1);
+        *len += sprintf(*buffer + *len, "%s", tabs);
+
 	ret = 1;
-	/* Get the text inside the <para> element and append it to buffer. */
-	tmptext = ast_xml_get_text(node);
-	if (tmptext) {
-		/* Strip \n etc. */
-		cleantext = xmldoc_string_cleanup(tmptext);
-		ast_xml_free_text(tmptext);
-		if (cleantext) {
-			*buffer = ast_realloc(*buffer, *len + strlen(tabs) + strlen(cleantext) + strlen(posttabs) + 1);
-			*len += sprintf(*buffer + *len, "%s%s%s", tabs, cleantext, posttabs);
-			ast_free(cleantext);
-			ret = 2;
-		}
-	}
+
+	tmp = node->AST_XML_CHILD;
+	while (tmp) {
+		if (!strcasecmp((char *)tmp->AST_XML_NAME, "literal")) {
+			sepinit = sepend = "'";
+		} else if (!strcasecmp((char *)tmp->AST_XML_NAME, "replaceable")) {
+			sepinit = "<";
+			sepend = ">";
+		} else if (!strcasecmp((char *)tmp->AST_XML_NAME, "emphasis")) {
+			sepinit = sepend = "*";
+		} else {
+			sepinit = sepend = "";
+		}
+
+		/* Get the text inside the <para> element and append it to buffer. */
+		tmptext = ast_xml_get_text(tmp);
+		if (tmptext) {
+			/* Strip \n etc. */
+			cleantext = xmldoc_string_cleanup(tmptext);
+			ast_xml_free_text(tmptext);
+			if (cleantext) {
+				*buffer = ast_realloc(*buffer, *len + strlen(cleantext) + strlen(sepinit) + strlen(sepend) + 3);
+				*len += sprintf(*buffer + *len, "%s%s%s", sepinit, cleantext, sepend);
+				ast_free(cleantext);
+				ret = 2;
+			}
+		}
+		tmp = tmp->AST_XML_NEXT;
+	}
+
+	*buffer = ast_realloc(*buffer, *len + xmldoc_postbrlen(posttabs) + 1);
+        *len += sprintf(*buffer + *len, "%s", posttabs);
 
 	return ret;
 }

Modified: team/group/appdocsxml/main/xml.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/xml.c?view=diff&rev=139743&r1=139742&r2=139743
==============================================================================
--- team/group/appdocsxml/main/xml.c (original)
+++ team/group/appdocsxml/main/xml.c Mon Aug 25 07:26:14 2008
@@ -161,11 +161,11 @@
 
 char *ast_xml_get_text(ast_xml_node *node)
 {
-	if (!node || !node->children) {
+	if (!node) {
 		return NULL;
 	}
 
-	return (char *)xmlNodeListGetString(node->doc, node->children, 0);
+	return (char *)xmlNodeGetContent(node);
 }
 
 #endif /* defined(HAVE_LIBXML2) && !defined(AST_XML_IMPLEMENTATION) */




More information about the asterisk-commits mailing list