Code improvement for EncodingMapper

This commit is contained in:
Don HO 2019-08-14 01:15:08 +02:00
parent f80b0ed293
commit 48f83a9d0f
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
6 changed files with 17 additions and 17 deletions

View File

@ -35,9 +35,9 @@ struct EncodingUnit {
class EncodingMapper { class EncodingMapper {
public: public:
static EncodingMapper* getInstance() { static EncodingMapper& getInstance() {
static EncodingMapper instance; static EncodingMapper instance;
return &instance; return instance;
} }
int getEncodingFromIndex(int index) const; int getEncodingFromIndex(int index) const;
int getIndexFromEncoding(int encoding) const; int getIndexFromEncoding(int encoding) const;

View File

@ -1017,8 +1017,8 @@ int Notepad_plus::getHtmlXmlEncoding(const TCHAR *fileName) const
char encodingStr[encodingStrLen]; char encodingStr[encodingStrLen];
_invisibleEditView.getText(encodingStr, startPos, endPos); _invisibleEditView.getText(encodingStr, startPos, endPos);
EncodingMapper *em = EncodingMapper::getInstance(); EncodingMapper& em = EncodingMapper::getInstance();
int enc = em->getEncodingFromString(encodingStr); int enc = em.getEncodingFromString(encodingStr);
return (enc == CP_ACP ? -1 : enc); return (enc == CP_ACP ? -1 : enc);
} }
return -1; return -1;
@ -1061,8 +1061,8 @@ int Notepad_plus::getHtmlXmlEncoding(const TCHAR *fileName) const
char encodingStr[encodingStrLen]; char encodingStr[encodingStrLen];
_invisibleEditView.getText(encodingStr, startPos, endPos); _invisibleEditView.getText(encodingStr, startPos, endPos);
EncodingMapper *em = EncodingMapper::getInstance(); EncodingMapper& em = EncodingMapper::getInstance();
int enc = em->getEncodingFromString(encodingStr); int enc = em.getEncodingFromString(encodingStr);
return (enc == CP_ACP ? -1 : enc); return (enc == CP_ACP ? -1 : enc);
} }
} }
@ -2391,8 +2391,8 @@ void Notepad_plus::setUniModeText()
} }
else else
{ {
EncodingMapper *em = EncodingMapper::getInstance(); EncodingMapper& em = EncodingMapper::getInstance();
int cmdID = em->getIndexFromEncoding(encoding); int cmdID = em.getIndexFromEncoding(encoding);
if (cmdID == -1) if (cmdID == -1)
{ {
//printStr(TEXT("Encoding problem. Encoding is not added in encoding_table?")); //printStr(TEXT("Encoding problem. Encoding is not added in encoding_table?"));
@ -3926,8 +3926,8 @@ void Notepad_plus::checkUnicodeMenuItems() const
} }
else else
{ {
EncodingMapper *em = EncodingMapper::getInstance(); EncodingMapper& em = EncodingMapper::getInstance();
int cmdID = em->getIndexFromEncoding(encoding); int cmdID = em.getIndexFromEncoding(encoding);
if (cmdID == -1) if (cmdID == -1)
{ {
//printStr(TEXT("Encoding problem. Encoding is not added in encoding_table?")); //printStr(TEXT("Encoding problem. Encoding is not added in encoding_table?"));

View File

@ -2300,8 +2300,8 @@ void Notepad_plus::command(int id)
{ {
int index = id - IDM_FORMAT_ENCODE; int index = id - IDM_FORMAT_ENCODE;
EncodingMapper *em = EncodingMapper::getInstance(); EncodingMapper& em = EncodingMapper::getInstance();
int encoding = em->getEncodingFromIndex(index); int encoding = em.getEncodingFromIndex(index);
if (encoding == -1) if (encoding == -1)
{ {
//printStr(TEXT("Encoding problem. Command is not added in encoding_table?")); //printStr(TEXT("Encoding problem. Command is not added in encoding_table?"));

View File

@ -1168,7 +1168,7 @@ int FileManager::detectCodepage(char* buf, size_t len)
uchardet_handle_data(ud, buf, len); uchardet_handle_data(ud, buf, len);
uchardet_data_end(ud); uchardet_data_end(ud);
const char* cs = uchardet_get_charset(ud); const char* cs = uchardet_get_charset(ud);
int codepage = EncodingMapper::getInstance()->getEncodingFromString(cs); int codepage = EncodingMapper::getInstance().getEncodingFromString(cs);
uchardet_delete(ud); uchardet_delete(ud);
return codepage; return codepage;
} }

View File

@ -1195,10 +1195,10 @@ INT_PTR CALLBACK DefaultNewDocDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR
int selIndex = -1; int selIndex = -1;
generic_string str; generic_string str;
EncodingMapper* em = EncodingMapper::getInstance(); EncodingMapper& em = EncodingMapper::getInstance();
for (size_t i = 0, encodingArraySize = sizeof(encodings)/sizeof(int) ; i < encodingArraySize ; ++i) for (size_t i = 0, encodingArraySize = sizeof(encodings)/sizeof(int) ; i < encodingArraySize ; ++i)
{ {
int cmdID = em->getIndexFromEncoding(encodings[i]); int cmdID = em.getIndexFromEncoding(encodings[i]);
if (cmdID != -1) if (cmdID != -1)
{ {
cmdID += IDM_FORMAT_ENCODE; cmdID += IDM_FORMAT_ENCODE;

View File

@ -135,8 +135,8 @@ void NativeLangSpeaker::init(TiXmlDocumentA *nativeLangDocRootA, bool loadIfEngl
if (declaration) if (declaration)
{ {
const char * encodingStr = declaration->Encoding(); const char * encodingStr = declaration->Encoding();
EncodingMapper *em = EncodingMapper::getInstance(); EncodingMapper& em = EncodingMapper::getInstance();
int enc = em->getEncodingFromString(encodingStr); int enc = em.getEncodingFromString(encodingStr);
_nativeLangEncoding = (enc != -1)?enc:CP_ACP; _nativeLangEncoding = (enc != -1)?enc:CP_ACP;
} }
} }