Use iconv to replace non-ascii characters
This commit is contained in:
parent
c9f01f4bc4
commit
e7de7ebbfa
@ -23,6 +23,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <stdlib.h>
|
||||
#include <iconv.h>
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QApplication>
|
||||
@ -795,6 +796,31 @@ QString DesktopEnvironment() {
|
||||
|
||||
}
|
||||
|
||||
QString UnicodeToAscii(const QString &unicode) {
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
iconv_t conv = iconv_open("ASCII//TRANSLIT", "UTF-8");
|
||||
if (conv == (iconv_t) -1) return QString();
|
||||
|
||||
QByteArray utf8 = unicode.toUtf8();
|
||||
size_t input_len = utf8.length() + 1;
|
||||
char input[input_len];
|
||||
|
||||
snprintf(input, input_len, "%s", utf8.constData());
|
||||
|
||||
char output[input_len*2];
|
||||
size_t output_len = sizeof(output);
|
||||
|
||||
char *input_ptr = input;
|
||||
char *output_ptr = output;
|
||||
iconv(conv, &input_ptr, &input_len, &output_ptr, &output_len);
|
||||
iconv_close(conv);
|
||||
|
||||
return QString(output);
|
||||
|
||||
}
|
||||
|
||||
#ifdef HAVE_TRANSLATIONS
|
||||
|
||||
QString SystemLanguageName() {
|
||||
|
@ -155,6 +155,8 @@ QString GetRandomString(const int len, const QString &UseCharacters);
|
||||
|
||||
QString DesktopEnvironment();
|
||||
|
||||
QString UnicodeToAscii(const QString &unicode);
|
||||
|
||||
#ifdef HAVE_TRANSLATIONS
|
||||
QString SystemLanguageName();
|
||||
void LoadTranslation(const QString &prefix, const QString &path, const QString &language);
|
||||
|
@ -166,19 +166,9 @@ QString AlbumCoverLoader::AlbumCoverFileName(QString artist, QString album) {
|
||||
album.remove('/');
|
||||
|
||||
QString filename = artist + "-" + album + ".jpg";
|
||||
filename = filename.toLower();
|
||||
filename = Utilities::UnicodeToAscii(filename.toLower());
|
||||
filename.replace(' ', '-');
|
||||
filename.replace("--", "-");
|
||||
filename.replace(230, "ae");
|
||||
filename.replace(198, "AE");
|
||||
filename.replace(246, 'o');
|
||||
filename.replace(248, 'o');
|
||||
filename.replace(214, 'O');
|
||||
filename.replace(216, 'O');
|
||||
filename.replace(228, 'a');
|
||||
filename.replace(229, 'a');
|
||||
filename.replace(196, 'A');
|
||||
filename.replace(197, 'A');
|
||||
filename.remove(OrganiseFormat::kValidFatCharacters);
|
||||
|
||||
return filename;
|
||||
|
@ -115,20 +115,8 @@ QString OrganiseFormat::GetFilenameForSong(const Song &song) const {
|
||||
filename = Utilities::PathWithoutFilenameExtension(filename) + song.basefilename();
|
||||
}
|
||||
|
||||
if (remove_non_fat_) {
|
||||
filename.replace(230, "ae");
|
||||
filename.replace(198, "AE");
|
||||
filename.replace(246, 'o');
|
||||
filename.replace(248, 'o');
|
||||
filename.replace(214, 'O');
|
||||
filename.replace(216, 'O');
|
||||
filename.replace(228, 'a');
|
||||
filename.replace(229, 'a');
|
||||
filename.replace(196, 'A');
|
||||
filename.replace(197, 'A');
|
||||
filename.remove(kValidFatCharacters);
|
||||
}
|
||||
|
||||
if (remove_non_fat_ || remove_non_ascii_) filename = Utilities::UnicodeToAscii(filename);
|
||||
if (remove_non_fat_) filename.remove(kValidFatCharacters);
|
||||
if (replace_spaces_) filename.replace(QRegExp("\\s"), "_");
|
||||
|
||||
if (remove_non_ascii_) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user