changeset 1035:d74ebd2d2c49

Require (and provide) text codec for output stream -- fixing #1153 (wrong codec used when writing RDF)
author Chris Cannam
date Mon, 02 Mar 2015 17:17:59 +0000
parents 88b54a185a0a
children 682d64f05e72
files rdf/RDFFeatureWriter.cpp transform/CSVFeatureWriter.cpp transform/FileFeatureWriter.cpp transform/FileFeatureWriter.h
diffstat 4 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/rdf/RDFFeatureWriter.cpp	Mon Dec 08 15:37:12 2014 +0000
+++ b/rdf/RDFFeatureWriter.cpp	Mon Mar 02 17:17:59 2015 +0000
@@ -22,6 +22,7 @@
 #include "PluginRDFIndexer.h"
 
 #include <QTextStream>
+#include <QTextCodec>
 #include <QUrl>
 #include <QFileInfo>
 #include <QRegExp>
@@ -160,7 +161,8 @@
     // Need to select appropriate output file for our track/transform
     // combination
 
-    QTextStream *stream = getOutputStream(trackId, transform.getIdentifier());
+    QTextStream *stream = getOutputStream(trackId, transform.getIdentifier(),
+                                          QTextCodec::codecForName("UTF-8"));
     if (!stream) {
         throw FailedToOpenOutputStream(trackId, transform.getIdentifier());
     }
--- a/transform/CSVFeatureWriter.cpp	Mon Dec 08 15:37:12 2014 +0000
+++ b/transform/CSVFeatureWriter.cpp	Mon Mar 02 17:17:59 2015 +0000
@@ -23,6 +23,7 @@
 
 #include <QRegExp>
 #include <QTextStream>
+#include <QTextCodec>
 
 using namespace std;
 using namespace Vamp;
@@ -123,7 +124,9 @@
     // Select appropriate output file for our track/transform
     // combination
 
-    QTextStream *sptr = getOutputStream(trackId, transformId);
+    QTextStream *sptr = getOutputStream(trackId,
+                                        transformId,
+                                        QTextCodec::codecForName("UTF-8"));
     if (!sptr) {
         throw FailedToOpenOutputStream(trackId, transformId);
     }
@@ -169,7 +172,9 @@
          i != m_pending.end(); ++i) {
         DataId tt = i->first;
         Plugin::Feature f = i->second;
-        QTextStream *sptr = getOutputStream(tt.first, tt.second.getIdentifier());
+        QTextStream *sptr = getOutputStream(tt.first,
+                                            tt.second.getIdentifier(),
+                                            QTextCodec::codecForName("UTF-8"));
         if (!sptr) {
             throw FailedToOpenOutputStream(tt.first, tt.second.getIdentifier());
         }
--- a/transform/FileFeatureWriter.cpp	Mon Dec 08 15:37:12 2014 +0000
+++ b/transform/FileFeatureWriter.cpp	Mon Mar 02 17:17:59 2015 +0000
@@ -315,7 +315,8 @@
 
 
 QTextStream *FileFeatureWriter::getOutputStream(QString trackId,
-                                               TransformId transformId)
+                                                TransformId transformId,
+                                                QTextCodec *codec)
 {
     QFile *file = getOutputFile(trackId, transformId);
     if (!file && !m_stdout) {
@@ -328,6 +329,7 @@
         } else {
             m_streams[file] = new QTextStream(file);
         }
+        m_streams[file]->setCodec(codec);
     }
 
     QTextStream *stream = m_streams[file];
--- a/transform/FileFeatureWriter.h	Mon Dec 08 15:37:12 2014 +0000
+++ b/transform/FileFeatureWriter.h	Mon Mar 02 17:17:59 2015 +0000
@@ -32,6 +32,7 @@
 using std::pair;
 
 class QTextStream;
+class QTextCodec;
 class QFile;
 
 class FileFeatureWriter : public FeatureWriter
@@ -55,7 +56,7 @@
     };
 
     FileFeatureWriter(int support, QString extension);
-    QTextStream *getOutputStream(QString, TransformId);
+    QTextStream *getOutputStream(QString, TransformId, QTextCodec *);
 
     typedef pair<QString, TransformId> TrackTransformPair;
     typedef map<TrackTransformPair, QString> FileNameMap;