- enhancement: set encoding

This commit is contained in:
royqh1979@gmail.com 2021-09-28 17:17:33 +08:00
parent 7c68fc4f75
commit a4f60e45bf
8 changed files with 318 additions and 223 deletions

View File

@ -260,7 +260,7 @@ QString Compiler::getCharsetArgument(const QByteArray& encoding)
QString result;
if (compilerSet()->autoAddCharsetParams() && encoding != ENCODING_ASCII) {
QString encodingName;
QString systemEncodingName=getDefaultSystemEncoding();
QString systemEncodingName=pCharsetInfoManager->getDefaultSystemEncoding();
if (encoding == ENCODING_SYSTEM_DEFAULT) {
encodingName = systemEncodingName;
} else if (encoding == ENCODING_UTF8_BOM) {

View File

@ -333,16 +333,20 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file)
} else {
QString encodingStr;
if (mProject->options().addCharset) {
QByteArray defaultSystemEncoding = pCharsetInfoManager->getDefaultSystemEncoding();
if (unit->encoding() == ENCODING_AUTO_DETECT) {
if (unit->editor() && unit->editor()->fileEncoding()!=ENCODING_ASCII)
encodingStr = QString(" -finput-charset=%1 -fexec-charset=%2")
.arg(unit->editor()->fileEncoding(),getDefaultSystemEncoding());
.arg(unit->editor()->fileEncoding(),
defaultSystemEncoding);
} else if (unit->encoding()!=ENCODING_ASCII) {
encodingStr = QString(" -finput-charset=%1 -fexec-charset=%2")
.arg(unit->encoding(),getDefaultSystemEncoding());
.arg(unit->encoding(),
defaultSystemEncoding);
} else if (unit->encoding()!=ENCODING_SYSTEM_DEFAULT) {
encodingStr = QString(" -finput-charset=%1 -fexec-charset=%2")
.arg(getDefaultSystemEncoding(),getDefaultSystemEncoding());
.arg(defaultSystemEncoding,
defaultSystemEncoding);
}
}

View File

@ -24,7 +24,7 @@ bool StdinCompiler::prepareForCompile()
fileType = FileType::CppSource;
QString strFileType;
if (!mIsAscii)
mArguments += getCharsetArgument(getDefaultSystemEncoding());
mArguments += getCharsetArgument(pCharsetInfoManager->getDefaultSystemEncoding());
switch(fileType) {
case FileType::CSource:
case FileType::CHeader:

View File

@ -13,6 +13,7 @@
#include "colorscheme.h"
#include "iconsmanager.h"
#include "autolinkmanager.h"
#include "platform.h"
#include "parser/parserutils.h"
QString getSettingFilename(const QString& filepath = QString()) {
@ -75,7 +76,8 @@ int main(int argc, char *argv[])
SystemConsts systemConsts;
pSystemConsts = &systemConsts;
pCharsetInfoManager = new CharsetInfoManager();
auto charsetInfoManager = std::unique_ptr<CharsetInfoManager>(pCharsetInfoManager);
//load settings
pSettings = new Settings(settingFilename);
auto settings = std::unique_ptr<Settings>(pSettings);

View File

@ -5,188 +5,194 @@
#ifdef Q_OS_WIN
#include <windows.h>
#endif
struct CodePageInfo{
int codepage;
QByteArray name;
QByteArray language;
explicit CodePageInfo(int codepage,const QByteArray& name, const QByteArray& language){
this->codepage = codepage;
this->name = name;
this->language = language;
}
};
CharsetInfoManager* pCharsetInfoManager;
using PCodePageInfo = std::shared_ptr<CodePageInfo>;
static QMap<int,PCodePageInfo> CodePages;
static void initCodePages(){
CodePages.insert(37,std::make_shared<CodePageInfo>(37,"IBM037",""));
CodePages.insert(437,std::make_shared<CodePageInfo>(437,"IBM437",""));
CodePages.insert(500,std::make_shared<CodePageInfo>(500,"IBM500",""));
CodePages.insert(708,std::make_shared<CodePageInfo>(708,"ASMO-708",""));
CodePages.insert(709,std::make_shared<CodePageInfo>(709,"",""));
CodePages.insert(710,std::make_shared<CodePageInfo>(710,"",""));
CodePages.insert(720,std::make_shared<CodePageInfo>(720,"DOS-720",""));
CodePages.insert(737,std::make_shared<CodePageInfo>(737,"ibm737",""));
CodePages.insert(775,std::make_shared<CodePageInfo>(775,"ibm775",""));
CodePages.insert(850,std::make_shared<CodePageInfo>(850,"ibm850",""));
CodePages.insert(852,std::make_shared<CodePageInfo>(852,"ibm852",""));
CodePages.insert(855,std::make_shared<CodePageInfo>(855,"IBM855",""));
CodePages.insert(857,std::make_shared<CodePageInfo>(857,"ibm857",""));
CodePages.insert(858,std::make_shared<CodePageInfo>(858,"IBM00858",""));
CodePages.insert(860,std::make_shared<CodePageInfo>(860,"IBM860",""));
CodePages.insert(861,std::make_shared<CodePageInfo>(861,"ibm861",""));
CodePages.insert(862,std::make_shared<CodePageInfo>(862,"DOS-862",""));
CodePages.insert(863,std::make_shared<CodePageInfo>(863,"IBM863",""));
CodePages.insert(864,std::make_shared<CodePageInfo>(864,"IBM864",""));
CodePages.insert(865,std::make_shared<CodePageInfo>(865,"IBM865",""));
CodePages.insert(866,std::make_shared<CodePageInfo>(866,"cp866",""));
CodePages.insert(869,std::make_shared<CodePageInfo>(869,"ibm869",""));
CodePages.insert(870,std::make_shared<CodePageInfo>(870,"IBM870",""));
CodePages.insert(874,std::make_shared<CodePageInfo>(874,"windows-874",""));
CodePages.insert(875,std::make_shared<CodePageInfo>(875,"cp875",""));
CodePages.insert(932,std::make_shared<CodePageInfo>(932,"shift_jis",""));
CodePages.insert(936,std::make_shared<CodePageInfo>(936,"gbk","Chinese"));
CodePages.insert(949,std::make_shared<CodePageInfo>(949,"ks_c_5601-1987",""));
CodePages.insert(950,std::make_shared<CodePageInfo>(950,"big5","Chinese_TC"));
CodePages.insert(1026,std::make_shared<CodePageInfo>(1026,"IBM1026",""));
CodePages.insert(1047,std::make_shared<CodePageInfo>(1047,"IBM01047",""));
CodePages.insert(1140,std::make_shared<CodePageInfo>(1140,"IBM01140",""));
CodePages.insert(1141,std::make_shared<CodePageInfo>(1141,"IBM01141",""));
CodePages.insert(1142,std::make_shared<CodePageInfo>(1142,"IBM01142",""));
CodePages.insert(1143,std::make_shared<CodePageInfo>(1143,"IBM01143",""));
CodePages.insert(1144,std::make_shared<CodePageInfo>(1144,"IBM01144",""));
CodePages.insert(1145,std::make_shared<CodePageInfo>(1145,"IBM01145",""));
CodePages.insert(1146,std::make_shared<CodePageInfo>(1146,"IBM01146",""));
CodePages.insert(1147,std::make_shared<CodePageInfo>(1147,"IBM01147",""));
CodePages.insert(1148,std::make_shared<CodePageInfo>(1148,"IBM01148",""));
CodePages.insert(1149,std::make_shared<CodePageInfo>(1149,"IBM01149",""));
CodePages.insert(1200,std::make_shared<CodePageInfo>(1200,"utf-16",""));
CodePages.insert(1201,std::make_shared<CodePageInfo>(1201,"unicodeFFFE",""));
CodePages.insert(1250,std::make_shared<CodePageInfo>(1250,"windows-1250",""));
CodePages.insert(1251,std::make_shared<CodePageInfo>(1251,"windows-1251",""));
CodePages.insert(1252,std::make_shared<CodePageInfo>(1252,"windows-1252",""));
CodePages.insert(1253,std::make_shared<CodePageInfo>(1253,"windows-1253",""));
CodePages.insert(1254,std::make_shared<CodePageInfo>(1254,"windows-1254",""));
CodePages.insert(1255,std::make_shared<CodePageInfo>(1255,"windows-1255",""));
CodePages.insert(1256,std::make_shared<CodePageInfo>(1256,"windows-1256",""));
CodePages.insert(1257,std::make_shared<CodePageInfo>(1257,"windows-1257",""));
CodePages.insert(1258,std::make_shared<CodePageInfo>(1258,"windows-1258",""));
CodePages.insert(1361,std::make_shared<CodePageInfo>(1361,"Johab",""));
CodePages.insert(10000,std::make_shared<CodePageInfo>(10000,"macintosh",""));
CodePages.insert(10001,std::make_shared<CodePageInfo>(10001,"x-mac-japanese",""));
CodePages.insert(10002,std::make_shared<CodePageInfo>(10002,"x-mac-chinesetrad",""));
CodePages.insert(10003,std::make_shared<CodePageInfo>(10003,"x-mac-korean",""));
CodePages.insert(10004,std::make_shared<CodePageInfo>(10004,"x-mac-arabic",""));
CodePages.insert(10005,std::make_shared<CodePageInfo>(10005,"x-mac-hebrew",""));
CodePages.insert(10006,std::make_shared<CodePageInfo>(10006,"x-mac-greek",""));
CodePages.insert(10007,std::make_shared<CodePageInfo>(10007,"x-mac-cyrillic",""));
CodePages.insert(10008,std::make_shared<CodePageInfo>(10008,"x-mac-chinesesimp",""));
CodePages.insert(10010,std::make_shared<CodePageInfo>(10010,"x-mac-romanian",""));
CodePages.insert(10017,std::make_shared<CodePageInfo>(10017,"x-mac-ukrainian",""));
CodePages.insert(10021,std::make_shared<CodePageInfo>(10021,"x-mac-thai",""));
CodePages.insert(10029,std::make_shared<CodePageInfo>(10029,"x-mac-ce",""));
CodePages.insert(10079,std::make_shared<CodePageInfo>(10079,"x-mac-icelandic",""));
CodePages.insert(10081,std::make_shared<CodePageInfo>(10081,"x-mac-turkish",""));
CodePages.insert(10082,std::make_shared<CodePageInfo>(10082,"x-mac-croatian",""));
CodePages.insert(12000,std::make_shared<CodePageInfo>(12000,"utf-32",""));
CodePages.insert(12001,std::make_shared<CodePageInfo>(12001,"utf-32BE",""));
CodePages.insert(20000,std::make_shared<CodePageInfo>(20000,"x-Chinese_CNS",""));
CodePages.insert(20001,std::make_shared<CodePageInfo>(20001,"x-cp20001",""));
CodePages.insert(20002,std::make_shared<CodePageInfo>(20002,"x_Chinese-Eten",""));
CodePages.insert(20003,std::make_shared<CodePageInfo>(20003,"x-cp20003",""));
CodePages.insert(20004,std::make_shared<CodePageInfo>(20004,"x-cp20004",""));
CodePages.insert(20005,std::make_shared<CodePageInfo>(20005,"x-cp20005",""));
CodePages.insert(20105,std::make_shared<CodePageInfo>(20105,"x-IA5",""));
CodePages.insert(20106,std::make_shared<CodePageInfo>(20106,"x-IA5-German",""));
CodePages.insert(20107,std::make_shared<CodePageInfo>(20107,"x-IA5-Swedish",""));
CodePages.insert(20108,std::make_shared<CodePageInfo>(20108,"x-IA5-Norwegian",""));
CodePages.insert(20127,std::make_shared<CodePageInfo>(20127,"us-ascii",""));
CodePages.insert(20261,std::make_shared<CodePageInfo>(20261,"x-cp20261",""));
CodePages.insert(20269,std::make_shared<CodePageInfo>(20269,"x-cp20269",""));
CodePages.insert(20273,std::make_shared<CodePageInfo>(20273,"IBM273",""));
CodePages.insert(20277,std::make_shared<CodePageInfo>(20277,"IBM277",""));
CodePages.insert(20278,std::make_shared<CodePageInfo>(20278,"IBM278",""));
CodePages.insert(20280,std::make_shared<CodePageInfo>(20280,"IBM280",""));
CodePages.insert(20284,std::make_shared<CodePageInfo>(20284,"IBM284",""));
CodePages.insert(20285,std::make_shared<CodePageInfo>(20285,"IBM285",""));
CodePages.insert(20290,std::make_shared<CodePageInfo>(20290,"IBM290",""));
CodePages.insert(20297,std::make_shared<CodePageInfo>(20297,"IBM297",""));
CodePages.insert(20420,std::make_shared<CodePageInfo>(20420,"IBM420",""));
CodePages.insert(20423,std::make_shared<CodePageInfo>(20423,"IBM423",""));
CodePages.insert(20424,std::make_shared<CodePageInfo>(20424,"IBM424",""));
CodePages.insert(20833,std::make_shared<CodePageInfo>(20833,"x-EBCDIC-KoreanExtended",""));
CodePages.insert(20838,std::make_shared<CodePageInfo>(20838,"IBM-Thai",""));
CodePages.insert(20866,std::make_shared<CodePageInfo>(20866,"koi8-r",""));
CodePages.insert(20871,std::make_shared<CodePageInfo>(20871,"IBM871",""));
CodePages.insert(20880,std::make_shared<CodePageInfo>(20880,"IBM880",""));
CodePages.insert(20905,std::make_shared<CodePageInfo>(20905,"IBM905",""));
CodePages.insert(20924,std::make_shared<CodePageInfo>(20924,"IBM00924",""));
CodePages.insert(20932,std::make_shared<CodePageInfo>(20932,"EUC-JP",""));
CodePages.insert(20936,std::make_shared<CodePageInfo>(20936,"x-cp20936",""));
CodePages.insert(20949,std::make_shared<CodePageInfo>(20949,"x-cp20949",""));
CodePages.insert(21025,std::make_shared<CodePageInfo>(21025,"cp1025",""));
CodePages.insert(21027,std::make_shared<CodePageInfo>(21027,"",""));
CodePages.insert(21866,std::make_shared<CodePageInfo>(21866,"koi8-u",""));
CodePages.insert(28591,std::make_shared<CodePageInfo>(28591,"iso-8859-1",""));
CodePages.insert(28592,std::make_shared<CodePageInfo>(28592,"iso-8859-2",""));
CodePages.insert(28593,std::make_shared<CodePageInfo>(28593,"iso-8859-3",""));
CodePages.insert(28594,std::make_shared<CodePageInfo>(28594,"iso-8859-4",""));
CodePages.insert(28595,std::make_shared<CodePageInfo>(28595,"iso-8859-5",""));
CodePages.insert(28596,std::make_shared<CodePageInfo>(28596,"iso-8859-6",""));
CodePages.insert(28597,std::make_shared<CodePageInfo>(28597,"iso-8859-7",""));
CodePages.insert(28598,std::make_shared<CodePageInfo>(28598,"iso-8859-8",""));
CodePages.insert(28599,std::make_shared<CodePageInfo>(28599,"iso-8859-9",""));
CodePages.insert(28603,std::make_shared<CodePageInfo>(28603,"iso-8859-13",""));
CodePages.insert(28605,std::make_shared<CodePageInfo>(28605,"iso-8859-15",""));
CodePages.insert(29001,std::make_shared<CodePageInfo>(29001,"x-Europa",""));
CodePages.insert(38598,std::make_shared<CodePageInfo>(38598,"iso-8859-8-i",""));
CodePages.insert(50220,std::make_shared<CodePageInfo>(50220,"iso-2022-jp",""));
CodePages.insert(50221,std::make_shared<CodePageInfo>(50221,"csISO2022JP",""));
CodePages.insert(50222,std::make_shared<CodePageInfo>(50222,"iso-2022-jp",""));
CodePages.insert(50225,std::make_shared<CodePageInfo>(50225,"iso-2022-kr",""));
CodePages.insert(50227,std::make_shared<CodePageInfo>(50227,"x-cp50227",""));
CodePages.insert(50229,std::make_shared<CodePageInfo>(50229,"",""));
CodePages.insert(50930,std::make_shared<CodePageInfo>(50930,"",""));
CodePages.insert(50931,std::make_shared<CodePageInfo>(50931,"",""));
CodePages.insert(50933,std::make_shared<CodePageInfo>(50933,"",""));
CodePages.insert(50935,std::make_shared<CodePageInfo>(50935,"",""));
CodePages.insert(50936,std::make_shared<CodePageInfo>(50936,"",""));
CodePages.insert(50937,std::make_shared<CodePageInfo>(50937,"",""));
CodePages.insert(50939,std::make_shared<CodePageInfo>(50939,"",""));
CodePages.insert(51932,std::make_shared<CodePageInfo>(51932,"euc-jp",""));
CodePages.insert(51936,std::make_shared<CodePageInfo>(51936,"euc-cn",""));
CodePages.insert(51949,std::make_shared<CodePageInfo>(51949,"euc-kr",""));
CodePages.insert(51950,std::make_shared<CodePageInfo>(51950,"",""));
CodePages.insert(52936,std::make_shared<CodePageInfo>(52936,"hz-gb-2312",""));
CodePages.insert(54936,std::make_shared<CodePageInfo>(54936,"gb18030",""));
CodePages.insert(57002,std::make_shared<CodePageInfo>(57002,"x-iscii-de",""));
CodePages.insert(57003,std::make_shared<CodePageInfo>(57003,"x-iscii-be",""));
CodePages.insert(57004,std::make_shared<CodePageInfo>(57004,"x-iscii-ta",""));
CodePages.insert(57005,std::make_shared<CodePageInfo>(57005,"x-iscii-te",""));
CodePages.insert(57006,std::make_shared<CodePageInfo>(57006,"x-iscii-as",""));
CodePages.insert(57007,std::make_shared<CodePageInfo>(57007,"x-iscii-or",""));
CodePages.insert(57008,std::make_shared<CodePageInfo>(57008,"x-iscii-ka",""));
CodePages.insert(57009,std::make_shared<CodePageInfo>(57009,"x-iscii-ma",""));
CodePages.insert(57010,std::make_shared<CodePageInfo>(57010,"x-iscii-gu",""));
CodePages.insert(57011,std::make_shared<CodePageInfo>(57011,"x-iscii-pa",""));
CodePages.insert(65000,std::make_shared<CodePageInfo>(65000,"utf-7",""));
CodePages.insert(65001,std::make_shared<CodePageInfo>(65001,"utf-8",""));
static void initmCodePages(){
}
QByteArray getDefaultSystemEncoding()
QByteArray CharsetInfoManager::getDefaultSystemEncoding()
{
if (CodePages.isEmpty())
initCodePages();
DWORD acp = GetACP();
PCodePageInfo info = CodePages.value(acp,PCodePageInfo());
PCharsetInfo info = findCharsetByCodepage(acp);
if (info) {
return info->name;
}
return "unknown";
}
#endif
PCharsetInfo CharsetInfoManager::findCharsetByCodepage(int codepage)
{
foreach (const PCharsetInfo& info, mCodePages) {
if (info->codepage == codepage)
return info;
}
return PCharsetInfo();
}
CharsetInfoManager::CharsetInfoManager():QObject()
{
mCodePages.insert(37,std::make_shared<CharsetInfo>(37,"IBM037","",false));
mCodePages.insert(437,std::make_shared<CharsetInfo>(437,"IBM437","",false));
mCodePages.insert(500,std::make_shared<CharsetInfo>(500,"IBM500","",false));
mCodePages.insert(708,std::make_shared<CharsetInfo>(708,"ASMO-708","",false));
mCodePages.insert(709,std::make_shared<CharsetInfo>(709,"","",false));
mCodePages.insert(710,std::make_shared<CharsetInfo>(710,"","",false));
mCodePages.insert(720,std::make_shared<CharsetInfo>(720,"DOS-720",tr("Arabic"),false));
mCodePages.insert(737,std::make_shared<CharsetInfo>(737,"ibm737",tr("Greek"),false));
mCodePages.insert(775,std::make_shared<CharsetInfo>(775,"ibm775",tr("Baltic"),false));
mCodePages.insert(850,std::make_shared<CharsetInfo>(850,"ibm850",tr("Western Europe"),false));
mCodePages.insert(852,std::make_shared<CharsetInfo>(852,"ibm852",tr("Central Europe"),false));
mCodePages.insert(855,std::make_shared<CharsetInfo>(855,"IBM855",tr("Cyrillic"),false));
mCodePages.insert(857,std::make_shared<CharsetInfo>(857,"ibm857",tr("Turkish"),false));
mCodePages.insert(858,std::make_shared<CharsetInfo>(858,"ibm858",tr("Western Europe"),false));
mCodePages.insert(860,std::make_shared<CharsetInfo>(860,"IBM860",tr("Western Europe"),false));
mCodePages.insert(861,std::make_shared<CharsetInfo>(861,"ibm861",tr("Northern Europe"),false));
mCodePages.insert(862,std::make_shared<CharsetInfo>(862,"DOS-862",tr("Hebrew"),false));
mCodePages.insert(863,std::make_shared<CharsetInfo>(863,"IBM863",tr("Western Europe"),false));
mCodePages.insert(864,std::make_shared<CharsetInfo>(864,"IBM864","",false));
mCodePages.insert(865,std::make_shared<CharsetInfo>(865,"IBM865",tr("Northern Europe"),false));
mCodePages.insert(866,std::make_shared<CharsetInfo>(866,"cp866",tr("Cyrillic"),false));
mCodePages.insert(869,std::make_shared<CharsetInfo>(869,"ibm869",tr("Greek"),false));
mCodePages.insert(870,std::make_shared<CharsetInfo>(870,"IBM870","",false));
mCodePages.insert(874,std::make_shared<CharsetInfo>(874,"tis-620",tr("Thai"),true));
mCodePages.insert(875,std::make_shared<CharsetInfo>(875,"cp875","",false));
mCodePages.insert(932,std::make_shared<CharsetInfo>(932,"shift_jis",tr("Japanese"),true));
mCodePages.insert(936,std::make_shared<CharsetInfo>(936,"gbk",tr("Chinese"),true));
mCodePages.insert(949,std::make_shared<CharsetInfo>(949,"windows-949",tr("Korean"),true));
mCodePages.insert(950,std::make_shared<CharsetInfo>(950,"big5",tr("Chinese"),true));
mCodePages.insert(1026,std::make_shared<CharsetInfo>(1026,"IBM1026","",false));
mCodePages.insert(1047,std::make_shared<CharsetInfo>(1047,"IBM01047","",false));
mCodePages.insert(1140,std::make_shared<CharsetInfo>(1140,"IBM01140","",false));
mCodePages.insert(1141,std::make_shared<CharsetInfo>(1141,"IBM01141","",false));
mCodePages.insert(1142,std::make_shared<CharsetInfo>(1142,"IBM01142","",false));
mCodePages.insert(1143,std::make_shared<CharsetInfo>(1143,"IBM01143","",false));
mCodePages.insert(1144,std::make_shared<CharsetInfo>(1144,"IBM01144","",false));
mCodePages.insert(1145,std::make_shared<CharsetInfo>(1145,"IBM01145","",false));
mCodePages.insert(1146,std::make_shared<CharsetInfo>(1146,"IBM01146","",false));
mCodePages.insert(1147,std::make_shared<CharsetInfo>(1147,"IBM01147","",false));
mCodePages.insert(1148,std::make_shared<CharsetInfo>(1148,"IBM01148","",false));
mCodePages.insert(1149,std::make_shared<CharsetInfo>(1149,"IBM01149","",false));
mCodePages.insert(1200,std::make_shared<CharsetInfo>(1200,"utf-16","",false));
mCodePages.insert(1201,std::make_shared<CharsetInfo>(1201,"unicodeFFFE","",false));
mCodePages.insert(1250,std::make_shared<CharsetInfo>(1250,"windows-1250",tr("Central Europe"),true));
mCodePages.insert(1251,std::make_shared<CharsetInfo>(1251,"windows-1251",tr("Cyrillic"),true));
mCodePages.insert(1252,std::make_shared<CharsetInfo>(1252,"windows-1252",tr("Western Europe"),true));
mCodePages.insert(1253,std::make_shared<CharsetInfo>(1253,"windows-1253",tr("Greek"),true));
mCodePages.insert(1254,std::make_shared<CharsetInfo>(1254,"windows-1254",tr("Turkish"),true));
mCodePages.insert(1255,std::make_shared<CharsetInfo>(1255,"windows-1255",tr("Hebrew"),true));
mCodePages.insert(1256,std::make_shared<CharsetInfo>(1256,"windows-1256",tr("Arabic"),true));
mCodePages.insert(1257,std::make_shared<CharsetInfo>(1257,"windows-1257",tr("Baltic"),true));
mCodePages.insert(1258,std::make_shared<CharsetInfo>(1258,"windows-1258",tr("Vietnamese"),true));
mCodePages.insert(1361,std::make_shared<CharsetInfo>(1361,"Johab","",false));
mCodePages.insert(10000,std::make_shared<CharsetInfo>(10000,"macintosh",tr("Cyrillic"),true));
mCodePages.insert(10001,std::make_shared<CharsetInfo>(10001,"x-mac-japanese","",false));
mCodePages.insert(10002,std::make_shared<CharsetInfo>(10002,"x-mac-chinesetrad","",false));
mCodePages.insert(10003,std::make_shared<CharsetInfo>(10003,"x-mac-korean","",false));
mCodePages.insert(10004,std::make_shared<CharsetInfo>(10004,"x-mac-arabic","",false));
mCodePages.insert(10005,std::make_shared<CharsetInfo>(10005,"x-mac-hebrew","",false));
mCodePages.insert(10006,std::make_shared<CharsetInfo>(10006,"x-mac-greek","",false));
mCodePages.insert(10007,std::make_shared<CharsetInfo>(10007,"x-mac-cyrillic","",false));
mCodePages.insert(10008,std::make_shared<CharsetInfo>(10008,"x-mac-chinesesimp","",false));
mCodePages.insert(10010,std::make_shared<CharsetInfo>(10010,"x-mac-romanian","",false));
mCodePages.insert(10017,std::make_shared<CharsetInfo>(10017,"x-mac-ukrainian","",false));
mCodePages.insert(10021,std::make_shared<CharsetInfo>(10021,"x-mac-thai","",false));
mCodePages.insert(10029,std::make_shared<CharsetInfo>(10029,"x-mac-ce","",false));
mCodePages.insert(10079,std::make_shared<CharsetInfo>(10079,"x-mac-icelandic","",false));
mCodePages.insert(10081,std::make_shared<CharsetInfo>(10081,"x-mac-turkish","",false));
mCodePages.insert(10082,std::make_shared<CharsetInfo>(10082,"x-mac-croatian","",false));
mCodePages.insert(12000,std::make_shared<CharsetInfo>(12000,"utf-32","",false));
mCodePages.insert(12001,std::make_shared<CharsetInfo>(12001,"utf-32BE","",false));
mCodePages.insert(20000,std::make_shared<CharsetInfo>(20000,"x-Chinese_CNS","",false));
mCodePages.insert(20001,std::make_shared<CharsetInfo>(20001,"x-cp20001","",false));
mCodePages.insert(20002,std::make_shared<CharsetInfo>(20002,"x_Chinese-Eten","",false));
mCodePages.insert(20003,std::make_shared<CharsetInfo>(20003,"x-cp20003","",false));
mCodePages.insert(20004,std::make_shared<CharsetInfo>(20004,"x-cp20004","",false));
mCodePages.insert(20005,std::make_shared<CharsetInfo>(20005,"x-cp20005","",false));
mCodePages.insert(20105,std::make_shared<CharsetInfo>(20105,"x-IA5","",false));
mCodePages.insert(20106,std::make_shared<CharsetInfo>(20106,"x-IA5-German","",false));
mCodePages.insert(20107,std::make_shared<CharsetInfo>(20107,"x-IA5-Swedish","",false));
mCodePages.insert(20108,std::make_shared<CharsetInfo>(20108,"x-IA5-Norwegian","",false));
mCodePages.insert(20127,std::make_shared<CharsetInfo>(20127,"us-ascii","",false));
mCodePages.insert(20261,std::make_shared<CharsetInfo>(20261,"x-cp20261","",false));
mCodePages.insert(20269,std::make_shared<CharsetInfo>(20269,"x-cp20269","",false));
mCodePages.insert(20273,std::make_shared<CharsetInfo>(20273,"IBM273","",false));
mCodePages.insert(20277,std::make_shared<CharsetInfo>(20277,"IBM277","",false));
mCodePages.insert(20278,std::make_shared<CharsetInfo>(20278,"IBM278","",false));
mCodePages.insert(20280,std::make_shared<CharsetInfo>(20280,"IBM280","",false));
mCodePages.insert(20284,std::make_shared<CharsetInfo>(20284,"IBM284","",false));
mCodePages.insert(20285,std::make_shared<CharsetInfo>(20285,"IBM285","",false));
mCodePages.insert(20290,std::make_shared<CharsetInfo>(20290,"IBM290","",false));
mCodePages.insert(20297,std::make_shared<CharsetInfo>(20297,"IBM297","",false));
mCodePages.insert(20420,std::make_shared<CharsetInfo>(20420,"IBM420","",false));
mCodePages.insert(20423,std::make_shared<CharsetInfo>(20423,"IBM423","",false));
mCodePages.insert(20424,std::make_shared<CharsetInfo>(20424,"IBM424","",false));
mCodePages.insert(20833,std::make_shared<CharsetInfo>(20833,"x-EBCDIC-KoreanExtended","",false));
mCodePages.insert(20838,std::make_shared<CharsetInfo>(20838,"IBM-Thai","",false));
mCodePages.insert(20866,std::make_shared<CharsetInfo>(20866,"koi8-r",tr("Cyrillic"),true));
mCodePages.insert(20871,std::make_shared<CharsetInfo>(20871,"IBM871","",false));
mCodePages.insert(20880,std::make_shared<CharsetInfo>(20880,"IBM880","",false));
mCodePages.insert(20905,std::make_shared<CharsetInfo>(20905,"IBM905","",false));
mCodePages.insert(20924,std::make_shared<CharsetInfo>(20924,"IBM00924","",false));
mCodePages.insert(20932,std::make_shared<CharsetInfo>(20932,"EUC-JP","",false));
mCodePages.insert(20936,std::make_shared<CharsetInfo>(20936,"x-cp20936","",false));
mCodePages.insert(20949,std::make_shared<CharsetInfo>(20949,"x-cp20949","",false));
mCodePages.insert(21025,std::make_shared<CharsetInfo>(21025,"cp1025","",false));
mCodePages.insert(21027,std::make_shared<CharsetInfo>(21027,"","",false));
mCodePages.insert(21866,std::make_shared<CharsetInfo>(21866,"koi8-u",tr("Cyrillic"),true));
mCodePages.insert(28591,std::make_shared<CharsetInfo>(28591,"iso-8859-1",tr("Western Europe"),true));
mCodePages.insert(28592,std::make_shared<CharsetInfo>(28592,"iso-8859-2",tr("Eastern Europe"),true));
mCodePages.insert(28593,std::make_shared<CharsetInfo>(28593,"iso-8859-3",tr("Turkish"),true));
mCodePages.insert(28594,std::make_shared<CharsetInfo>(28594,"iso-8859-4",tr("Baltic"),true));
mCodePages.insert(28595,std::make_shared<CharsetInfo>(28595,"iso-8859-5",tr("Cyrillic"),true));
mCodePages.insert(28596,std::make_shared<CharsetInfo>(28596,"iso-8859-6",tr("Arabic"),true));
mCodePages.insert(28597,std::make_shared<CharsetInfo>(28597,"iso-8859-7",tr("Greek"),true));
mCodePages.insert(28598,std::make_shared<CharsetInfo>(28598,"iso-8859-8",tr("Hebrew"),true));
mCodePages.insert(28599,std::make_shared<CharsetInfo>(28599,"iso-8859-9",tr("Turkish"),true));
mCodePages.insert(28603,std::make_shared<CharsetInfo>(28603,"iso-8859-13",tr("Baltic"),true));
mCodePages.insert(-1,std::make_shared<CharsetInfo>(28605,"iso-8859-14",tr("Celtic"),true));
mCodePages.insert(28605,std::make_shared<CharsetInfo>(28605,"iso-8859-15",tr("Western Europe"),true));
mCodePages.insert(29001,std::make_shared<CharsetInfo>(29001,"x-Europa","",false));
mCodePages.insert(38598,std::make_shared<CharsetInfo>(38598,"iso-8859-8-i","",false));
mCodePages.insert(50220,std::make_shared<CharsetInfo>(50220,"iso-2022-jp","",false));
mCodePages.insert(50221,std::make_shared<CharsetInfo>(50221,"csISO2022JP","",false));
mCodePages.insert(50222,std::make_shared<CharsetInfo>(50222,"iso-2022-jp","",false));
mCodePages.insert(50225,std::make_shared<CharsetInfo>(50225,"iso-2022-kr","",false));
mCodePages.insert(50227,std::make_shared<CharsetInfo>(50227,"x-cp50227","",false));
mCodePages.insert(50229,std::make_shared<CharsetInfo>(50229,"","",false));
mCodePages.insert(50930,std::make_shared<CharsetInfo>(50930,"","",false));
mCodePages.insert(50931,std::make_shared<CharsetInfo>(50931,"","",false));
mCodePages.insert(50933,std::make_shared<CharsetInfo>(50933,"","",false));
mCodePages.insert(50935,std::make_shared<CharsetInfo>(50935,"","",false));
mCodePages.insert(50936,std::make_shared<CharsetInfo>(50936,"","",false));
mCodePages.insert(50937,std::make_shared<CharsetInfo>(50937,"","",false));
mCodePages.insert(50939,std::make_shared<CharsetInfo>(50939,"","",false));
mCodePages.insert(51932,std::make_shared<CharsetInfo>(51932,"euc-jp",tr("Japanese"),true));
mCodePages.insert(51936,std::make_shared<CharsetInfo>(51936,"euc-cn","",false));
mCodePages.insert(51949,std::make_shared<CharsetInfo>(51949,"euc-kr",tr("Korean"),true));
mCodePages.insert(51950,std::make_shared<CharsetInfo>(51950,"","",false));
mCodePages.insert(52936,std::make_shared<CharsetInfo>(52936,"hz-gb-2312","",false));
mCodePages.insert(54936,std::make_shared<CharsetInfo>(54936,"gb18030",tr("Chinese"),true));
mCodePages.insert(57002,std::make_shared<CharsetInfo>(57002,"x-iscii-de","",false));
mCodePages.insert(57003,std::make_shared<CharsetInfo>(57003,"x-iscii-be","",false));
mCodePages.insert(57004,std::make_shared<CharsetInfo>(57004,"x-iscii-ta","",false));
mCodePages.insert(57005,std::make_shared<CharsetInfo>(57005,"x-iscii-te","",false));
mCodePages.insert(57006,std::make_shared<CharsetInfo>(57006,"x-iscii-as","",false));
mCodePages.insert(57007,std::make_shared<CharsetInfo>(57007,"x-iscii-or","",false));
mCodePages.insert(57008,std::make_shared<CharsetInfo>(57008,"x-iscii-ka","",false));
mCodePages.insert(57009,std::make_shared<CharsetInfo>(57009,"x-iscii-ma","",false));
mCodePages.insert(57010,std::make_shared<CharsetInfo>(57010,"x-iscii-gu","",false));
mCodePages.insert(57011,std::make_shared<CharsetInfo>(57011,"x-iscii-pa","",false));
mCodePages.insert(65000,std::make_shared<CharsetInfo>(65000,"utf-7","",false));
mCodePages.insert(65001,std::make_shared<CharsetInfo>(65001,"utf-8","",false));
}
CharsetInfo::CharsetInfo(int codepage, const QByteArray &name, const QString &language, bool enabled)
{
this->codepage = codepage;
this->name = name;
this->language = language;
this->enabled = enabled;
}

View File

@ -2,6 +2,36 @@
#define PLATFORM_H
#include <QByteArray>
#include <QString>
#include <memory>
#include <QObject>
struct CharsetInfo{
int codepage;
QByteArray name;
QString language;
bool enabled;
explicit CharsetInfo(int codepage,
const QByteArray& name,
const QString& language,
bool enabled);
};
using PCharsetInfo = std::shared_ptr<CharsetInfo>;
class CharsetInfoManager: public QObject {
Q_OBJECT;
public:
explicit CharsetInfoManager();
QByteArray getDefaultSystemEncoding();
PCharsetInfo findCharsetByCodepage(int codepage);
QStringList languageNames();
QList<PCharsetInfo> findCharsetsByLanguageName(const QString& languageName);
private:
static QList<PCharsetInfo> mCodePages;
};
using PCharsetInfoManager = std::shared_ptr<CharsetInfo>;
extern CharsetInfoManager* pCharsetInfoManager;
QByteArray getDefaultSystemEncoding();
#endif // PLATFORM_H

View File

@ -15,7 +15,7 @@ SynExporter::SynExporter()
mForegroundColor = QGuiApplication::palette().color(QPalette::Text);
mUseBackground = false;
mExportAsText = false;
mCharset = getDefaultSystemEncoding();
mCharset = pCharsetInfoManager->getDefaultSystemEncoding();
mFileEndingType = FileEndingType::Windows;
clear();
setTitle("");

View File

@ -40,35 +40,49 @@
<property name="title">
<string>File Options</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="3">
<widget class="QCheckBox" name="chkLink">
<property name="text">
<string>Include in linking</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Build Priority:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinPriority"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Build Priority:</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<item>
<widget class="QCheckBox" name="chkCompile">
<property name="enabled">
<bool>true</bool>
@ -78,36 +92,75 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<item>
<widget class="QCheckBox" name="chkLink">
<property name="text">
<string>Include in linking</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkCompileAsCPP">
<property name="text">
<string>Compile files as C++</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Encoding</string>
</property>
<item>
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Encoding</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbEncoding">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinPriority"/>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="cbEncoding"/>
</item>
<item row="6" column="0" colspan="3">
<widget class="QPlainTextEdit" name="txtBuildCommand"/>
</item>
<item row="5" column="0" colspan="3">
<item>
<widget class="QCheckBox" name="chkOverrideBuildCommand">
<property name="text">
<string>Override build command:</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="txtBuildCommand"/>
</item>
</layout>
</widget>
</widget>