From 79d86829294ac54132c01153660e70e30c15c378 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Wed, 22 Sep 2010 18:15:17 -0400 Subject: [PATCH] Re-add some tests for unprintable but also invalid chars. Apparently Qt's XML classes don't properly check for invalid chars when writing XML, even if you tell them to. Also switch to QXmlStreamWriter, as apparently going forward it is the more supported class. BUG: 251762 --- utilities/collectionscanner/CollectionScanner.cpp | 27 +++++++++++++------- 1 files changed, 17 insertions(+), 10 deletions(-) diff --git a/utilities/collectionscanner/CollectionScanner.cpp b/utilities/collectionscanner/CollectionScanner.cpp index 0a23a53..28c554b 100644 --- a/utilities/collectionscanner/CollectionScanner.cpp +++ b/utilities/collectionscanner/CollectionScanner.cpp @@ -37,13 +37,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include //Taglib: #include @@ -814,8 +814,10 @@ CollectionScanner::readTags( const QString &path, TagLib::AudioProperties::ReadS void CollectionScanner::writeElement( const QString &name, const AttributeHash &attributes ) { - QDomDocument doc; // A dummy. We don't really use DOM, but SAX2 - QDomElement element = doc.createElement( name ); + QString text; + QXmlStreamWriter writer( &text ); + + writer.writeStartElement( name ); QHashIterator it( attributes ); while( it.hasNext() ) @@ -829,7 +831,15 @@ CollectionScanner::writeElement( const QString &name, const AttributeHash &attri bool noCategory = false; for( unsigned i = 0; i < len; i++ ) { - if( data[i].category() == QChar::NoCategory ) + if( data[i].category() == QChar::NoCategory || + data[i].category() == QChar::Other_Surrogate || + ( + data[i].unicode() < 20 && + data[i].unicode() != 9 && + data[i].unicode() != 10 && + data[i].unicode() != 13 + ) + ) { noCategory = true; break; @@ -838,15 +848,12 @@ CollectionScanner::writeElement( const QString &name, const AttributeHash &attri if( noCategory ) continue; - - element.setAttribute( it.key(), it.value() ); + writer.writeAttribute( it.key(), it.value() ); } - QString text; - QTextStream stream( &text, QIODevice::WriteOnly ); - element.save( stream, 0 ); + writer.writeEndElement(); - std::cout << text.toUtf8().data() << std::endl; + std::cout << text.toUtf8().data() << std::endl << std::endl; } // taken verbatim from Qt's sources, since it's stupidly in the QtGui module -- 1.7.0.4