Browse Source

Code improvement for EncodingMapper

pull/6046/head
Don HO 5 years ago
parent
commit
48f83a9d0f
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
  1. 4
      PowerEditor/src/EncodingMapper.h
  2. 16
      PowerEditor/src/Notepad_plus.cpp
  3. 4
      PowerEditor/src/NppCommands.cpp
  4. 2
      PowerEditor/src/ScitillaComponent/Buffer.cpp
  5. 4
      PowerEditor/src/WinControls/Preference/preferenceDlg.cpp
  6. 4
      PowerEditor/src/localization.cpp

4
PowerEditor/src/EncodingMapper.h

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

16
PowerEditor/src/Notepad_plus.cpp

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

4
PowerEditor/src/NppCommands.cpp

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

2
PowerEditor/src/ScitillaComponent/Buffer.cpp

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

4
PowerEditor/src/WinControls/Preference/preferenceDlg.cpp

@ -1195,10 +1195,10 @@ INT_PTR CALLBACK DefaultNewDocDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR
int selIndex = -1;
generic_string str;
EncodingMapper* em = EncodingMapper::getInstance();
EncodingMapper& em = EncodingMapper::getInstance();
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)
{
cmdID += IDM_FORMAT_ENCODE;

4
PowerEditor/src/localization.cpp

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

Loading…
Cancel
Save