Commit in reactos/subsys/system/explorer/utility on MAIN
xmlstorage.cpp+51-291.7 -> 1.8
xmlstorage.h+2-181.13 -> 1.14
+53-47
2 modified files
fix XML formating

reactos/subsys/system/explorer/utility
xmlstorage.cpp 1.7 -> 1.8
diff -u -r1.7 -r1.8
--- xmlstorage.cpp	6 Apr 2004 22:15:25 -0000	1.7
+++ xmlstorage.cpp	9 Apr 2004 11:51:37 -0000	1.8
@@ -75,7 +75,11 @@
 		cerr << get_error_string();
 */
 
-	_pos->append_trailing(_content.c_str(), _content.length());
+	if (_pos->_children.empty())
+		_pos->_trailing.append(_content);
+	else
+		_pos->_children.back()->_trailing.append(_content);
+
 	_content.erase();
 
 	return status;
@@ -85,23 +89,24 @@
  /// store XML version and encoding into XML reader
 void XMLCALL XMLReader::XML_XmlDeclHandler(void* userData, const XML_Char* version, const XML_Char* encoding, int standalone)
 {
-	XMLReader* pThis = (XMLReader*) userData;
+	XMLReader* pReader = (XMLReader*) userData;
 
 	if (version) {
-		pThis->_xml_version = version;
-		pThis->_encoding = encoding;
+		pReader->_xml_version = version;
+		pReader->_encoding = encoding;
 	}
 }
 
  /// notifications about XML start tag
 void XMLCALL XMLReader::XML_StartElementHandler(void* userData, const XML_Char* name, const XML_Char** atts)
 {
-	XMLReader* pThis = (XMLReader*) userData;
+	XMLReader* pReader = (XMLReader*) userData;
+	XMLPos& pos = pReader->_pos;
 
 	 // search for end of first line
-	const char* s = pThis->_content.c_str();
+	const char* s = pReader->_content.c_str();
 	const char* p = s;
-	const char* e = p + pThis->_content.length();
+	const char* e = p + pReader->_content.length();
 
 	for(; p<e; ++p)
 		if (*p == '\n') {
@@ -110,7 +115,14 @@
 		}
 
 	if (p != s)
-		pThis->_pos->append_trailing(s, p-s);
+		if (pos->_children.empty()) {	// no children in last node?
+			if (pReader->_last_tag == TAG_START)
+				pos->_content.append(s, p-s);
+			else if (pReader->_last_tag == TAG_END)
+				pos->_trailing.append(s, p-s);
+			// else TAG_NONE -> don't store white space in root node
+		} else
+			pos->_children.back()->_trailing.append(s, p-s);
 
 	std::string leading;
 
@@ -119,7 +131,7 @@
 
 	XMLNode* node = new XMLNode(String_from_XML_Char(name), leading);
 
-	pThis->_pos.add_down(node);
+	pos.add_down(node);
 
 	while(*atts) {
 		const XML_Char* attr_name = *atts++;
@@ -128,19 +140,20 @@
 		(*node)[String_from_XML_Char(attr_name)] = String_from_XML_Char(attr_value);
 	}
 
-	pThis->_in_node = true;
-	pThis->_content.erase();
+	pReader->_last_tag = TAG_START;
+	pReader->_content.erase();
 }
 
  /// notifications about XML end tag
 void XMLCALL XMLReader::XML_EndElementHandler(void* userData, const XML_Char* name)
 {
-	XMLReader* pThis = (XMLReader*) userData;
+	XMLReader* pReader = (XMLReader*) userData;
+	XMLPos& pos = pReader->_pos;
 
 	 // search for end of first line
-	const char* s = pThis->_content.c_str();
+	const char* s = pReader->_content.c_str();
 	const char* p = s;
-	const char* e = p + pThis->_content.length();
+	const char* e = p + pReader->_content.length();
 
 	for(; p<e; ++p)
 		if (*p == '\n') {
@@ -149,23 +162,29 @@
 		}
 
 	if (p != s)
-		pThis->_pos->append_content(s, p-s);
+		if (pos->_children.empty())	// no children in current node?
+			pos->_content.append(s, p-s);
+		else
+			if (pReader->_last_tag == TAG_START)
+				pos->_content.append(s, p-s);
+			else
+				pos->_children.back()->_trailing.append(s, p-s);
 
 	if (p != e)
-		pThis->_pos->_end_leading.assign(p, e-p);
+		pos->_end_leading.assign(p, e-p);
 
-	pThis->_pos.back();
+	pos.back();
 
-	pThis->_in_node = false;
-	pThis->_content.erase();
+	pReader->_last_tag = TAG_END;
+	pReader->_content.erase();
 }
 
  /// store content, white space and comments
 void XMLCALL XMLReader::XML_DefaultHandler(void* userData, const XML_Char* s, int len)
 {
-	XMLReader* pThis = (XMLReader*) userData;
+	XMLReader* pReader = (XMLReader*) userData;
 
-	pThis->_content.append(s, len);
+	pReader->_content.append(s, len);
 }
 
 
