Moved available_codepages() function into MUtilities library.

This commit is contained in:
LoRd_MuldeR 2014-12-19 23:50:58 +01:00
parent a90d30c71e
commit 77219cf7d4
2 changed files with 35 additions and 0 deletions

View File

@ -95,6 +95,8 @@ namespace MUtils
MUTILS_API QString clean_file_name(const QString &name);
MUTILS_API QString clean_file_path(const QString &path);
MUTILS_API QStringList available_codepages(const bool &noAliases = true);
//Internal
namespace Internal
{

View File

@ -35,6 +35,7 @@
#include <QDir>
#include <QReadWriteLock>
#include <QProcess>
#include <QTextCodec>
//CRT
#include <cstdlib>
@ -378,6 +379,38 @@ QString MUtils::clean_file_path(const QString &path)
return parts.join("/");
}
///////////////////////////////////////////////////////////////////////////////
// AVAILABLE CODEPAGES
///////////////////////////////////////////////////////////////////////////////
QStringList MUtils::available_codepages(const bool &noAliases)
{
QStringList codecList;
QList<QByteArray> availableCodecs = QTextCodec::availableCodecs();
while(!availableCodecs.isEmpty())
{
const QByteArray current = availableCodecs.takeFirst();
if(!current.toLower().startsWith("system"))
{
codecList << QString::fromLatin1(current.constData(), current.size());
if(noAliases)
{
if(QTextCodec *const currentCodec = QTextCodec::codecForName(current.constData()))
{
const QList<QByteArray> aliases = currentCodec->aliases();
for(QList<QByteArray>::ConstIterator iter = aliases.constBegin(); iter != aliases.constEnd(); iter++)
{
availableCodecs.removeAll(*iter);
}
}
}
}
}
return codecList;
}
///////////////////////////////////////////////////////////////////////////////
// SELF-TEST
///////////////////////////////////////////////////////////////////////////////