-rw-r--r-- | libopie/xmltree.cc | 17 | ||||
-rw-r--r-- | libopie2/opiecore/xmltree.cc | 17 |
2 files changed, 20 insertions, 14 deletions
diff --git a/libopie/xmltree.cc b/libopie/xmltree.cc index 3d03cc6..408e3c6 100644 --- a/libopie/xmltree.cc +++ b/libopie/xmltree.cc @@ -44,108 +44,110 @@ XMLElement::~XMLElement() void XMLElement::appendChild( XMLElement *child ) { if ( child->m_parent ) child->m_parent->removeChild( child ); child->m_parent = this; if ( m_last ) m_last->m_next = child; child->m_prev = m_last; if ( !m_first ) m_first = child; m_last = child; } void XMLElement::insertAfter( XMLElement *newChild, XMLElement *refChild ) { assert( newChild != refChild ); if ( refChild == m_last ) { appendChild( newChild ); return; } assert( refChild ); assert( refChild->m_parent ); assert( refChild->m_parent == this ); if ( newChild->m_parent && newChild != refChild ) newChild->m_parent->removeChild( newChild ); newChild->m_parent = this; XMLElement *next = refChild->m_next; refChild->m_next = newChild; newChild->m_prev = refChild; newChild->m_next = next; if ( next ) next->m_prev = newChild; } -QString XMLElement::attribute(const QString &attr )const + +QString XMLElement::attribute( const QString &attr ) const { - if ( !m_attributes.contains( attr ) ) - return QString::null; AttributeMap::ConstIterator it = m_attributes.find( attr ); + if ( it == m_attributes.end() ) + return QString::null; return it.data(); } -void XMLElement::setAttribute(const QString &attr, const QString &value ) + +void XMLElement::setAttribute( const QString &attr, const QString &value ) { - m_attributes.remove( attr ); - m_attributes.insert( attr, value ); + m_attributes.replace( attr, value ); } + void XMLElement::insertBefore( XMLElement *newChild, XMLElement *refChild ) { assert( refChild ); assert( refChild->m_parent ); assert( refChild->m_parent == this ); assert( newChild != refChild ); if ( newChild->m_parent && newChild != refChild ) newChild->m_parent->removeChild( newChild ); newChild->m_parent = this; XMLElement *prev = refChild->m_prev; refChild->m_prev = newChild; newChild->m_prev = prev; newChild->m_next = refChild; if ( prev ) prev->m_next = newChild; if ( refChild == m_first ) m_first = newChild; } void XMLElement::removeChild( XMLElement *child ) { if ( child->m_parent != this ) return; if ( m_first == child ) m_first = child->m_next; if ( m_last == child ) m_last = child->m_prev; if ( child->m_prev ) child->m_prev->m_next = child->m_next; if ( child->m_next ) child->m_next->m_prev = child->m_prev; child->m_parent = 0; child->m_prev = 0; child->m_next = 0; } @@ -270,49 +272,50 @@ bool Handler::characters( const QString &ch ) return true; } XMLElement *XMLElement::namedItem( const QString &name ) { XMLElement *e = m_first; for (; e; e = e->nextChild() ) if ( e->tagName() == name ) return e; return 0; } XMLElement *XMLElement::clone() const { XMLElement *res = new XMLElement; res->setTagName( m_tag ); res->setValue( m_value ); res->setAttributes( m_attributes ); XMLElement *e = m_first; for (; e; e = e->m_next ) res->appendChild( e->clone() ); return res; } XMLElement *XMLElement::load( const QString &fileName ) { QFile f( fileName ); if ( !f.open( IO_ReadOnly ) ) return 0; QTextStream stream( &f ); stream.setEncoding( QTextStream::UnicodeUTF8 ); QXmlInputSource src( stream ); QXmlSimpleReader reader; Handler handler; reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false ); reader.setContentHandler( &handler ); reader.parse( src ); return handler.root();; } - +/* vim: et sw=4 + */ diff --git a/libopie2/opiecore/xmltree.cc b/libopie2/opiecore/xmltree.cc index 3d03cc6..408e3c6 100644 --- a/libopie2/opiecore/xmltree.cc +++ b/libopie2/opiecore/xmltree.cc @@ -44,108 +44,110 @@ XMLElement::~XMLElement() void XMLElement::appendChild( XMLElement *child ) { if ( child->m_parent ) child->m_parent->removeChild( child ); child->m_parent = this; if ( m_last ) m_last->m_next = child; child->m_prev = m_last; if ( !m_first ) m_first = child; m_last = child; } void XMLElement::insertAfter( XMLElement *newChild, XMLElement *refChild ) { assert( newChild != refChild ); if ( refChild == m_last ) { appendChild( newChild ); return; } assert( refChild ); assert( refChild->m_parent ); assert( refChild->m_parent == this ); if ( newChild->m_parent && newChild != refChild ) newChild->m_parent->removeChild( newChild ); newChild->m_parent = this; XMLElement *next = refChild->m_next; refChild->m_next = newChild; newChild->m_prev = refChild; newChild->m_next = next; if ( next ) next->m_prev = newChild; } -QString XMLElement::attribute(const QString &attr )const + +QString XMLElement::attribute( const QString &attr ) const { - if ( !m_attributes.contains( attr ) ) - return QString::null; AttributeMap::ConstIterator it = m_attributes.find( attr ); + if ( it == m_attributes.end() ) + return QString::null; return it.data(); } -void XMLElement::setAttribute(const QString &attr, const QString &value ) + +void XMLElement::setAttribute( const QString &attr, const QString &value ) { - m_attributes.remove( attr ); - m_attributes.insert( attr, value ); + m_attributes.replace( attr, value ); } + void XMLElement::insertBefore( XMLElement *newChild, XMLElement *refChild ) { assert( refChild ); assert( refChild->m_parent ); assert( refChild->m_parent == this ); assert( newChild != refChild ); if ( newChild->m_parent && newChild != refChild ) newChild->m_parent->removeChild( newChild ); newChild->m_parent = this; XMLElement *prev = refChild->m_prev; refChild->m_prev = newChild; newChild->m_prev = prev; newChild->m_next = refChild; if ( prev ) prev->m_next = newChild; if ( refChild == m_first ) m_first = newChild; } void XMLElement::removeChild( XMLElement *child ) { if ( child->m_parent != this ) return; if ( m_first == child ) m_first = child->m_next; if ( m_last == child ) m_last = child->m_prev; if ( child->m_prev ) child->m_prev->m_next = child->m_next; if ( child->m_next ) child->m_next->m_prev = child->m_prev; child->m_parent = 0; child->m_prev = 0; child->m_next = 0; } @@ -270,49 +272,50 @@ bool Handler::characters( const QString &ch ) return true; } XMLElement *XMLElement::namedItem( const QString &name ) { XMLElement *e = m_first; for (; e; e = e->nextChild() ) if ( e->tagName() == name ) return e; return 0; } XMLElement *XMLElement::clone() const { XMLElement *res = new XMLElement; res->setTagName( m_tag ); res->setValue( m_value ); res->setAttributes( m_attributes ); XMLElement *e = m_first; for (; e; e = e->m_next ) res->appendChild( e->clone() ); return res; } XMLElement *XMLElement::load( const QString &fileName ) { QFile f( fileName ); if ( !f.open( IO_ReadOnly ) ) return 0; QTextStream stream( &f ); stream.setEncoding( QTextStream::UnicodeUTF8 ); QXmlInputSource src( stream ); QXmlSimpleReader reader; Handler handler; reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false ); reader.setContentHandler( &handler ); reader.parse( src ); return handler.root();; } - +/* vim: et sw=4 + */ |