* http://www.mozilla.org/MPL/ *
***************************************************************************/
-#include <tdebug.h>
-
#include "attachedpictureframe.h"
+#include <tstringlist.h>
+#include <tdebug.h>
+
using namespace TagLib;
using namespace ID3v2;
{
ByteVector data;
- data.append(char(d->textEncoding));
+ String::Type encoding = checkEncoding(d->description, d->textEncoding);
+
+ data.append(char(encoding));
data.append(d->mimeType.data(String::Latin1));
data.append(textDelimiter(String::Latin1));
data.append(char(d->type));
- data.append(d->description.data(d->textEncoding));
- data.append(textDelimiter(d->textEncoding));
+ data.append(d->description.data(encoding));
+ data.append(textDelimiter(encoding));
data.append(d->data);
return data;
#include <tbytevectorlist.h>
#include <id3v2tag.h>
#include <tdebug.h>
+#include <tstringlist.h>
#include "commentsframe.h"
d->text = s;
}
-
String::Type CommentsFrame::textEncoding() const
{
return d->textEncoding;
{
ByteVector v;
- v.append(char(d->textEncoding));
+ String::Type encoding = d->textEncoding;
+
+ encoding = checkEncoding(d->description, encoding);
+ encoding = checkEncoding(d->text, encoding);
+
+ v.append(char(encoding));
v.append(d->language.size() == 3 ? d->language : "XXX");
- v.append(d->description.data(d->textEncoding));
- v.append(textDelimiter(d->textEncoding));
- v.append(d->text.data(d->textEncoding));
+ v.append(d->description.data(encoding));
+ v.append(textDelimiter(encoding));
+ v.append(d->text.data(encoding));
return v;
}
ByteVector TextIdentificationFrame::renderFields() const
{
+ String::Type encoding = checkEncoding(d->fieldList, d->textEncoding);
+
ByteVector v;
- v.append(char(d->textEncoding));
+ v.append(char(encoding));
for(StringList::ConstIterator it = d->fieldList.begin(); it != d->fieldList.end(); it++) {
// encoding.
if(it != d->fieldList.begin())
- v.append(textDelimiter(d->textEncoding));
+ v.append(textDelimiter(encoding));
- v.append((*it).data(d->textEncoding));
+ v.append((*it).data(encoding));
}
return v;
* The ID3v2 Frames document gives a description of each of these formats
* and the expected order of strings in each. ID3v2::Header::frameID() can
* be used to determine the frame type.
+ *
+ * \note If non-Latin1 compatible strings are used with this class, even if
+ * the text encoding is set to Latin1, the frame will be written using UTF8
+ * (with the encoding flag appropriately set in the output).
*/
class TAGLIB_EXPORT TextIdentificationFrame : public Frame
*
* \note In this case you must specify the text encoding as it
* resolves the ambiguity between constructors.
+ *
+ * \note Please see the note in the class description regarding Latin1.
*/
TextIdentificationFrame(const ByteVector &type, String::Type encoding);
* This defaults to the type that was either specified in the constructor
* or read from the frame when parsed.
*
+ * \note Please see the note in the class description regarding Latin1.
+ *
* \see setTextEncoding()
* \see render()
*/
* Sets the text encoding to be used when rendering this frame to
* \a encoding.
*
+ * \note Please see the note in the class description regarding Latin1.
+ *
* \see textEncoding()
* \see render()
*/
#include "urllinkframe.h"
#include <tdebug.h>
+#include <tstringlist.h>
using namespace TagLib;
using namespace ID3v2;
{
ByteVector v;
- v.append(char(d->textEncoding));
- v.append(d->description.data(d->textEncoding));
- v.append(textDelimiter(d->textEncoding));
+ String::Type encoding = checkEncoding(d->description, d->textEncoding);
+
+ v.append(char(encoding));
+ v.append(d->description.data(encoding));
+ v.append(textDelimiter(encoding));
v.append(url().data(String::Latin1));
return v;
#endif
#include <tdebug.h>
+#include <tstringlist.h>
#include "id3v2frame.h"
#include "id3v2synchdata.h"
return str;
}
+String::Type Frame::checkEncoding(const StringList &fields, String::Type encoding) // static
+{
+ if(encoding != String::Latin1)
+ return encoding;
+
+ for(StringList::ConstIterator it = fields.begin(); it != fields.end(); ++it) {
+ if(!(*it).isLatin1()) {
+ debug("Frame::checkEncoding() -- Rendering using UTF8.");
+ return String::UTF8;
+ }
+ }
+
+ return String::Latin1;
+}
////////////////////////////////////////////////////////////////////////////////
// Frame::Header class
return v;
}
-bool Frame::Header::frameAlterPreservation() const // deprecated
+bool Frame::Header::frameAlterPreservation() const
{
return fileAlterPreservation();
}
namespace TagLib {
+ class StringList;
+
namespace ID3v2 {
class Tag;
String readStringField(const ByteVector &data, String::Type encoding,
int *positon = 0);
+ /*!
+ * Checks a the list of string values to see if they can be used with the
+ * specified encoding and returns the recommended encoding.
+ */
+ static String::Type checkEncoding(const StringList &fields,
+ String::Type encoding);
+
private:
Frame(const Frame &);
Frame &operator=(const Frame &);
ByteVector render() const;
/*!
- * @deprecated
+ * \deprecated
*/
bool frameAlterPreservation() const;
String::Type defaultEncoding;
bool useDefaultEncoding;
+
+ template <class T> void setTextEncoding(T *frame)
+ {
+ if(useDefaultEncoding)
+ frame->setTextEncoding(defaultEncoding);
+ }
};
FrameFactory *FrameFactory::factory = 0;
// Text Identification (frames 4.2)
if(frameID.startsWith("T")) {
+
TextIdentificationFrame *f = frameID != "TXXX"
? new TextIdentificationFrame(data, header)
: new UserTextIdentificationFrame(data, header);
- if(d->useDefaultEncoding)
- f->setTextEncoding(d->defaultEncoding);
+ d->setTextEncoding(f);
if(frameID == "TCON")
updateGenre(f);
if(frameID == "COMM") {
CommentsFrame *f = new CommentsFrame(data, header);
- if(d->useDefaultEncoding)
- f->setTextEncoding(d->defaultEncoding);
+ d->setTextEncoding(f);
return f;
}
if(frameID == "APIC") {
AttachedPictureFrame *f = new AttachedPictureFrame(data, header);
- if(d->useDefaultEncoding)
- f->setTextEncoding(d->defaultEncoding);
+ d->setTextEncoding(f);
return f;
}
// General Encapsulated Object (frames 4.15)
- if(frameID == "GEOB")
- return new GeneralEncapsulatedObjectFrame(data, header);
+ if(frameID == "GEOB") {
+ GeneralEncapsulatedObjectFrame *f = new GeneralEncapsulatedObjectFrame(data, header);
+ d->setTextEncoding(f);
+ return f;
+ }
// URL link (frames 4.3)
}
else {
UserUrlLinkFrame *f = new UserUrlLinkFrame(data, header);
- if(d->useDefaultEncoding)
- f->setTextEncoding(d->defaultEncoding);
+ d->setTextEncoding(f);
return f;
}
}