@@ -282,7 +301,9 @@
 	for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it)
 		out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\"";
 
-	if (!_children.empty() || !_content.empty()) {
+	if (_children.empty() && _content.empty())
+		out << "/>";
+	else {
 		out << '>';
 
 		if (_content.empty())
@@ -292,19 +313,20 @@
 
 		Children::const_iterator it = _children.begin();
 
-		if (it != _children.end())
+		if (it != _children.end()) {
 			for(; it!=_children.end(); ++it)
 				(*it)->smart_write_worker(out, indent+1);
 
-		if (_end_leading.empty())
-			for(int i=indent; i--; )
-				out << XML_INDENT_SPACE;
-		else
+			if (_end_leading.empty())
+				for(int i=indent; i--; )
+					out << XML_INDENT_SPACE;
+			else
+				out << _end_leading;
+		} else
 			out << _end_leading;
 
 		out << "</" << EncodeXMLString(*this) << '>';
-	} else
-		out << "/>";
+	}
 
 	if (_trailing.empty())
 		out << '\n';

reactos/subsys/system/explorer/utility
xmlstorage.h 1.13 -> 1.14
diff -u -r1.13 -r1.14
--- xmlstorage.h	6 Apr 2004 22:15:25 -0000	1.13
+++ xmlstorage.h	9 Apr 2004 11:51:37 -0000	1.14
@@ -576,22 +576,6 @@
 	}
 #endif
 
-	void append_content(const char* s, int l)
-	{
-		//if (_children.empty())
-			_content.append(s, l);
-		//else
-		//	_children.back()->_content.append(s, l);
-	}
-
-	void append_trailing(const char* s, int l)
-	{
-		if (_children.empty())
-			_content.append(s, l);
-		else
-			_children.back()->_trailing.append(s, l);
-	}
-
 	void write_worker(std::ostream& out, int indent) const;
 	void pretty_write_worker(std::ostream& out, int indent) const;
 	void smart_write_worker(std::ostream& out, int indent) const;
@@ -1227,7 +1211,7 @@
 		XML_SetElementHandler(_parser, XML_StartElementHandler, XML_EndElementHandler);
 		XML_SetDefaultHandler(_parser, XML_DefaultHandler);
 
-		_in_node = false;
+		_last_tag = TAG_NONE;
 	}
 
 	~XMLReader()
@@ -1265,7 +1249,7 @@
 	std::string _encoding;
 
 	std::string _content;
-	bool		_in_node;
+	enum {TAG_NONE, TAG_START, TAG_END} _last_tag;
 
 	static void XMLCALL XML_XmlDeclHandler(void* userData, const XML_Char* version, const XML_Char* encoding, int standalone);
 	static void XMLCALL XML_StartElementHandler(void* userData, const XML_Char* name, const XML_Char** atts);
CVSspam 0.2.8