From 77219cf7d430c86e017ca98993fcada9822c7bde Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Fri, 19 Dec 2014 23:50:58 +0100 Subject: [PATCH] Moved available_codepages() function into MUtilities library. --- include/MUtils/Global.h | 2 ++ src/Global.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/MUtils/Global.h b/include/MUtils/Global.h index 07750a7..286efa4 100644 --- a/include/MUtils/Global.h +++ b/include/MUtils/Global.h @@ -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 { diff --git a/src/Global.cpp b/src/Global.cpp index 984b56d..96d60e2 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -35,6 +35,7 @@ #include #include #include +#include //CRT #include @@ -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 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 aliases = currentCodec->aliases(); + for(QList::ConstIterator iter = aliases.constBegin(); iter != aliases.constEnd(); iter++) + { + availableCodecs.removeAll(*iter); + } + } + } + } + } + + return codecList; +} + /////////////////////////////////////////////////////////////////////////////// // SELF-TEST ///////////////////////////////////////////////////////////////////////////////