[Marble-commits] KDE/kdeedu/marble/src/lib/geodata/parser

Thibaut Gridel tgridel at free.fr
Wed Sep 9 23:15:50 CEST 2009


SVN commit 1021710 by tgridel:

GeoParser: do not skip the first tag parsing if needed

this simplifies recursion logic as well, ParseDocument
- expects a valid startElement,
- possibly recognises, parses and stacks it
- then iterates for next startElement to recurse, or endElement to pop

 M  +40 -44    GeoParser.cpp  


--- trunk/KDE/kdeedu/marble/src/lib/geodata/parser/GeoParser.cpp #1021709:1021710
@@ -132,61 +132,57 @@
         return;
     }
 
-    while ( !atEnd() ) {
-        readNext();
-        GeoTagHandler::QualifiedName qName( name().toString(),
-                                            namespaceUri().toString() );
+    bool processChildren = true;
+    GeoTagHandler::QualifiedName qName( name().toString(),
+                                        namespaceUri().toString() );
 
-        if( tokenType() == QXmlStreamReader::Invalid ) 
-            raiseWarning( QString( "%1: %2" ).arg( error() ).arg( errorString() ) );
+    if( tokenType() == QXmlStreamReader::Invalid )
+        raiseWarning( QString( "%1: %2" ).arg( error() ).arg( errorString() ) );
 
-        if ( isEndElement() ) {
-            if ( !isValidRootElement() )
-                m_nodeStack.pop();
+    GeoStackItem stackItem( qName, 0 );
 
+    if ( const GeoTagHandler* handler = GeoTagHandler::recognizes( qName )) {
+        stackItem.assignNode( handler->parse( *this ));
+        processChildren = !isEndElement();
+    }
+    // Only add GeoStackItem to the parent chain, if the tag handler
+    // for the current element possibly contains non-textual children.
+    // Consider following DGML snippet "<name>Test</name>" - the
+    // DGMLNameTagHandler assumes that <name> only contains textual
+    // children, and reads the joined value of all children using
+    // readElementText(). This implicates that tags like <name>
+    // don't contain any children that would need to be processed using
+    // this parseDocument() function.
+    if ( processChildren ) {
+        m_nodeStack.push( stackItem );
 #if DUMP_PARENT_STACK > 0
-            dumpParentStack( name().toString(), m_nodeStack.size(), true );
+        dumpParentStack( name().toString(), m_nodeStack.size(), false );
 #endif
-            break;
-        }
-
-        if ( isStartElement() ) {
-            bool processChildren = true;
-            GeoStackItem stackItem( qName, 0 );
-
-            if ( const GeoTagHandler* handler = GeoTagHandler::recognizes( qName )) {
-                stackItem.assignNode( handler->parse( *this ));
-                processChildren = !isEndElement();
-            }
-
-            // Only add GeoStackItem to the parent chain, if the tag handler
-            // for the current element possibly contains non-textual children.
-            // Consider following DGML snippet "<name>Test</name>" - the
-            // DGMLNameTagHandler assumes that <name> only contains textual
-            // children, and reads the joined value of all children using
-            // readElementText(). This implicates that tags like <name>
-            // don't contain any children that would need to be processed using
-            // this parseDocument() function.
-            if ( processChildren ) {
-                m_nodeStack.push( stackItem );
-
+    }
 #if DUMP_PARENT_STACK > 0
-                dumpParentStack( name().toString(), m_nodeStack.size(), false );
+    else {
+        // This is only used for debugging purposes.
+        m_nodeStack.push( stackItem );
+        dumpParentStack( name().toString() + "-discarded", m_nodeStack.size(), false );
+
+        m_nodeStack.pop();
+        dumpParentStack( name().toString() + "-discarded", m_nodeStack.size(), true );
+    }
 #endif
 
-                parseDocument();
-            }
+    while ( !atEnd() ) {
+        readNext();
+        if ( isEndElement() ) {
+            m_nodeStack.pop();
 #if DUMP_PARENT_STACK > 0
-            else {
-                // This is only used for debugging purposes.
-                m_nodeStack.push( stackItem );
-                dumpParentStack( name().toString(), m_nodeStack.size(), false );
-
-                m_nodeStack.pop();
-                dumpParentStack( name().toString(), m_nodeStack.size(), true );
-            }
+            dumpParentStack( name().toString(), m_nodeStack.size(), true );
 #endif
+            break;
         }
+
+        if ( isStartElement() ) {
+            parseDocument();
+        }
     }
 }
 


More information about the Marble-commits mailing list