mirror of
https://abf.rosa.ru/djam/taglib.git
synced 2025-02-24 06:12:49 +00:00
670 lines
20 KiB
Diff
670 lines
20 KiB
Diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|
index 298ee7e..94fbd55 100644
|
|
--- a/CMakeLists.txt
|
|
+++ b/CMakeLists.txt
|
|
@@ -119,6 +119,8 @@ if(NOT HAVE_ZLIB AND ZLIB_SOURCE)
|
|
set(HAVE_ZLIB_SOURCE 1)
|
|
endif()
|
|
|
|
+SET(HAVE_LIBRCC 1)
|
|
+
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
|
configure_file(config.h.cmake "${CMAKE_CURRENT_BINARY_DIR}/config.h")
|
|
|
|
diff --git a/config.h.cmake b/config.h.cmake
|
|
index 7eb5993..8d4a541 100644
|
|
--- a/config.h.cmake
|
|
+++ b/config.h.cmake
|
|
@@ -30,4 +30,7 @@
|
|
/* Indicates whether debug messages are shown even in release mode */
|
|
#cmakedefine TRACE_IN_RELEASE 1
|
|
|
|
+/* Defined if you have LibRCC from RusXMMS project */
|
|
+#cmakedefine HAVE_LIBRCC 1
|
|
+
|
|
#cmakedefine TESTS_DIR "@TESTS_DIR@"
|
|
diff --git a/examples/tagreader_c.c b/examples/tagreader_c.c
|
|
index 0436992..e0f17d8 100644
|
|
--- a/examples/tagreader_c.c
|
|
+++ b/examples/tagreader_c.c
|
|
@@ -38,7 +38,7 @@ int main(int argc, char *argv[])
|
|
TagLib_Tag *tag;
|
|
const TagLib_AudioProperties *properties;
|
|
|
|
- taglib_set_strings_unicode(FALSE);
|
|
+ //taglib_set_strings_unicode(FALSE);
|
|
|
|
for(i = 1; i < argc; i++) {
|
|
printf("******************** \"%s\" ********************\n", argv[i]);
|
|
diff --git a/examples/tagwriter.cpp b/examples/tagwriter.cpp
|
|
index ed8b0d7..6a7a263 100644
|
|
--- a/examples/tagwriter.cpp
|
|
+++ b/examples/tagwriter.cpp
|
|
@@ -115,7 +115,7 @@ int main(int argc, char *argv[])
|
|
if(isArgument(argv[i]) && i + 1 < argc && !isArgument(argv[i + 1])) {
|
|
|
|
char field = argv[i][1];
|
|
- TagLib::String value = argv[i + 1];
|
|
+ TagLib::String value(argv[i + 1], TagLib::String::Locale);
|
|
|
|
TagLib::List<TagLib::FileRef>::ConstIterator it;
|
|
for(it = fileList.begin(); it != fileList.end(); ++it) {
|
|
diff --git a/taglib/CMakeLists.txt b/taglib/CMakeLists.txt
|
|
index 000f793..e30471e 100644
|
|
--- a/taglib/CMakeLists.txt
|
|
+++ b/taglib/CMakeLists.txt
|
|
@@ -42,6 +42,7 @@ set(tag_HDRS
|
|
audioproperties.h
|
|
taglib_export.h
|
|
${CMAKE_CURRENT_BINARY_DIR}/../taglib_config.h
|
|
+ toolkit/rccpatch.h
|
|
toolkit/taglib.h
|
|
toolkit/tstring.h
|
|
toolkit/tlist.h
|
|
@@ -297,6 +298,7 @@ set(xm_SRCS
|
|
)
|
|
|
|
set(toolkit_SRCS
|
|
+ toolkit/rccpatch.cpp
|
|
toolkit/tstring.cpp
|
|
toolkit/tstringlist.cpp
|
|
toolkit/tbytevector.cpp
|
|
@@ -345,7 +347,7 @@ set(tag_LIB_SRCS
|
|
add_library(tag ${tag_LIB_SRCS} ${tag_HDRS})
|
|
|
|
if(ZLIB_FOUND)
|
|
- target_link_libraries(tag ${ZLIB_LIBRARIES})
|
|
+ target_link_libraries(tag rcc ${ZLIB_LIBRARIES})
|
|
endif()
|
|
|
|
if(HAVE_BOOST_ATOMIC)
|
|
diff --git a/taglib/mpeg/id3v1/id3v1tag.cpp b/taglib/mpeg/id3v1/id3v1tag.cpp
|
|
index ca93041..dca5f7a 100644
|
|
--- a/taglib/mpeg/id3v1/id3v1tag.cpp
|
|
+++ b/taglib/mpeg/id3v1/id3v1tag.cpp
|
|
@@ -69,15 +69,15 @@ StringHandler::StringHandler()
|
|
|
|
String ID3v1::StringHandler::parse(const ByteVector &data) const
|
|
{
|
|
- return String(data, String::Latin1).stripWhiteSpace();
|
|
+ return String(data, String::Latin1ID3).stripWhiteSpace();
|
|
}
|
|
|
|
ByteVector ID3v1::StringHandler::render(const String &s) const
|
|
{
|
|
- if(s.isLatin1())
|
|
- return s.data(String::Latin1);
|
|
- else
|
|
+ if(!s.isLatin1() && String::ID3WType(String::Latin1) == String::Latin1)
|
|
return ByteVector();
|
|
+
|
|
+ return s.data(String::Latin1ID3);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -262,7 +262,7 @@ void ID3v1::Tag::parse(const ByteVector &data)
|
|
d->track = static_cast<unsigned char>(data[offset + 29]);
|
|
}
|
|
else
|
|
- d->comment = data.mid(offset, 30);
|
|
+ d->comment = stringHandler->parse(data.mid(offset, 30));
|
|
|
|
offset += 30;
|
|
|
|
diff --git a/taglib/mpeg/id3v2/frames/commentsframe.cpp b/taglib/mpeg/id3v2/frames/commentsframe.cpp
|
|
index b561832..9cfaba2 100644
|
|
--- a/taglib/mpeg/id3v2/frames/commentsframe.cpp
|
|
+++ b/taglib/mpeg/id3v2/frames/commentsframe.cpp
|
|
@@ -148,10 +148,10 @@ void CommentsFrame::parseFields(const ByteVector &data)
|
|
return;
|
|
}
|
|
|
|
- d->textEncoding = String::Type(data[0]);
|
|
+ d->textEncoding = String::ID3Type(data[0]);
|
|
d->language = data.mid(1, 3);
|
|
|
|
- int byteAlign = d->textEncoding == String::Latin1 || d->textEncoding == String::UTF8 ? 1 : 2;
|
|
+ int byteAlign = (d->textEncoding == String::Latin1 || d->textEncoding == String::Latin1ID3 || d->textEncoding == String::Latin1ID3V2 || d->textEncoding == String::UTF8) ? 1 : 2;
|
|
|
|
ByteVectorList l = ByteVectorList::split(data.mid(4), textDelimiter(d->textEncoding), byteAlign, 2);
|
|
|
|
@@ -171,11 +171,13 @@ ByteVector CommentsFrame::renderFields() const
|
|
ByteVector v;
|
|
|
|
String::Type encoding = d->textEncoding;
|
|
+
|
|
+ encoding = String::ID3WType(encoding);
|
|
|
|
encoding = checkTextEncoding(d->description, encoding);
|
|
encoding = checkTextEncoding(d->text, encoding);
|
|
|
|
- v.append(char(encoding));
|
|
+ v.append(char(String::ID3RealType(encoding)));
|
|
v.append(d->language.size() == 3 ? d->language : "XXX");
|
|
v.append(d->description.data(encoding));
|
|
v.append(textDelimiter(encoding));
|
|
diff --git a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp
|
|
index d9d3b29..74f69da 100644
|
|
--- a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp
|
|
+++ b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp
|
|
@@ -191,12 +191,12 @@ void TextIdentificationFrame::parseFields(const ByteVector &data)
|
|
|
|
// read the string data type (the first byte of the field data)
|
|
|
|
- d->textEncoding = String::Type(data[0]);
|
|
+ d->textEncoding = String::ID3Type(data[0]);
|
|
|
|
// split the byte array into chunks based on the string type (two byte delimiter
|
|
// for unicode encodings)
|
|
|
|
- int byteAlign = d->textEncoding == String::Latin1 || d->textEncoding == String::UTF8 ? 1 : 2;
|
|
+ int byteAlign = (d->textEncoding == String::Latin1 || d->textEncoding == String::Latin1ID3 || d->textEncoding == String::Latin1ID3V2 || d->textEncoding == String::UTF8) ? 1 : 2;
|
|
|
|
// build a small counter to strip nulls off the end of the field
|
|
|
|
@@ -227,11 +227,14 @@ void TextIdentificationFrame::parseFields(const ByteVector &data)
|
|
|
|
ByteVector TextIdentificationFrame::renderFields() const
|
|
{
|
|
- String::Type encoding = checkTextEncoding(d->fieldList, d->textEncoding);
|
|
+ String::Type encoding = d->textEncoding;
|
|
+
|
|
+ encoding = String::ID3WType(encoding);
|
|
+ encoding = checkTextEncoding(d->fieldList, encoding);
|
|
|
|
ByteVector v;
|
|
|
|
- v.append(char(encoding));
|
|
+ v.append(char(String::ID3RealType(encoding)));
|
|
|
|
for(StringList::ConstIterator it = d->fieldList.begin(); it != d->fieldList.end(); it++) {
|
|
|
|
diff --git a/taglib/mpeg/id3v2/id3v2frame.cpp b/taglib/mpeg/id3v2/id3v2frame.cpp
|
|
index 1f896fa..ef9d91d 100644
|
|
--- a/taglib/mpeg/id3v2/id3v2frame.cpp
|
|
+++ b/taglib/mpeg/id3v2/id3v2frame.cpp
|
|
@@ -297,7 +297,7 @@ String::Type Frame::checkEncoding(const StringList &fields, String::Type encodin
|
|
if((encoding == String::UTF8 || encoding == String::UTF16BE) && version != 4)
|
|
return String::UTF16;
|
|
|
|
- if(encoding != String::Latin1)
|
|
+ if((encoding != String::Latin1)&&(encoding != String::Latin1ID3V2))
|
|
return encoding;
|
|
|
|
for(StringList::ConstIterator it = fields.begin(); it != fields.end(); ++it) {
|
|
diff --git a/taglib/toolkit/rccpatch.cpp b/taglib/toolkit/rccpatch.cpp
|
|
new file mode 100644
|
|
index 0000000..af99323
|
|
--- /dev/null
|
|
+++ b/taglib/toolkit/rccpatch.cpp
|
|
@@ -0,0 +1,237 @@
|
|
+#include <stdlib.h>
|
|
+
|
|
+#include <string>
|
|
+#include "tstring.h"
|
|
+#include "tbytevector.h"
|
|
+
|
|
+//#define RCC_DEBUG
|
|
+
|
|
+
|
|
+#ifndef HAVE_LIBRCC
|
|
+# include <config.h>
|
|
+#endif
|
|
+
|
|
+#ifdef HAVE_LIBRCC
|
|
+# ifdef RCC_DEBUG
|
|
+# include <stdio.h>
|
|
+# endif /* RCC_DEBUG */
|
|
+# include <librcc.h>
|
|
+# include <string.h>
|
|
+#endif /* HAVE_LIBRCC */
|
|
+
|
|
+
|
|
+#ifdef HAVE_LIBRCC
|
|
+# define ID3_CLASS 0
|
|
+# define ID3V2_CLASS 1
|
|
+# define UTF_CLASS 2
|
|
+# define OUT_CLASS 3
|
|
+static rcc_class classes[] = {
|
|
+ { "id3", RCC_CLASS_STANDARD, NULL, NULL, "ID3 Encoding", 0 },
|
|
+ { "id3v2", RCC_CLASS_STANDARD, "id3", NULL, "ID3 v.2 Encoding", 0 },
|
|
+ { "utf", RCC_CLASS_KNOWN, "UTF-8", NULL, "Unicode Encoding", 0},
|
|
+ { "out", RCC_CLASS_TRANSLATE_LOCALE, "LC_CTYPE", NULL, "Output Encoding", 0 },
|
|
+ { NULL, RCC_CLASS_STANDARD, NULL, NULL, NULL, 0 }
|
|
+};
|
|
+
|
|
+static int rcc_initialized = 0;
|
|
+
|
|
+static rcc_context ctx = NULL;
|
|
+#endif /* HAVE_LIBRCC */
|
|
+
|
|
+
|
|
+void rccTaglibPatchFree() {
|
|
+#ifdef HAVE_LIBRCC
|
|
+ if (rcc_initialized) {
|
|
+ rccFree();
|
|
+ rcc_initialized = 0;
|
|
+ }
|
|
+#endif /* HAVE_LIBRCC */
|
|
+}
|
|
+
|
|
+void rccTaglibPatchInit() {
|
|
+#ifdef HAVE_LIBRCC
|
|
+ if (rcc_initialized) return;
|
|
+ rccInit();
|
|
+ rccInitDefaultContext(NULL, 0, 0, classes, 0);
|
|
+ rccLoad(NULL, "xmms");
|
|
+ rccInitDb4(NULL, NULL, 0);
|
|
+ rcc_initialized = 1;
|
|
+#endif /* HAVE_LIBRCC */
|
|
+}
|
|
+
|
|
+void rccTaglibPatchSetContext(void *newctx) {
|
|
+#ifdef HAVE_LIBRCC
|
|
+ if (newctx) {
|
|
+ ctx = (rcc_context)newctx;
|
|
+ rcc_initialized = 1;
|
|
+ }
|
|
+#endif /* HAVE_LIBRCC */
|
|
+}
|
|
+
|
|
+static void rccTaglibPatchTryInit() {
|
|
+#ifdef HAVE_LIBRCC
|
|
+ if (!rcc_initialized) {
|
|
+ rccTaglibPatchInit();
|
|
+ if (rcc_initialized) atexit(rccTaglibPatchFree);
|
|
+ }
|
|
+#endif /* HAVE_LIBRCC */
|
|
+}
|
|
+
|
|
+
|
|
+TagLib::ByteVector rccTaglibPatchRecodeOutput(const std::string &s) {
|
|
+ TagLib::ByteVector v;
|
|
+#ifdef HAVE_LIBRCC
|
|
+ size_t rlen;
|
|
+ char *res;
|
|
+
|
|
+ rccTaglibPatchTryInit();
|
|
+
|
|
+ res = rccSizedRecode(ctx, UTF_CLASS, OUT_CLASS, s.c_str(), s.length(), &rlen);
|
|
+#ifdef RCC_DEBUG
|
|
+ for (const unsigned char *c = (const unsigned char*)s.c_str(); *c; c++) {
|
|
+ if (*c > 127) {
|
|
+ printf(" Output: %s - %s\n", s.c_str(), res?res:"null");
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+#endif /* RCC_DEBUG */
|
|
+
|
|
+ if (res) v.setData(res, rlen);
|
|
+ else v.setData("", 0);
|
|
+ //v.setData(s.c_str(), s.length());
|
|
+
|
|
+ return v;
|
|
+#else
|
|
+ v.setData("", 0);
|
|
+
|
|
+ return v;
|
|
+#endif /* HAVE_LIBRCC */
|
|
+}
|
|
+
|
|
+TagLib::ByteVector rccTaglibPatchRecodeOutputID3(const std::string &s, bool v2 = false) {
|
|
+ TagLib::ByteVector v;
|
|
+#ifdef HAVE_LIBRCC
|
|
+ size_t rlen;
|
|
+ char *res;
|
|
+
|
|
+ rccTaglibPatchTryInit();
|
|
+
|
|
+ res = rccSizedRecode(ctx, UTF_CLASS, v2?ID3V2_CLASS:ID3_CLASS, s.c_str(), s.length(), &rlen);
|
|
+#ifdef RCC_DEBUG
|
|
+ for (const unsigned char *c = (const unsigned char*)s.c_str(); *c; c++) {
|
|
+ if (*c > 127) {
|
|
+ printf(" OutputID3(%i): %s - %s\n", v2, s.c_str(), res?res:"null");
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+#endif /* RCC_DEBUG */
|
|
+
|
|
+ if (res) v.setData(res, rlen);
|
|
+ else v.setData("", 0);
|
|
+ //v.setData(s.c_str(), s.length());
|
|
+
|
|
+ return v;
|
|
+#else
|
|
+ v.setData("", 0);
|
|
+
|
|
+ return v;
|
|
+#endif /* HAVE_LIBRCC */
|
|
+}
|
|
+
|
|
+TagLib::ByteVector rccTaglibPatchRecodeInput(const std::string &s) {
|
|
+ TagLib::ByteVector v;
|
|
+#ifdef HAVE_LIBRCC
|
|
+ size_t rlen;
|
|
+ char *res;
|
|
+
|
|
+ rccTaglibPatchTryInit();
|
|
+
|
|
+ res = rccSizedRecode(ctx, OUT_CLASS, UTF_CLASS, s.c_str(), s.length(), &rlen);
|
|
+#ifdef RCC_DEBUG
|
|
+ for (const unsigned char *c = (const unsigned char*)s.c_str(); *c; c++) {
|
|
+ if (*c > 127) {
|
|
+ printf(" Input: %s - %s\n", s.c_str(), res?res:"null");
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+#endif /* RCC_DEBUG */
|
|
+
|
|
+ if (res) v.setData(res, rlen);
|
|
+ else
|
|
+#endif /* HAVE_LIBRCC */
|
|
+ v.setData("", 0);
|
|
+
|
|
+ return v;
|
|
+}
|
|
+
|
|
+TagLib::ByteVector rccTaglibPatchRecodeInputID3(const std::string &s, bool v2 = false) {
|
|
+ TagLib::ByteVector v;
|
|
+#ifdef HAVE_LIBRCC
|
|
+ size_t rlen;
|
|
+ char *res;
|
|
+
|
|
+ rccTaglibPatchTryInit();
|
|
+
|
|
+ res = rccSizedRecode(ctx, v2?ID3V2_CLASS:ID3_CLASS, UTF_CLASS, s.c_str(), s.length(), &rlen);
|
|
+#ifdef RCC_DEBUG
|
|
+ for (const unsigned char *c = (const unsigned char*)s.c_str(); *c; c++) {
|
|
+ if (*c > 127) {
|
|
+ printf(" InputID3(%i): %s - %s\n", v2, s.c_str(), res?res:"null");
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+#endif /* RCC_DEBUG */
|
|
+ if (res) v.setData(res, rlen + 1);
|
|
+ else
|
|
+#endif /* HAVE_LIBRCC */
|
|
+ v.setData("", 0);
|
|
+
|
|
+ return v;
|
|
+}
|
|
+
|
|
+TagLib::String::Type rccTaglibPatchGetLocaleType() {
|
|
+#ifdef HAVE_LIBRCC
|
|
+ size_t len;
|
|
+ char charset[32];
|
|
+
|
|
+ rccTaglibPatchTryInit();
|
|
+ if (!rccLocaleGetCharset(charset, NULL, 31)) {
|
|
+ if (!strncmp(charset, "UTF", 3)) {
|
|
+ len = strlen(charset);
|
|
+
|
|
+ if (charset[len-1]=='8') return TagLib::String::UTF8;
|
|
+ if (!strcmp(charset+(len-2),"16")) return TagLib::String::UTF16;
|
|
+ if (!strcmp(charset+(len-4),"16LE")) return TagLib::String::UTF16LE;
|
|
+ if (!strcmp(charset+(len-4),"16BE")) return TagLib::String::UTF16BE;
|
|
+ }
|
|
+ return TagLib::String::Latin1;
|
|
+ }
|
|
+#endif /* HAVE_LIBRCC */
|
|
+ return TagLib::String::UTF8;
|
|
+}
|
|
+
|
|
+TagLib::String::Type rccTaglibPatchGetID3Type() {
|
|
+#ifdef HAVE_LIBRCC
|
|
+ size_t len;
|
|
+ const char *charset;
|
|
+
|
|
+ rccTaglibPatchTryInit();
|
|
+
|
|
+ charset = rccGetCurrentCharsetName(ctx, ID3V2_CLASS);
|
|
+ if (charset) {
|
|
+ if (!strncmp(charset, "UTF", 3)) {
|
|
+ len = strlen(charset);
|
|
+
|
|
+ if (charset[len-1]=='8') return TagLib::String::UTF8;
|
|
+ if (!strcmp(charset+(len-2),"16")) return TagLib::String::UTF16;
|
|
+ if (!strcmp(charset+(len-4),"16LE")) return TagLib::String::UTF16LE;
|
|
+ if (!strcmp(charset+(len-4),"16BE")) return TagLib::String::UTF16BE;
|
|
+ }
|
|
+ return TagLib::String::Latin1ID3V2;
|
|
+ } else {
|
|
+ // Error or no-language configured: If Latin1ID3V2 is returned we normally will use the default unicode encoding unless Latin1 is selected by taglib
|
|
+ return TagLib::String::Latin1ID3V2;
|
|
+ }
|
|
+#endif /* HAVE_LIBRCC */
|
|
+ return TagLib::String::Latin1;
|
|
+}
|
|
diff --git a/taglib/toolkit/rccpatch.h b/taglib/toolkit/rccpatch.h
|
|
new file mode 100644
|
|
index 0000000..31f4410
|
|
--- /dev/null
|
|
+++ b/taglib/toolkit/rccpatch.h
|
|
@@ -0,0 +1,20 @@
|
|
+#ifndef _RCC_PATCH_H
|
|
+#define _RCC_PATCH_H
|
|
+
|
|
+#include <string.h>
|
|
+#include "tstring.h"
|
|
+#include "tbytevector.h"
|
|
+
|
|
+void rccTaglibPatchFree();
|
|
+void rccTaglibPatchInit();
|
|
+void rccTaglibPatchSetContext(void *newctx);
|
|
+
|
|
+TagLib::ByteVector rccTaglibPatchRecodeOutput(const std::string &s);
|
|
+TagLib::ByteVector rccTaglibPatchRecodeInput(const std::string &s);
|
|
+TagLib::ByteVector rccTaglibPatchRecodeOutputID3(const std::string &s, bool v2 = false);
|
|
+TagLib::ByteVector rccTaglibPatchRecodeInputID3(const std::string &s, bool v2 = false);
|
|
+
|
|
+TagLib::String::Type rccTaglibPatchGetLocaleType();
|
|
+TagLib::String::Type rccTaglibPatchGetID3Type();
|
|
+
|
|
+#endif /* _RCC_PATCH_H */
|
|
diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp
|
|
index 01a6926..d641ae5 100644
|
|
--- a/taglib/toolkit/tstring.cpp
|
|
+++ b/taglib/toolkit/tstring.cpp
|
|
@@ -42,6 +42,7 @@
|
|
#include <trefcounter.h>
|
|
#include <tutils.h>
|
|
|
|
+#include "rccpatch.h"
|
|
#include "tstring.h"
|
|
|
|
namespace
|
|
@@ -120,15 +121,37 @@ namespace
|
|
else
|
|
return String::UTF16BE;
|
|
}
|
|
+
|
|
+ void copyFromUTF8(std::wstring &data, const char *s, size_t length);
|
|
|
|
// Converts a Latin-1 string into UTF-16(without BOM/CPU byte order)
|
|
// and copies it to the internal buffer.
|
|
- void copyFromLatin1(std::wstring &data, const char *s, size_t length)
|
|
+ void copyFromLatin1(std::wstring &data, const char *s, size_t length, bool prepare = false, String::Type t = String::Latin1)
|
|
{
|
|
data.resize(length);
|
|
|
|
for(size_t i = 0; i < length; ++i)
|
|
data[i] = static_cast<unsigned char>(s[i]);
|
|
+
|
|
+
|
|
+ // librcc conversation
|
|
+ if (prepare) {
|
|
+
|
|
+ ByteVector v;
|
|
+ std::string str = std::string(s, length);
|
|
+
|
|
+ if (t == String::Latin1ID3) v = rccTaglibPatchRecodeInputID3(str, false);
|
|
+ else if (t == String::Latin1ID3V2) v = rccTaglibPatchRecodeInputID3(str, true);
|
|
+ else /* Latin1 converted from Locale */ v = rccTaglibPatchRecodeInput(str);
|
|
+
|
|
+ if (v.size()) {
|
|
+ copyFromUTF8(data, v.data(), v.size());
|
|
+ } else {
|
|
+ // We don't know if we got UTF-8 encoded string or either rcc is disable or something is failed,
|
|
+ // since standard applications are really expecting here Latin1, it is safe to just check if we have violations of UTF8
|
|
+ //if (Unicode::isLegalUTF8(s)) t = UTF8;
|
|
+ }
|
|
+ }
|
|
}
|
|
|
|
// Converts a UTF-8 string into UTF-16(without BOM/CPU byte order)
|
|
@@ -264,8 +287,11 @@ String::String(const String &s) :
|
|
String::String(const std::string &s, Type t) :
|
|
d(new StringPrivate())
|
|
{
|
|
- if(t == Latin1)
|
|
- copyFromLatin1(d->data, s.c_str(), s.length());
|
|
+ if(t == Locale)
|
|
+ t = rccTaglibPatchGetLocaleType();
|
|
+
|
|
+ if(t == Latin1 || t == Latin1ID3 || t == Latin1ID3V2)
|
|
+ copyFromLatin1(d->data, s.c_str(), s.length(), true, t);
|
|
else if(t == String::UTF8)
|
|
copyFromUTF8(d->data, s.c_str(), s.length());
|
|
else {
|
|
@@ -312,8 +338,11 @@ String::String(const wchar_t *s, Type t) :
|
|
String::String(const char *s, Type t) :
|
|
d(new StringPrivate())
|
|
{
|
|
- if(t == Latin1)
|
|
- copyFromLatin1(d->data, s, ::strlen(s));
|
|
+ if(t == Locale)
|
|
+ t = rccTaglibPatchGetLocaleType();
|
|
+
|
|
+ if(t == Latin1 || t == Latin1ID3 || t == Latin1ID3V2)
|
|
+ copyFromLatin1(d->data, s, ::strlen(s), true, t);
|
|
else if(t == String::UTF8)
|
|
copyFromUTF8(d->data, s, ::strlen(s));
|
|
else {
|
|
@@ -344,9 +373,13 @@ String::String(const ByteVector &v, Type t) :
|
|
{
|
|
if(v.isEmpty())
|
|
return;
|
|
+
|
|
+ if(t == Locale)
|
|
+ t = rccTaglibPatchGetLocaleType();
|
|
+
|
|
+ if(t == Latin1 || t == Latin1ID3 || t == Latin1ID3V2)
|
|
+ copyFromLatin1(d->data, v.data(), v.size(), true, t);
|
|
|
|
- if(t == Latin1)
|
|
- copyFromLatin1(d->data, v.data(), v.size());
|
|
else if(t == UTF8)
|
|
copyFromUTF8(d->data, v.data(), v.size());
|
|
else
|
|
@@ -499,8 +532,38 @@ bool String::isNull() const
|
|
|
|
ByteVector String::data(Type t) const
|
|
{
|
|
- switch(t)
|
|
- {
|
|
+ ByteVector v;
|
|
+
|
|
+ if (t == Locale) {
|
|
+ // The source is either Unicode or real Latin1 (if rcc is bypassed)
|
|
+ std::string s = to8Bit(true);
|
|
+
|
|
+ // In case of UTF8 locale, this probably will return NULL (no recoding needed), but we will take UTF8 path in the next swtich
|
|
+ v = rccTaglibPatchRecodeOutput(s);
|
|
+ if (v.size()) return v;
|
|
+
|
|
+ t = rccTaglibPatchGetLocaleType();
|
|
+ }
|
|
+
|
|
+ switch(t) {
|
|
+ case Latin1ID3:
|
|
+ case Latin1ID3V2:
|
|
+ {
|
|
+ std::string s = to8Bit(true);
|
|
+ if (t == Latin1ID3) v = rccTaglibPatchRecodeOutputID3(s, false);
|
|
+ else if (t == Latin1ID3V2) v = rccTaglibPatchRecodeOutputID3(s, true);
|
|
+ if (v.size())
|
|
+ return v;
|
|
+
|
|
+ // we don't know if we got NULL because rcc is disabled (error) or UTF8 output is required
|
|
+ if ((t == Latin1ID3V2)&&(rccTaglibPatchGetID3Type() == UTF8)) {
|
|
+ v.setData(s.c_str(), s.length());
|
|
+ } else {
|
|
+ for(wstring::const_iterator it = d->data.begin(); it != d->data.end(); it++)
|
|
+ v.append(char(*it));
|
|
+ }
|
|
+ return v;
|
|
+ }
|
|
case Latin1:
|
|
{
|
|
ByteVector v(size(), 0);
|
|
@@ -816,7 +879,35 @@ const TagLib::String operator+(const TagLib::String &s1, const char *s2)
|
|
|
|
std::ostream &operator<<(std::ostream &s, const TagLib::String &str)
|
|
{
|
|
- s << str.to8Bit();
|
|
+ TagLib::ByteVector bv = str.data(TagLib::String::Locale);
|
|
+ s << bv;
|
|
return s;
|
|
}
|
|
|
|
+TagLib::String::Type TagLib::String::ID3Type(int i)
|
|
+{
|
|
+ if(i == Latin1)
|
|
+ return Latin1ID3V2;
|
|
+ return Type(i);
|
|
+};
|
|
+
|
|
+TagLib::String::Type TagLib::String::ID3WType(Type type)
|
|
+{
|
|
+ Type rcc_type = rccTaglibPatchGetID3Type();
|
|
+ if((rcc_type == Latin1ID3)||(rcc_type == Latin1ID3V2)||(rcc_type == Latin1)) {
|
|
+ if(type == Latin1) return
|
|
+ rcc_type;
|
|
+ return type;
|
|
+ }
|
|
+
|
|
+ return rcc_type;
|
|
+};
|
|
+
|
|
+TagLib::String::Type TagLib::String::ID3RealType(Type type)
|
|
+{
|
|
+ if((type == Latin1ID3) || (type == Latin1ID3V2))
|
|
+ return Latin1;
|
|
+ return type;
|
|
+}
|
|
+
|
|
+
|
|
diff --git a/taglib/toolkit/tstring.h b/taglib/toolkit/tstring.h
|
|
index 97e9ff6..d95f645 100644
|
|
--- a/taglib/toolkit/tstring.h
|
|
+++ b/taglib/toolkit/tstring.h
|
|
@@ -96,6 +96,18 @@ namespace TagLib {
|
|
*/
|
|
enum Type {
|
|
/*!
|
|
+ * Determine using current locale settings
|
|
+ */
|
|
+ Locale = -1,
|
|
+ /*!
|
|
+ * Latin1 for ID3 tags.
|
|
+ */
|
|
+ Latin1ID3 = 65,
|
|
+ /*!
|
|
+ * Latin1 for ID3v2 tags.
|
|
+ */
|
|
+ Latin1ID3V2 = 66,
|
|
+ /*!
|
|
* IS08859-1, or <i>Latin1</i> encoding. 8 bit characters.
|
|
*/
|
|
Latin1 = 0,
|
|
@@ -117,6 +129,10 @@ namespace TagLib {
|
|
*/
|
|
UTF16LE = 4
|
|
};
|
|
+
|
|
+ static Type ID3Type(int i);
|
|
+ static Type ID3WType(Type type);
|
|
+ static Type ID3RealType(Type type);
|
|
|
|
/*!
|
|
* Constructs an empty String.
|