[sword-svn] r1922 - in trunk: src/utilfuns tests

scribe at crosswire.org scribe at crosswire.org
Tue May 30 21:34:51 MST 2006


Author: scribe
Date: 2006-05-30 21:33:52 -0700 (Tue, 30 May 2006)
New Revision: 1922

Modified:
   trunk/src/utilfuns/utilxml.cpp
   trunk/tests/xmltest.cpp
Log:
Added beginnings of support for XML attributes delineated with single '


Modified: trunk/src/utilfuns/utilxml.cpp
===================================================================
--- trunk/src/utilfuns/utilxml.cpp	2006-05-22 11:25:36 UTC (rev 1921)
+++ trunk/src/utilfuns/utilxml.cpp	2006-05-31 04:33:52 UTC (rev 1922)
@@ -49,10 +49,10 @@
 					strncpy(name, buf+start, i-start);
 					name[i-start] = 0;
 				}
-				for (; ((buf[i]) && (strchr(" =\"", buf[i]))); i++);
+				for (; ((buf[i]) && (strchr(" =\"\'", buf[i]))); i++);
 				if (buf[i]) {	// we have attribute value
 					start = i;
-					for (; ((buf[i]) && (buf[i] != '\"')); i++);
+					for (; ((buf[i]) && (buf[i] != '\"') && (buf[i] != '\'')); i++);
 					if (i-start) {
 						if (value)
 							delete [] value;
@@ -212,9 +212,9 @@
 		//tag.appendFormatted(" %s=\"%s\"", it->first.c_str(), it->second.c_str());
 		tag.append(' ');
 		tag.append(it->first.c_str());
-		tag.append("=\"");
+		tag.append((strchr(it->second.c_str(), '\"')) ? "=\'" : "=\"");
 		tag.append(it->second.c_str());
-		tag.append('"');
+		tag.append((strchr(it->second.c_str(), '\"'))? '\'' : '\"');
 	}
 
 	if (isEmpty())

Modified: trunk/tests/xmltest.cpp
===================================================================
--- trunk/tests/xmltest.cpp	2006-05-22 11:25:36 UTC (rev 1921)
+++ trunk/tests/xmltest.cpp	2006-05-31 04:33:52 UTC (rev 1922)
@@ -5,9 +5,13 @@
 using namespace std;
 
 int main(int argc, char **argv) {
-	XMLTag x((argc > 1) ? argv[1] : "<verse osisID=\"John.1.1\" type=\"test type\" yeah = \"stuff\" />");
+	const char *xml = "<verse osisID=\"John.1.1\" type=\'test type\' yeah = \"stuff\" />";
+	cout << ((argc > 1) ? argv[1]: xml) << "\n";
+	XMLTag x((argc > 1) ? argv[1] : xml);
 //	x.setAttribute("newOne", "oneValue");
 	cout << x.toString() << "\n";
+	x.setAttribute("addedAttribute", "with a \" quote");
+	cout << x.toString() << "\n";
 	cout << "Tag name: [" << x.getName() << "]\n";
 	StringList attributes = x.getAttributeNames();
 	for (StringList::iterator it = attributes.begin(); it != attributes.end(); it++) {



More information about the sword-cvs mailing list