Code simplification

This commit is contained in:
Damien GERARD 2015-08-14 23:32:23 +02:00
parent 9c857ed811
commit f2bb34ccb2
10 changed files with 393 additions and 401 deletions

View File

@ -96,7 +96,7 @@ char getDriveLetter()
generic_string relativeFilePathToFullFilePath(const TCHAR *relativeFilePath) generic_string relativeFilePathToFullFilePath(const TCHAR *relativeFilePath)
{ {
generic_string fullFilePathName = TEXT(""); generic_string fullFilePathName;
TCHAR fullFileName[MAX_PATH]; TCHAR fullFileName[MAX_PATH];
BOOL isRelative = ::PathIsRelative(relativeFilePath); BOOL isRelative = ::PathIsRelative(relativeFilePath);
@ -203,8 +203,9 @@ void folderBrowser(HWND parent, int outputCtrlID, const TCHAR *defaultStr)
generic_string getFolderName(HWND parent, const TCHAR *defaultDir) generic_string getFolderName(HWND parent, const TCHAR *defaultDir)
{ {
generic_string folderName(TEXT("")); generic_string folderName;
LPMALLOC pShellMalloc = 0; LPMALLOC pShellMalloc = 0;
if (::SHGetMalloc(&pShellMalloc) == NO_ERROR) if (::SHGetMalloc(&pShellMalloc) == NO_ERROR)
{ {
BROWSEINFO info; BROWSEINFO info;

View File

@ -483,7 +483,7 @@ static const ScintillaKeyDefinition scintKeyDefs[] =
}; };
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
@ -533,6 +533,92 @@ namespace // anonymous namespace
return -1; return -1;
} }
static inline size_t getAsciiLenFromBase64Len(size_t base64StrLen)
{
return (base64StrLen % 4) ? 0 : (base64StrLen - base64StrLen / 4);
}
static int base64ToAscii(char *dest, const char *base64Str)
{
static const int base64IndexArray[123] =
{
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 62, -1, -1, -1, 63,
52, 53, 54, 55 ,56, 57, 58, 59,
60, 61, -1, -1, -1, -1, -1, -1,
-1, 0, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, -1, -1, -1, -1 ,-1,
-1, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51
};
size_t b64StrLen = strlen(base64Str);
size_t nbLoop = b64StrLen / 4;
size_t i = 0;
int k = 0;
enum {b64_just, b64_1padded, b64_2padded} padd = b64_just;
for ( ; i < nbLoop ; i++)
{
size_t j = i * 4;
UCHAR uc0, uc1, uc2, uc3, p0, p1;
uc0 = (UCHAR)base64IndexArray[base64Str[j]];
uc1 = (UCHAR)base64IndexArray[base64Str[j+1]];
uc2 = (UCHAR)base64IndexArray[base64Str[j+2]];
uc3 = (UCHAR)base64IndexArray[base64Str[j+3]];
if ((uc0 == -1) || (uc1 == -1) || (uc2 == -1) || (uc3 == -1))
return -1;
if (base64Str[j+2] == '=') // && (uc3 == '=')
{
uc2 = uc3 = 0;
padd = b64_2padded;
}
else if (base64Str[j+3] == '=')
{
uc3 = 0;
padd = b64_1padded;
}
p0 = uc0 << 2;
p1 = uc1 << 2;
p1 >>= 6;
dest[k++] = p0 | p1;
p0 = uc1 << 4;
p1 = uc2 << 2;
p1 >>= 4;
dest[k++] = p0 | p1;
p0 = uc2 << 6;
p1 = uc3;
dest[k++] = p0 | p1;
}
//dest[k] = '\0';
if (padd == b64_1padded)
// dest[k-1] = '\0';
return k-1;
else if (padd == b64_2padded)
// dest[k-2] = '\0';
return k-2;
return k;
}
} // anonymous namespace } // anonymous namespace
@ -540,32 +626,72 @@ namespace // anonymous namespace
wstring LocalizationSwitcher::getLangFromXmlFileName(const wchar_t *fn) const
void cutString(const TCHAR* str2cut, vector<generic_string>& patternVect)
{
TCHAR str2scan[MAX_PATH];
lstrcpy(str2scan, str2cut);
size_t len = lstrlen(str2scan);
bool isProcessing = false;
TCHAR *pBegin = nullptr;
for (size_t i = 0 ; i <= len ; ++i)
{
switch(str2scan[i])
{
case ' ':
case '\0':
{
if (isProcessing)
{
str2scan[i] = '\0';
patternVect.push_back(pBegin);
isProcessing = false;
}
break;
}
default:
{
if (!isProcessing)
{
isProcessing = true;
pBegin = str2scan+i;
}
}
}
}
}
std::wstring LocalizationSwitcher::getLangFromXmlFileName(const wchar_t *fn) const
{ {
size_t nbItem = sizeof(localizationDefs)/sizeof(LocalizationSwitcher::LocalizationDefinition); size_t nbItem = sizeof(localizationDefs)/sizeof(LocalizationSwitcher::LocalizationDefinition);
for (size_t i = 0 ; i < nbItem ; ++i) for (size_t i = 0 ; i < nbItem ; ++i)
{ {
if (wcsicmp(fn, localizationDefs[i]._xmlFileName) == 0) if (0 == wcsicmp(fn, localizationDefs[i]._xmlFileName))
return localizationDefs[i]._langName; return localizationDefs[i]._langName;
} }
return TEXT(""); return std::wstring();
} }
wstring LocalizationSwitcher::getXmlFilePathFromLangName(const wchar_t *langName) const
std::wstring LocalizationSwitcher::getXmlFilePathFromLangName(const wchar_t *langName) const
{ {
for (size_t i = 0, len = _localizationList.size(); i < len ; ++i) for (size_t i = 0, len = _localizationList.size(); i < len ; ++i)
{ {
if (wcsicmp(langName, _localizationList[i].first.c_str()) == 0) if (0 == wcsicmp(langName, _localizationList[i].first.c_str()))
return _localizationList[i].second; return _localizationList[i].second;
} }
return TEXT(""); return std::wstring();
} }
bool LocalizationSwitcher::addLanguageFromXml(wstring xmlFullPath) bool LocalizationSwitcher::addLanguageFromXml(wstring xmlFullPath)
{ {
wchar_t * fn = ::PathFindFileNameW(xmlFullPath.c_str()); wchar_t * fn = ::PathFindFileNameW(xmlFullPath.c_str());
wstring foundLang = getLangFromXmlFileName(fn); wstring foundLang = getLangFromXmlFileName(fn);
if (foundLang != TEXT("")) if (not foundLang.empty())
{ {
_localizationList.push_back(pair<wstring, wstring>(foundLang, xmlFullPath)); _localizationList.push_back(pair<wstring, wstring>(foundLang, xmlFullPath));
return true; return true;
@ -573,10 +699,11 @@ bool LocalizationSwitcher::addLanguageFromXml(wstring xmlFullPath)
return false; return false;
} }
bool LocalizationSwitcher::switchToLang(wchar_t *lang2switch) const bool LocalizationSwitcher::switchToLang(wchar_t *lang2switch) const
{ {
wstring langPath = getXmlFilePathFromLangName(lang2switch); wstring langPath = getXmlFilePathFromLangName(lang2switch);
if (langPath == TEXT("")) if (langPath.empty())
return false; return false;
return ::CopyFileW(langPath.c_str(), _nativeLangPath.c_str(), FALSE) != FALSE; return ::CopyFileW(langPath.c_str(), _nativeLangPath.c_str(), FALSE) != FALSE;
@ -586,13 +713,12 @@ bool LocalizationSwitcher::switchToLang(wchar_t *lang2switch) const
generic_string ThemeSwitcher::getThemeFromXmlFileName(const TCHAR *xmlFullPath) const generic_string ThemeSwitcher::getThemeFromXmlFileName(const TCHAR *xmlFullPath) const
{ {
if (!xmlFullPath || !xmlFullPath[0]) if (!xmlFullPath || !xmlFullPath[0])
return TEXT(""); return generic_string();
generic_string fn(::PathFindFileName(xmlFullPath)); generic_string fn(::PathFindFileName(xmlFullPath));
PathRemoveExtension((TCHAR *)fn.c_str()); PathRemoveExtension((TCHAR *)fn.c_str());
return fn.c_str(); return fn;
} }
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
#pragma warning(disable : 4996) #pragma warning(disable : 4996)
@ -619,39 +745,27 @@ winVer getWindowsVersion()
pGNSI(&si); pGNSI(&si);
else else
GetSystemInfo(&si); GetSystemInfo(&si);
//printInt(osvi.dwMajorVersion);
//printInt(osvi.dwMinorVersion);
switch (osvi.dwPlatformId) switch (osvi.dwPlatformId)
{ {
case VER_PLATFORM_WIN32_NT: case VER_PLATFORM_WIN32_NT:
{ {
if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 3) if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 3)
{
return WV_WIN81; return WV_WIN81;
}
if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 2) if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 2)
{
return WV_WIN8; return WV_WIN8;
}
if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1) if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1)
{
return WV_WIN7; return WV_WIN7;
}
if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0) if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0)
{
return WV_VISTA; return WV_VISTA;
}
if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2) if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
{ {
if (osvi.wProductType == VER_NT_WORKSTATION && if (osvi.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
{
return WV_XPX64; return WV_XPX64;
}
return WV_S2003; return WV_S2003;
} }
@ -663,28 +777,22 @@ winVer getWindowsVersion()
if (osvi.dwMajorVersion <= 4) if (osvi.dwMajorVersion <= 4)
return WV_NT; return WV_NT;
}
break; break;
}
// Test for the Windows Me/98/95. // Test for the Windows Me/98/95.
case VER_PLATFORM_WIN32_WINDOWS: case VER_PLATFORM_WIN32_WINDOWS:
{ {
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
{
return WV_95; return WV_95;
}
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
{
return WV_98; return WV_98;
}
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
{
return WV_ME; return WV_ME;
}
}
break; break;
}
case VER_PLATFORM_WIN32s: case VER_PLATFORM_WIN32s:
return WV_WIN32S; return WV_WIN32S;
@ -692,13 +800,20 @@ winVer getWindowsVersion()
default: default:
return WV_UNKNOWN; return WV_UNKNOWN;
} }
return WV_UNKNOWN; return WV_UNKNOWN;
} }
NppParameters * NppParameters::_pSelf = new NppParameters; NppParameters * NppParameters::_pSelf = new NppParameters;
int FileDialog::_dialogFileBoxId = (NppParameters::getInstance())->getWinVersion() < WV_W2K?edt1:cmb13; int FileDialog::_dialogFileBoxId = (NppParameters::getInstance())->getWinVersion() < WV_W2K?edt1:cmb13;
NppParameters::NppParameters() : _pXmlDoc(NULL),_pXmlUserDoc(NULL), _pXmlUserStylerDoc(NULL),_pXmlUserLangDoc(NULL),\ NppParameters::NppParameters() : _pXmlDoc(NULL),_pXmlUserDoc(NULL), _pXmlUserStylerDoc(NULL),_pXmlUserLangDoc(NULL),\
_pXmlNativeLangDocA(NULL), _nbLang(0), _pXmlToolIconsDoc(NULL), _nbRecentFile(0),\ _pXmlNativeLangDocA(NULL), _nbLang(0), _pXmlToolIconsDoc(NULL), _nbRecentFile(0),\
_nbMaxRecentFile(10), _recentFileCustomLength(RECENTFILES_SHOWFULLPATH),\ _nbMaxRecentFile(10), _recentFileCustomLength(RECENTFILES_SHOWFULLPATH),\
@ -706,14 +821,12 @@ NppParameters::NppParameters() : _pXmlDoc(NULL),_pXmlUserDoc(NULL), _pXmlUserSty
_pXmlSessionDoc(NULL), _pXmlBlacklistDoc(NULL), _nbUserLang(0), _nbExternalLang(0),\ _pXmlSessionDoc(NULL), _pXmlBlacklistDoc(NULL), _nbUserLang(0), _nbExternalLang(0),\
_hUXTheme(NULL), _transparentFuncAddr(NULL), _enableThemeDialogTextureFuncAddr(NULL),\ _hUXTheme(NULL), _transparentFuncAddr(NULL), _enableThemeDialogTextureFuncAddr(NULL),\
_pNativeLangSpeaker(NULL), _isTaskListRBUTTONUP_Active(false), _fileSaveDlgFilterIndex(-1),\ _pNativeLangSpeaker(NULL), _isTaskListRBUTTONUP_Active(false), _fileSaveDlgFilterIndex(-1),\
_asNotepadStyle(false), _isFindReplacing(false), _initialCloudChoice(TEXT("")) _asNotepadStyle(false), _isFindReplacing(false)
{ {
// init import UDL array // init import UDL array
_nbImportedULD = 0; _nbImportedULD = 0;
for (int i = 0 ; i < NB_MAX_IMPORTED_UDL ; ++i) for (int i = 0 ; i < NB_MAX_IMPORTED_UDL ; ++i)
{ _importedULD[i] = nullptr;
_importedULD[i] = NULL;
}
//Get windows version //Get windows version
_winVersion = getWindowsVersion(); _winVersion = getWindowsVersion();
@ -730,7 +843,7 @@ NppParameters::NppParameters() : _pXmlDoc(NULL),_pXmlUserDoc(NULL), _pXmlUserSty
::GetCurrentDirectory(MAX_PATH, curDir); ::GetCurrentDirectory(MAX_PATH, curDir);
_currentDirectory = curDir; _currentDirectory = curDir;
_appdataNppDir = TEXT(""); _appdataNppDir.clear();
generic_string notepadStylePath(_nppPath); generic_string notepadStylePath(_nppPath);
PathAppend(notepadStylePath, notepadStyleFile); PathAppend(notepadStylePath, notepadStyleFile);
@ -741,6 +854,7 @@ NppParameters::NppParameters() : _pXmlDoc(NULL),_pXmlUserDoc(NULL), _pXmlUserSty
initScintillaKeys(); initScintillaKeys();
} }
NppParameters::~NppParameters() NppParameters::~NppParameters()
{ {
for (int i = 0 ; i < _nbLang ; ++i) for (int i = 0 ; i < _nbLang ; ++i)
@ -753,44 +867,11 @@ NppParameters::~NppParameters()
FreeLibrary(_hUXTheme); FreeLibrary(_hUXTheme);
for (std::vector<TiXmlDocument *>::iterator it = _pXmlExternalLexerDoc.begin(), end = _pXmlExternalLexerDoc.end(); it != end; ++it ) for (std::vector<TiXmlDocument *>::iterator it = _pXmlExternalLexerDoc.begin(), end = _pXmlExternalLexerDoc.end(); it != end; ++it )
{
delete (*it); delete (*it);
}
_pXmlExternalLexerDoc.clear(); _pXmlExternalLexerDoc.clear();
} }
void cutString(const TCHAR *str2cut, vector<generic_string> & patternVect)
{
TCHAR str2scan[MAX_PATH];
lstrcpy(str2scan, str2cut);
size_t len = lstrlen(str2scan);
bool isProcessing = false;
TCHAR *pBegin = NULL;
for (size_t i = 0 ; i <= len ; ++i)
{
switch(str2scan[i])
{
case ' ':
case '\0':
{
if (isProcessing)
{
str2scan[i] = '\0';
patternVect.push_back(pBegin);
isProcessing = false;
}
break;
}
default :
if (!isProcessing)
{
isProcessing = true;
pBegin = str2scan+i;
}
}
}
}
bool NppParameters::reloadStylers(TCHAR *stylePath) bool NppParameters::reloadStylers(TCHAR *stylePath)
{ {
@ -842,124 +923,37 @@ bool NppParameters::reloadLang()
if (!loadOkay) if (!loadOkay)
{ {
delete _pXmlNativeLangDocA; delete _pXmlNativeLangDocA;
_pXmlNativeLangDocA = NULL; _pXmlNativeLangDocA = nullptr;
return false; return false;
} }
return loadOkay; return loadOkay;
} }
size_t getAsciiLenFromBase64Len(size_t base64StrLen)
{
if (base64StrLen % 4) return 0;
return base64StrLen - base64StrLen / 4;
}
int base64ToAscii(char *dest, const char *base64Str)
{
int base64IndexArray[123] =\
{\
-1, -1, -1, -1, -1, -1, -1, -1,\
-1, -1, -1, -1, -1, -1, -1, -1,\
-1, -1, -1, -1, -1, -1, -1, -1,\
-1, -1, -1, -1, -1, -1, -1, -1,\
-1, -1, -1, -1, -1, -1, -1, -1,\
-1, -1, -1, 62, -1, -1, -1, 63,\
52, 53, 54, 55 ,56, 57, 58, 59,\
60, 61, -1, -1, -1, -1, -1, -1,\
-1, 0, 1, 2, 3, 4, 5, 6,\
7, 8, 9, 10, 11, 12, 13, 14,\
15, 16, 17, 18, 19, 20, 21, 22,\
23, 24, 25, -1, -1, -1, -1 ,-1,\
-1, 26, 27, 28, 29, 30, 31, 32,\
33, 34, 35, 36, 37, 38, 39, 40,\
41, 42, 43, 44, 45, 46, 47, 48,\
49, 50, 51\
};
size_t b64StrLen = strlen(base64Str);
size_t nbLoop = b64StrLen / 4;
size_t i = 0;
int k = 0;
enum {b64_just, b64_1padded, b64_2padded} padd = b64_just;
for ( ; i < nbLoop ; i++)
{
size_t j = i * 4;
UCHAR uc0, uc1, uc2, uc3, p0, p1;
uc0 = (UCHAR)base64IndexArray[base64Str[j]];
uc1 = (UCHAR)base64IndexArray[base64Str[j+1]];
uc2 = (UCHAR)base64IndexArray[base64Str[j+2]];
uc3 = (UCHAR)base64IndexArray[base64Str[j+3]];
if ((uc0 == -1) || (uc1 == -1) || (uc2 == -1) || (uc3 == -1))
return -1;
if (base64Str[j+2] == '=') // && (uc3 == '=')
{
uc2 = uc3 = 0;
padd = b64_2padded;
}
else if (base64Str[j+3] == '=')
{
uc3 = 0;
padd = b64_1padded;
}
p0 = uc0 << 2;
p1 = uc1 << 2;
p1 >>= 6;
dest[k++] = p0 | p1;
p0 = uc1 << 4;
p1 = uc2 << 2;
p1 >>= 4;
dest[k++] = p0 | p1;
p0 = uc2 << 6;
p1 = uc3;
dest[k++] = p0 | p1;
}
//dest[k] = '\0';
if (padd == b64_1padded)
// dest[k-1] = '\0';
return k-1;
else if (padd == b64_2padded)
// dest[k-2] = '\0';
return k-2;
return k;
}
generic_string NppParameters::getSettingsFolder() generic_string NppParameters::getSettingsFolder()
{ {
generic_string settingsFolderPath;
if (_isLocal) if (_isLocal)
{
return _nppPath; return _nppPath;
}
else
{
ITEMIDLIST *pidl; ITEMIDLIST *pidl;
const HRESULT specialLocationResult = SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl); const HRESULT specialLocationResult = SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl);
if (!SUCCEEDED( specialLocationResult)) if (!SUCCEEDED( specialLocationResult))
{ return generic_string();
return TEXT( "" );
}
TCHAR tmp[MAX_PATH]; TCHAR tmp[MAX_PATH];
SHGetPathFromIDList(pidl, tmp); SHGetPathFromIDList(pidl, tmp);
generic_string settingsFolderPath = tmp; generic_string settingsFolderPath{tmp};
PathAppend(settingsFolderPath, TEXT("Notepad++")); PathAppend(settingsFolderPath, TEXT("Notepad++"));
return settingsFolderPath; return settingsFolderPath;
} }
}
bool NppParameters::load() bool NppParameters::load()
{ {
L_END = L_EXTERNAL; L_END = L_EXTERNAL;
bool isAllLaoded = true; bool isAllLaoded = true;
for (int i = 0 ; i < NB_LANG ; _langList[i] = NULL, ++i); for (int i = 0 ; i < NB_LANG ; _langList[i] = NULL, ++i)
{}
// Make localConf.xml path // Make localConf.xml path
generic_string localConfPath(_nppPath); generic_string localConfPath(_nppPath);
@ -978,9 +972,8 @@ bool NppParameters::load()
ITEMIDLIST *pidl; ITEMIDLIST *pidl;
const HRESULT specialLocationResult = SHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidl); const HRESULT specialLocationResult = SHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidl);
if (!SUCCEEDED( specialLocationResult)) if (!SUCCEEDED( specialLocationResult))
{
return false; return false;
}
TCHAR progPath[MAX_PATH]; TCHAR progPath[MAX_PATH];
SHGetPathFromIDList(pidl, progPath); SHGetPathFromIDList(pidl, progPath);
TCHAR nppDirLocation[MAX_PATH]; TCHAR nppDirLocation[MAX_PATH];
@ -1001,9 +994,8 @@ bool NppParameters::load()
ITEMIDLIST *pidl; ITEMIDLIST *pidl;
const HRESULT specialLocationResult = SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl); const HRESULT specialLocationResult = SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl);
if (!SUCCEEDED( specialLocationResult)) if (!SUCCEEDED( specialLocationResult))
{
return false; return false;
}
TCHAR tmp[MAX_PATH]; TCHAR tmp[MAX_PATH];
SHGetPathFromIDList(pidl, tmp); SHGetPathFromIDList(pidl, tmp);
_userPath = tmp; _userPath = tmp;
@ -1012,15 +1004,13 @@ bool NppParameters::load()
_appdataNppDir = _userPath; _appdataNppDir = _userPath;
if (!PathFileExists(_userPath.c_str())) if (!PathFileExists(_userPath.c_str()))
{
::CreateDirectory(_userPath.c_str(), NULL); ::CreateDirectory(_userPath.c_str(), NULL);
} }
}
_sessionPath = _userPath; // Session stock the absolute file path, it should never be on cloud _sessionPath = _userPath; // Session stock the absolute file path, it should never be on cloud
// Detection cloud settings // Detection cloud settings
generic_string cloudChoicePath = _userPath; generic_string cloudChoicePath{_userPath};
cloudChoicePath += TEXT("\\cloud\\choice"); cloudChoicePath += TEXT("\\cloud\\choice");
// cloudChoicePath doesn't exist, just quit // cloudChoicePath doesn't exist, just quit
@ -1031,7 +1021,7 @@ bool NppParameters::load()
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
std::wstring cloudChoiceStrW = wmc->char2wchar(cloudChoiceStr.c_str(), SC_CP_UTF8); std::wstring cloudChoiceStrW = wmc->char2wchar(cloudChoiceStr.c_str(), SC_CP_UTF8);
if (cloudChoiceStrW != TEXT("") && ::PathFileExists(cloudChoiceStrW.c_str())) if (not cloudChoiceStrW.empty() and ::PathFileExists(cloudChoiceStrW.c_str()))
{ {
_userPath = cloudChoiceStrW; _userPath = cloudChoiceStrW;
_nppGUI._cloudPath = cloudChoiceStrW; _nppGUI._cloudPath = cloudChoiceStrW;
@ -1087,7 +1077,7 @@ bool NppParameters::load()
{ {
::MessageBox(NULL, TEXT("Load langs.xml failed!"), TEXT("Configurator"),MB_OK); ::MessageBox(NULL, TEXT("Load langs.xml failed!"), TEXT("Configurator"),MB_OK);
delete _pXmlDoc; delete _pXmlDoc;
_pXmlDoc = NULL; _pXmlDoc = nullptr;
isAllLaoded = false; isAllLaoded = false;
} }
else else
@ -1151,9 +1141,7 @@ bool NppParameters::load()
} }
if (_nppGUI._themeName.empty() || (!PathFileExists(_nppGUI._themeName.c_str()))) if (_nppGUI._themeName.empty() || (!PathFileExists(_nppGUI._themeName.c_str())))
{
_nppGUI._themeName.assign(_stylerPath); _nppGUI._themeName.assign(_stylerPath);
}
_pXmlUserStylerDoc = new TiXmlDocument(_nppGUI._themeName.c_str()); _pXmlUserStylerDoc = new TiXmlDocument(_nppGUI._themeName.c_str());
@ -1183,7 +1171,7 @@ bool NppParameters::load()
if (!loadOkay) if (!loadOkay)
{ {
delete _pXmlUserLangDoc; delete _pXmlUserLangDoc;
_pXmlUserLangDoc = NULL; _pXmlUserLangDoc = nullptr;
isAllLaoded = false; isAllLaoded = false;
} }
else else
@ -1202,7 +1190,7 @@ bool NppParameters::load()
// LocalizationSwitcher should use always user path // LocalizationSwitcher should use always user path
_localizationSwitcher._nativeLangPath = nativeLangPath; _localizationSwitcher._nativeLangPath = nativeLangPath;
if (_startWithLocFileName != TEXT("")) // localization argument detected, use user wished localization if (not _startWithLocFileName.empty()) // localization argument detected, use user wished localization
{ {
// overwrite nativeLangPath variable // overwrite nativeLangPath variable
nativeLangPath = _nppPath; nativeLangPath = _nppPath;
@ -1225,7 +1213,7 @@ bool NppParameters::load()
if (!loadOkay) if (!loadOkay)
{ {
delete _pXmlNativeLangDocA; delete _pXmlNativeLangDocA;
_pXmlNativeLangDocA = NULL; _pXmlNativeLangDocA = nullptr;
isAllLaoded = false; isAllLaoded = false;
} }
@ -1240,7 +1228,7 @@ bool NppParameters::load()
if (!loadOkay) if (!loadOkay)
{ {
delete _pXmlToolIconsDoc; delete _pXmlToolIconsDoc;
_pXmlToolIconsDoc = NULL; _pXmlToolIconsDoc = nullptr;
isAllLaoded = false; isAllLaoded = false;
} }
@ -1263,7 +1251,7 @@ bool NppParameters::load()
if (!loadOkay) if (!loadOkay)
{ {
delete _pXmlShortcutDoc; delete _pXmlShortcutDoc;
_pXmlShortcutDoc = NULL; _pXmlShortcutDoc = nullptr;
isAllLaoded = false; isAllLaoded = false;
} }
else else
@ -1296,7 +1284,7 @@ bool NppParameters::load()
if (!loadOkay) if (!loadOkay)
{ {
delete _pXmlContextMenuDocA; delete _pXmlContextMenuDocA;
_pXmlContextMenuDocA = NULL; _pXmlContextMenuDocA = nullptr;
isAllLaoded = false; isAllLaoded = false;
} }
@ -1311,6 +1299,7 @@ bool NppParameters::load()
if (nppGUI._rememberLastSession) if (nppGUI._rememberLastSession)
{ {
_pXmlSessionDoc = new TiXmlDocument(_sessionPath); _pXmlSessionDoc = new TiXmlDocument(_sessionPath);
loadOkay = _pXmlSessionDoc->LoadFile(); loadOkay = _pXmlSessionDoc->LoadFile();
if (!loadOkay) if (!loadOkay)
isAllLaoded = false; isAllLaoded = false;
@ -1322,7 +1311,7 @@ bool NppParameters::load()
if (_pXmlExternalLexerDoc[i]) if (_pXmlExternalLexerDoc[i])
delete _pXmlExternalLexerDoc[i]; delete _pXmlExternalLexerDoc[i];
_pXmlSessionDoc = NULL; _pXmlSessionDoc = nullptr;
} }
//------------------------------// //------------------------------//
@ -1336,59 +1325,34 @@ bool NppParameters::load()
_pXmlBlacklistDoc = new TiXmlDocument(_blacklistPath); _pXmlBlacklistDoc = new TiXmlDocument(_blacklistPath);
loadOkay = _pXmlBlacklistDoc->LoadFile(); loadOkay = _pXmlBlacklistDoc->LoadFile();
if (loadOkay) if (loadOkay)
{
getBlackListFromXmlTree(); getBlackListFromXmlTree();
} }
}
return isAllLaoded; return isAllLaoded;
} }
void NppParameters::destroyInstance() void NppParameters::destroyInstance()
{
if (_pXmlDoc != NULL)
{ {
delete _pXmlDoc; delete _pXmlDoc;
}
if (_pXmlUserDoc != NULL)
{
delete _pXmlUserDoc; delete _pXmlUserDoc;
}
if (_pXmlUserStylerDoc)
delete _pXmlUserStylerDoc; delete _pXmlUserStylerDoc;
if (_pXmlUserLangDoc)
{
delete _pXmlUserLangDoc; delete _pXmlUserLangDoc;
}
for (int i = 0 ; i < _nbImportedULD ; ++i) for (int i = 0 ; i < _nbImportedULD ; ++i)
{ {
delete _importedULD[i]; delete _importedULD[i];
_importedULD[i] = NULL; _importedULD[i] = nullptr;
} }
_nbImportedULD = 0; _nbImportedULD = 0;
if (_pXmlNativeLangDocA)
delete _pXmlNativeLangDocA; delete _pXmlNativeLangDocA;
if (_pXmlToolIconsDoc)
delete _pXmlToolIconsDoc; delete _pXmlToolIconsDoc;
if (_pXmlShortcutDoc)
delete _pXmlShortcutDoc; delete _pXmlShortcutDoc;
if (_pXmlContextMenuDocA)
delete _pXmlContextMenuDocA; delete _pXmlContextMenuDocA;
if (_pXmlSessionDoc)
delete _pXmlSessionDoc; delete _pXmlSessionDoc;
if (_pXmlBlacklistDoc)
delete _pXmlBlacklistDoc; delete _pXmlBlacklistDoc;
delete _pSelf; delete _pSelf;
_pSelf = NULL; _pSelf = nullptr;
} }
@ -1416,9 +1380,8 @@ void NppParameters::removeTransparent(HWND hwnd)
void NppParameters::SetTransparent(HWND hwnd, int percent) void NppParameters::SetTransparent(HWND hwnd, int percent)
{ {
if (!_transparentFuncAddr) if (nullptr != _transparentFuncAddr)
return; {
::SetWindowLongPtr(hwnd, GWL_EXSTYLE, ::GetWindowLongPtr(hwnd, GWL_EXSTYLE) | 0x00080000); ::SetWindowLongPtr(hwnd, GWL_EXSTYLE, ::GetWindowLongPtr(hwnd, GWL_EXSTYLE) | 0x00080000);
if (percent > 255) if (percent > 255)
percent = 255; percent = 255;
@ -1426,6 +1389,7 @@ void NppParameters::SetTransparent(HWND hwnd, int percent)
percent = 0; percent = 0;
_transparentFuncAddr(hwnd, 0, percent, 0x00000002); _transparentFuncAddr(hwnd, 0, percent, 0x00000002);
} }
}
bool NppParameters::isExistingExternalLangName(const TCHAR *newName) const bool NppParameters::isExistingExternalLangName(const TCHAR *newName) const
@ -1529,6 +1493,7 @@ static int CALLBACK EnumFontFamExProc(const LOGFONT* lpelfe, const TEXTMETRIC*,
return 1; // I want to get all fonts return 1; // I want to get all fonts
} }
void NppParameters::setFontList(HWND hWnd) void NppParameters::setFontList(HWND hWnd)
{ {
//---------------// //---------------//
@ -1536,7 +1501,8 @@ void NppParameters::setFontList(HWND hWnd)
//---------------// //---------------//
LOGFONT lf; LOGFONT lf;
_fontlist.clear(); _fontlist.clear();
_fontlist.push_back(TEXT("")); _fontlist.reserve(64); // arbitrary
_fontlist.push_back(generic_string());
lf.lfCharSet = DEFAULT_CHARSET; lf.lfCharSet = DEFAULT_CHARSET;
lf.lfFaceName[0]='\0'; lf.lfFaceName[0]='\0';
@ -1545,6 +1511,7 @@ void NppParameters::setFontList(HWND hWnd)
::EnumFontFamiliesEx(hDC, &lf, EnumFontFamExProc, (LPARAM)&_fontlist, 0); ::EnumFontFamiliesEx(hDC, &lf, EnumFontFamExProc, (LPARAM)&_fontlist, 0);
} }
void NppParameters::getLangKeywordsFromXmlTree() void NppParameters::getLangKeywordsFromXmlTree()
{ {
TiXmlNode *root = TiXmlNode *root =
@ -1553,6 +1520,7 @@ void NppParameters::getLangKeywordsFromXmlTree()
feedKeyWordsParameters(root); feedKeyWordsParameters(root);
} }
void NppParameters::getExternalLexerFromXmlTree(TiXmlDocument *doc) void NppParameters::getExternalLexerFromXmlTree(TiXmlDocument *doc)
{ {
TiXmlNode *root = doc->FirstChild(TEXT("NotepadPlus")); TiXmlNode *root = doc->FirstChild(TEXT("NotepadPlus"));
@ -1561,6 +1529,7 @@ void NppParameters::getExternalLexerFromXmlTree(TiXmlDocument *doc)
feedStylerArray(root); feedStylerArray(root);
} }
int NppParameters::addExternalLangToEnd(ExternalLangContainer * externalLang) int NppParameters::addExternalLangToEnd(ExternalLangContainer * externalLang)
{ {
_externalLangArray[_nbExternalLang] = externalLang; _externalLangArray[_nbExternalLang] = externalLang;
@ -1569,6 +1538,7 @@ int NppParameters::addExternalLangToEnd(ExternalLangContainer * externalLang)
return _nbExternalLang-1; return _nbExternalLang-1;
} }
bool NppParameters::getUserStylersFromXmlTree() bool NppParameters::getUserStylersFromXmlTree()
{ {
TiXmlNode *root = _pXmlUserStylerDoc->FirstChild(TEXT("NotepadPlus")); TiXmlNode *root = _pXmlUserStylerDoc->FirstChild(TEXT("NotepadPlus"));
@ -1576,13 +1546,15 @@ bool NppParameters::getUserStylersFromXmlTree()
return feedStylerArray(root); return feedStylerArray(root);
} }
bool NppParameters::getUserParametersFromXmlTree() bool NppParameters::getUserParametersFromXmlTree()
{ {
if (!_pXmlUserDoc) if (!_pXmlUserDoc)
return false; return false;
TiXmlNode *root = _pXmlUserDoc->FirstChild(TEXT("NotepadPlus")); TiXmlNode *root = _pXmlUserDoc->FirstChild(TEXT("NotepadPlus"));
if (!root) return false; if (nullptr == root)
return false;
// Get GUI parameters // Get GUI parameters
feedGUIParameters(root); feedGUIParameters(root);
@ -1607,6 +1579,7 @@ bool NppParameters::getUserParametersFromXmlTree()
return true; return true;
} }
bool NppParameters::getUserDefineLangsFromXmlTree(TiXmlDocument *tixmldoc) bool NppParameters::getUserDefineLangsFromXmlTree(TiXmlDocument *tixmldoc)
{ {
if (!tixmldoc) if (!tixmldoc)
@ -1634,6 +1607,7 @@ bool NppParameters::getShortcutsFromXmlTree()
return true; return true;
} }
bool NppParameters::getMacrosFromXmlTree() bool NppParameters::getMacrosFromXmlTree()
{ {
if (!_pXmlShortcutDoc) if (!_pXmlShortcutDoc)
@ -1647,6 +1621,7 @@ bool NppParameters::getMacrosFromXmlTree()
return true; return true;
} }
bool NppParameters::getUserCmdsFromXmlTree() bool NppParameters::getUserCmdsFromXmlTree()
{ {
if (!_pXmlShortcutDoc) if (!_pXmlShortcutDoc)
@ -1872,7 +1847,7 @@ bool NppParameters::getContextMenuFromXmlTree(HMENU mainMenuHadle, HMENU plugins
menuEntryName = menuEntryNameA?wmc->char2wchar(menuEntryNameA, SC_CP_UTF8):TEXT(""); menuEntryName = menuEntryNameA?wmc->char2wchar(menuEntryNameA, SC_CP_UTF8):TEXT("");
menuItemName = menuItemNameA?wmc->char2wchar(menuItemNameA, SC_CP_UTF8):TEXT(""); menuItemName = menuItemNameA?wmc->char2wchar(menuItemNameA, SC_CP_UTF8):TEXT("");
if (menuEntryName != TEXT("") && menuItemName != TEXT("")) if (not menuEntryName.empty() and not menuItemName.empty())
{ {
int cmd = getCmdIdFromMenuEntryItemName(mainMenuHadle, menuEntryName, menuItemName); int cmd = getCmdIdFromMenuEntryItemName(mainMenuHadle, menuEntryName, menuItemName);
if (cmd != -1) if (cmd != -1)
@ -1889,7 +1864,7 @@ bool NppParameters::getContextMenuFromXmlTree(HMENU mainMenuHadle, HMENU plugins
pluginCmdName = pluginCmdNameA?wmc->char2wchar(pluginCmdNameA, SC_CP_UTF8):TEXT(""); pluginCmdName = pluginCmdNameA?wmc->char2wchar(pluginCmdNameA, SC_CP_UTF8):TEXT("");
// if plugin menu existing plls the value of PluginEntryName and PluginCommandItemName are valid // if plugin menu existing plls the value of PluginEntryName and PluginCommandItemName are valid
if (pluginsMenu && pluginName != TEXT("") && pluginCmdName != TEXT("")) if (pluginsMenu && not pluginName.empty() && not pluginCmdName.empty())
{ {
int pluginCmdId = getPluginCmdIdFromMenuEntryItemName(pluginsMenu, pluginName, pluginCmdName); int pluginCmdId = getPluginCmdIdFromMenuEntryItemName(pluginsMenu, pluginName, pluginCmdName);
if (pluginCmdId != -1) if (pluginCmdId != -1)
@ -1902,6 +1877,7 @@ bool NppParameters::getContextMenuFromXmlTree(HMENU mainMenuHadle, HMENU plugins
return true; return true;
} }
void NppParameters::setWorkingDir(const TCHAR * newPath) void NppParameters::setWorkingDir(const TCHAR * newPath)
{ {
if (newPath && newPath[0]) if (newPath && newPath[0])
@ -1911,15 +1887,12 @@ void NppParameters::setWorkingDir(const TCHAR * newPath)
else else
{ {
if (PathFileExists(_nppGUI._defaultDirExp)) if (PathFileExists(_nppGUI._defaultDirExp))
{
_currentDirectory = _nppGUI._defaultDirExp; _currentDirectory = _nppGUI._defaultDirExp;
}
else else
{
_currentDirectory = _nppPath.c_str(); _currentDirectory = _nppPath.c_str();
} }
} }
}
bool NppParameters::loadSession(Session & session, const TCHAR *sessionFileName) bool NppParameters::loadSession(Session & session, const TCHAR *sessionFileName)
{ {
@ -1932,6 +1905,7 @@ bool NppParameters::loadSession(Session & session, const TCHAR *sessionFileName)
return loadOkay; return loadOkay;
} }
bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session *pSession) bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session *pSession)
{ {
if ((pSessionDoc) && (!pSession)) if ((pSessionDoc) && (!pSession))
@ -2591,9 +2565,10 @@ LangType NppParameters::getLangFromExt(const TCHAR *ext)
if (pLS) if (pLS)
userList = pLS->getLexerUserExt(); userList = pLS->getLexerUserExt();
generic_string list(TEXT("")); generic_string list;
if (defList) if (defList)
list += defList; list += defList;
if (userList) if (userList)
{ {
list += TEXT(" "); list += TEXT(" ");
@ -2662,10 +2637,8 @@ bool NppParameters::writeSettingsFilesOnCloudForThe1stTime(const generic_string
{ {
bool isOK = false; bool isOK = false;
if (cloudSettingsPath == TEXT("")) if (cloudSettingsPath.empty())
{
return false; return false;
}
// config.xml // config.xml
generic_string cloudConfigPath = cloudSettingsPath; generic_string cloudConfigPath = cloudSettingsPath;
@ -3110,7 +3083,7 @@ void NppParameters::feedUserKeywordList(TiXmlNode *node)
{ {
if (!lstrcmp(udlVersion, TEXT("")) && !lstrcmp(keywordsName, TEXT("Delimiters"))) // support for old style (pre 2.0) if (!lstrcmp(udlVersion, TEXT("")) && !lstrcmp(keywordsName, TEXT("Delimiters"))) // support for old style (pre 2.0)
{ {
basic_string<TCHAR> temp = TEXT(""); basic_string<TCHAR> temp;
kwl = (valueNode)?valueNode->Value():TEXT("000000"); kwl = (valueNode)?valueNode->Value():TEXT("000000");
temp += TEXT("00"); if (kwl[0] != '0') temp += kwl[0]; temp += TEXT(" 01"); temp += TEXT("00"); if (kwl[0] != '0') temp += kwl[0]; temp += TEXT(" 01");
@ -3127,7 +3100,7 @@ void NppParameters::feedUserKeywordList(TiXmlNode *node)
{ {
kwl = (valueNode)?valueNode->Value():TEXT(""); kwl = (valueNode)?valueNode->Value():TEXT("");
//int len = _tcslen(kwl); //int len = _tcslen(kwl);
basic_string<TCHAR> temp = TEXT(" "); basic_string<TCHAR> temp{TEXT(" ")};
temp += kwl; temp += kwl;
size_t pos = 0; size_t pos = 0;
@ -3604,14 +3577,15 @@ generic_string NppParameters::getLocPathFromStr(const generic_string & localizat
if (localizationCode == TEXT("uz")) if (localizationCode == TEXT("uz"))
return TEXT("uzbek.xml"); return TEXT("uzbek.xml");
return TEXT(""); return generic_string();
} }
void NppParameters::feedKeyWordsParameters(TiXmlNode *node) void NppParameters::feedKeyWordsParameters(TiXmlNode *node)
{ {
TiXmlNode *langRoot = node->FirstChildElement(TEXT("Languages")); TiXmlNode *langRoot = node->FirstChildElement(TEXT("Languages"));
if (!langRoot) return; if (!langRoot)
return;
for (TiXmlNode *langNode = langRoot->FirstChildElement(TEXT("Language")); for (TiXmlNode *langNode = langRoot->FirstChildElement(TEXT("Language"));
langNode ; langNode ;
@ -5310,7 +5284,7 @@ bool NppParameters::writeGUIParams()
pStr = _nppGUI._matchedPairConf._doHtmlXmlTag?TEXT("yes"):TEXT("no"); pStr = _nppGUI._matchedPairConf._doHtmlXmlTag?TEXT("yes"):TEXT("no");
element->SetAttribute(TEXT("htmlXmlTag"), pStr); element->SetAttribute(TEXT("htmlXmlTag"), pStr);
TiXmlElement hist_element(TEXT("")); TiXmlElement hist_element{TEXT("")};
hist_element.SetValue(TEXT("UserDefinePair")); hist_element.SetValue(TEXT("UserDefinePair"));
// remove all old sub-nodes // remove all old sub-nodes
@ -5566,7 +5540,7 @@ bool NppParameters::writeGUIParams()
GUIConfigElement->SetAttribute(TEXT("doubleQuotes"), _nppGUI._matchedPairConf._doDoubleQuotes?TEXT("yes"):TEXT("no")); GUIConfigElement->SetAttribute(TEXT("doubleQuotes"), _nppGUI._matchedPairConf._doDoubleQuotes?TEXT("yes"):TEXT("no"));
GUIConfigElement->SetAttribute(TEXT("htmlXmlTag"), _nppGUI._matchedPairConf._doHtmlXmlTag?TEXT("yes"):TEXT("no")); GUIConfigElement->SetAttribute(TEXT("htmlXmlTag"), _nppGUI._matchedPairConf._doHtmlXmlTag?TEXT("yes"):TEXT("no"));
TiXmlElement hist_element(TEXT("")); TiXmlElement hist_element{TEXT("")};
hist_element.SetValue(TEXT("UserDefinePair")); hist_element.SetValue(TEXT("UserDefinePair"));
for (size_t i = 0, nb = _nppGUI._matchedPairConf._matchedPairs.size(); i < nb; ++i) for (size_t i = 0, nb = _nppGUI._matchedPairConf._matchedPairs.size(); i < nb; ++i)
{ {
@ -5698,7 +5672,7 @@ bool NppParameters::writeFindHistory()
(findHistoryRoot->ToElement())->SetAttribute(TEXT("transparency"), _findHistory._transparency); (findHistoryRoot->ToElement())->SetAttribute(TEXT("transparency"), _findHistory._transparency);
(findHistoryRoot->ToElement())->SetAttribute(TEXT("dotMatchesNewline"), _findHistory._dotMatchesNewline?TEXT("yes"):TEXT("no")); (findHistoryRoot->ToElement())->SetAttribute(TEXT("dotMatchesNewline"), _findHistory._dotMatchesNewline?TEXT("yes"):TEXT("no"));
TiXmlElement hist_element(TEXT("")); TiXmlElement hist_element{TEXT("")};
hist_element.SetValue(TEXT("Path")); hist_element.SetValue(TEXT("Path"));
for (size_t i = 0, len = _findHistory._findHistoryPaths.size(); i < len; ++i) for (size_t i = 0, len = _findHistory._findHistoryPaths.size(); i < len; ++i)
@ -6203,7 +6177,7 @@ void NppParameters::insertUserLang2Tree(TiXmlNode *node, UserLangContainer *user
TiXmlElement *rootElement = (node->InsertEndChild(TiXmlElement(TEXT("UserLang"))))->ToElement(); TiXmlElement *rootElement = (node->InsertEndChild(TiXmlElement(TEXT("UserLang"))))->ToElement();
TCHAR temp[32]; TCHAR temp[32];
generic_string udlVersion = TEXT(""); generic_string udlVersion;
udlVersion += generic_itoa(SCE_UDL_VERSION_MAJOR, temp, 10); udlVersion += generic_itoa(SCE_UDL_VERSION_MAJOR, temp, 10);
udlVersion += TEXT("."); udlVersion += TEXT(".");
udlVersion += generic_itoa(SCE_UDL_VERSION_MINOR, temp, 10); udlVersion += generic_itoa(SCE_UDL_VERSION_MINOR, temp, 10);

View File

@ -923,11 +923,11 @@ bool FileManager::backupCurrentBuffer()
else // buffer not dirty, sync: delete the backup file else // buffer not dirty, sync: delete the backup file
{ {
generic_string backupFilePath = buffer->getBackupFileName(); generic_string backupFilePath = buffer->getBackupFileName();
if (backupFilePath != TEXT("")) if (not backupFilePath.empty())
{ {
// delete backup file // delete backup file
generic_string file2Delete = buffer->getBackupFileName(); generic_string file2Delete = buffer->getBackupFileName();
buffer->setBackupFileName(TEXT("")); buffer->setBackupFileName(generic_string());
result = (::DeleteFile(file2Delete.c_str()) != 0); result = (::DeleteFile(file2Delete.c_str()) != 0);
// Session changes, save it // Session changes, save it
@ -993,7 +993,7 @@ bool FileManager::deleteCurrentBufferBackup()
if (not backupFilePath.empty()) if (not backupFilePath.empty())
{ {
// delete backup file // delete backup file
buffer->setBackupFileName(TEXT("")); buffer->setBackupFileName(generic_string());
result = (::DeleteFile(backupFilePath.c_str()) != 0); result = (::DeleteFile(backupFilePath.c_str()) != 0);
} }
@ -1001,6 +1001,7 @@ bool FileManager::deleteCurrentBufferBackup()
return result; return result;
} }
bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, generic_string * error_msg) bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, generic_string * error_msg)
{ {
HANDLE writeEvent = ::OpenEvent(EVENT_ALL_ACCESS, TRUE, TEXT("nppWrittingEvent")); HANDLE writeEvent = ::OpenEvent(EVENT_ALL_ACCESS, TRUE, TEXT("nppWrittingEvent"));
@ -1115,11 +1116,11 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, g
/* for saveAs it's not necessary since this action is for the "current" directory, so we let manage in SAVEPOINTREACHED event /* for saveAs it's not necessary since this action is for the "current" directory, so we let manage in SAVEPOINTREACHED event
generic_string backupFilePath = buffer->getBackupFileName(); generic_string backupFilePath = buffer->getBackupFileName();
if (backupFilePath != TEXT("")) if (not backupFilePath.empty())
{ {
// delete backup file // delete backup file
generic_string file2Delete = buffer->getBackupFileName(); generic_string file2Delete = buffer->getBackupFileName();
buffer->setBackupFileName(TEXT("")); buffer->setBackupFileName(generic_string());
::DeleteFile(file2Delete.c_str()); ::DeleteFile(file2Delete.c_str());
} }
*/ */
@ -1140,7 +1141,7 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, g
if (not backupFilePath.empty()) if (not backupFilePath.empty())
{ {
// delete backup file // delete backup file
buffer->setBackupFileName(TEXT("")); buffer->setBackupFileName(generic_string());
::DeleteFile(backupFilePath.c_str()); ::DeleteFile(backupFilePath.c_str());
} }

View File

@ -699,12 +699,12 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
//Single actions //Single actions
case IDCANCEL: case IDCANCEL:
(*_ppEditView)->execute(SCI_CALLTIPCANCEL); (*_ppEditView)->execute(SCI_CALLTIPCANCEL);
setStatusbarMessage(TEXT(""), FSNoMessage); setStatusbarMessage(generic_string(), FSNoMessage);
display(false); display(false);
break; break;
case IDOK : // Find Next : only for FIND_DLG and REPLACE_DLG case IDOK : // Find Next : only for FIND_DLG and REPLACE_DLG
{ {
setStatusbarMessage(TEXT(""), FSNoMessage); setStatusbarMessage(generic_string(), FSNoMessage);
bool isUnicode = (*_ppEditView)->getCurrentBuffer()->getUnicodeMode() != uni8Bit; bool isUnicode = (*_ppEditView)->getCurrentBuffer()->getUnicodeMode() != uni8Bit;
HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT); HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT);
@ -2141,7 +2141,7 @@ void FindReplaceDlg::execSavedCommand(int cmd, int intValue, generic_string stri
(*_ppEditView)->execute(SCI_ENDUNDOACTION); (*_ppEditView)->execute(SCI_ENDUNDOACTION);
nppParamInst->_isFindReplacing = false; nppParamInst->_isFindReplacing = false;
generic_string result = TEXT(""); generic_string result;
if (nbReplaced < 0) if (nbReplaced < 0)
result = TEXT("Replace All: The regular expression is malformed."); result = TEXT("Replace All: The regular expression is malformed.");
@ -2161,7 +2161,7 @@ void FindReplaceDlg::execSavedCommand(int cmd, int intValue, generic_string stri
case IDCCOUNTALL : case IDCCOUNTALL :
{ {
int nbCounted = processAll(ProcessCountAll, _env); int nbCounted = processAll(ProcessCountAll, _env);
generic_string result = TEXT(""); generic_string result;
if (nbCounted < 0) if (nbCounted < 0)
result = TEXT("Count: The regular expression to search is malformed."); result = TEXT("Count: The regular expression to search is malformed.");
@ -2182,9 +2182,12 @@ void FindReplaceDlg::execSavedCommand(int cmd, int intValue, generic_string stri
nppParamInst->_isFindReplacing = true; nppParamInst->_isFindReplacing = true;
int nbMarked = processAll(ProcessMarkAll, _env); int nbMarked = processAll(ProcessMarkAll, _env);
nppParamInst->_isFindReplacing = false; nppParamInst->_isFindReplacing = false;
generic_string result = TEXT(""); generic_string result;
if (nbMarked < 0) if (nbMarked < 0)
{
result = TEXT("Mark: The regular expression to search is malformed."); result = TEXT("Mark: The regular expression to search is malformed.");
}
else else
{ {
TCHAR moreInfo[128]; TCHAR moreInfo[128];
@ -2194,6 +2197,7 @@ void FindReplaceDlg::execSavedCommand(int cmd, int intValue, generic_string stri
wsprintf(moreInfo, TEXT("%d matches."), nbMarked); wsprintf(moreInfo, TEXT("%d matches."), nbMarked);
result = moreInfo; result = moreInfo;
} }
setStatusbarMessage(result, FSMessage); setStatusbarMessage(result, FSMessage);
break; break;
} }

View File

@ -31,16 +31,17 @@
MenuItemUnit::MenuItemUnit(unsigned long cmdID, const TCHAR *itemName, const TCHAR *parentFolderName) : _cmdID(cmdID) MenuItemUnit::MenuItemUnit(unsigned long cmdID, const TCHAR *itemName, const TCHAR *parentFolderName) : _cmdID(cmdID)
{ {
if (!itemName) if (!itemName)
_itemName = TEXT(""); _itemName.clear();
else else
_itemName = itemName; _itemName = itemName;
if (!parentFolderName) if (!parentFolderName)
_parentFolderName = TEXT(""); _parentFolderName.clear();
else else
_parentFolderName = parentFolderName; _parentFolderName = parentFolderName;
} }
ContextMenu::~ContextMenu() ContextMenu::~ContextMenu()
{ {
if (isCreated()) if (isCreated())
@ -51,21 +52,22 @@ ContextMenu::~ContextMenu()
} }
} }
void ContextMenu::create(HWND hParent, const std::vector<MenuItemUnit> & menuItemArray, const HMENU mainMenuHandle) void ContextMenu::create(HWND hParent, const std::vector<MenuItemUnit> & menuItemArray, const HMENU mainMenuHandle)
{ {
_hParent = hParent; _hParent = hParent;
_hMenu = ::CreatePopupMenu(); _hMenu = ::CreatePopupMenu();
bool lastIsSep = false; bool lastIsSep = false;
HMENU hParentFolder = NULL; HMENU hParentFolder = NULL;
generic_string currentParentFolderStr = TEXT(""); generic_string currentParentFolderStr;
int j = 0; int j = 0;
for (size_t i = 0, len = menuItemArray.size(); i < len; ++i) for (size_t i = 0, len = menuItemArray.size(); i < len; ++i)
{ {
const MenuItemUnit & item = menuItemArray[i]; const MenuItemUnit & item = menuItemArray[i];
if (item._parentFolderName == TEXT("")) if (item._parentFolderName.empty())
{ {
currentParentFolderStr = TEXT(""); currentParentFolderStr.clear();
hParentFolder = NULL; hParentFolder = NULL;
j = 0; j = 0;
} }

View File

@ -24,53 +24,55 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#pragma once
#ifndef CONTEXTMENU_H
#define CONTEXTMENU_H
#include "Common.h" #include "Common.h"
struct MenuItemUnit {
unsigned long _cmdID;
struct MenuItemUnit final
{
unsigned long _cmdID = 0;
generic_string _itemName; generic_string _itemName;
generic_string _parentFolderName; generic_string _parentFolderName;
MenuItemUnit() : _cmdID(0), _itemName(TEXT("")), _parentFolderName(TEXT("")){};
MenuItemUnit(unsigned long cmdID, generic_string itemName, generic_string parentFolderName=TEXT("")) MenuItemUnit() = default;
MenuItemUnit(unsigned long cmdID, generic_string itemName, generic_string parentFolderName = generic_string())
: _cmdID(cmdID), _itemName(itemName), _parentFolderName(parentFolderName){}; : _cmdID(cmdID), _itemName(itemName), _parentFolderName(parentFolderName){};
MenuItemUnit(unsigned long cmdID, const TCHAR *itemName, const TCHAR *parentFolderName=NULL); MenuItemUnit(unsigned long cmdID, const TCHAR *itemName, const TCHAR *parentFolderName = nullptr);
}; };
class ContextMenu {
class ContextMenu final
{
public: public:
ContextMenu() : _hParent(NULL), _hMenu(NULL) {};
~ContextMenu(); ~ContextMenu();
void create(HWND hParent, const std::vector<MenuItemUnit> & menuItemArray, const HMENU mainMenuHandle = NULL); void create(HWND hParent, const std::vector<MenuItemUnit> & menuItemArray, const HMENU mainMenuHandle = NULL);
bool isCreated() const {return _hMenu != NULL;}; bool isCreated() const {return _hMenu != NULL;}
void display(const POINT & p) const { void display(const POINT & p) const {
::TrackPopupMenu(_hMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hParent, NULL); ::TrackPopupMenu(_hMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hParent, NULL);
}; }
void enableItem(int cmdID, bool doEnable) const { void enableItem(int cmdID, bool doEnable) const
int flag = doEnable?MF_ENABLED | MF_BYCOMMAND:MF_DISABLED | MF_GRAYED | MF_BYCOMMAND; {
int flag = doEnable ? (MF_ENABLED | MF_BYCOMMAND) : (MF_DISABLED | MF_GRAYED | MF_BYCOMMAND);
::EnableMenuItem(_hMenu, cmdID, flag); ::EnableMenuItem(_hMenu, cmdID, flag);
}; }
void checkItem(int cmdID, bool doCheck) const { void checkItem(int cmdID, bool doCheck) const
{
::CheckMenuItem(_hMenu, cmdID, MF_BYCOMMAND | (doCheck ? MF_CHECKED : MF_UNCHECKED)); ::CheckMenuItem(_hMenu, cmdID, MF_BYCOMMAND | (doCheck ? MF_CHECKED : MF_UNCHECKED));
}; }
HMENU getMenuHandle() { HMENU getMenuHandle() const
{
return _hMenu; return _hMenu;
}; }
private: private:
HWND _hParent; HWND _hParent = NULL;
HMENU _hMenu; HMENU _hMenu = NULL;
std::vector<HMENU> _subMenus; std::vector<HMENU> _subMenus;
}; };
#endif //CONTEXTMENU_H

View File

@ -1374,7 +1374,7 @@ void DockingCont::SelectTab(int iTab)
for (int iItem = 0; iItem < iItemCnt; ++iItem) for (int iItem = 0; iItem < iItemCnt; ++iItem)
{ {
generic_string szText(TEXT("")); generic_string szText;
if (iItem == iTab && pszMaxTxt) if (iItem == iTab && pszMaxTxt)
{ {
// fake here an icon before text ... // fake here an icon before text ...

View File

@ -41,23 +41,28 @@
#include "Common.h" #include "Common.h"
#include "StaticDialog.h" #include "StaticDialog.h"
class DockingDlgInterface : public StaticDialog class DockingDlgInterface : public StaticDialog
{ {
public: public:
DockingDlgInterface(): StaticDialog(), _HSource(NULL),\ DockingDlgInterface() = default;
_dlgID(-1), _isFloating(TRUE), _iDockedPos(0), _pluginName(TEXT("")) {};
DockingDlgInterface(int dlgID): StaticDialog(), _HSource(NULL),\ explicit DockingDlgInterface(int dlgID)
_dlgID(dlgID), _isFloating(TRUE), _iDockedPos(0), _pluginName(TEXT("")) {}; : _dlgID(dlgID)
{}
virtual void init(HINSTANCE hInst, HWND parent) {
virtual void init(HINSTANCE hInst, HWND parent)
{
StaticDialog::init(hInst, parent); StaticDialog::init(hInst, parent);
TCHAR temp[MAX_PATH]; TCHAR temp[MAX_PATH];
::GetModuleFileName((HMODULE)hInst, temp, MAX_PATH); ::GetModuleFileName((HMODULE)hInst, temp, MAX_PATH);
_moduleName = ::PathFindFileName(temp); _moduleName = ::PathFindFileName(temp);
}; }
void create(tTbData * data, bool isRTL = false){ void create(tTbData * data, bool isRTL = false)
{
StaticDialog::create(_dlgID, isRTL); StaticDialog::create(_dlgID, isRTL);
TCHAR temp[MAX_PATH]; TCHAR temp[MAX_PATH];
::GetWindowText(_hSelf, temp, MAX_PATH); ::GetWindowText(_hSelf, temp, MAX_PATH);
@ -71,36 +76,34 @@ public:
// additional info // additional info
data->pszAddInfo = NULL; data->pszAddInfo = NULL;
}; }
virtual void updateDockingDlg() { virtual void updateDockingDlg()
{
::SendMessage(_hParent, NPPM_DMMUPDATEDISPINFO, 0, (LPARAM)_hSelf); ::SendMessage(_hParent, NPPM_DMMUPDATEDISPINFO, 0, (LPARAM)_hSelf);
} }
virtual void destroy() { virtual void destroy() {}
};
virtual void setBackgroundColor(COLORREF) { virtual void setBackgroundColor(COLORREF) {}
};
virtual void setForegroundColor(COLORREF) { virtual void setForegroundColor(COLORREF) {}
};
virtual void display(bool toShow = true) const { virtual void display(bool toShow = true) const {
::SendMessage(_hParent, toShow?NPPM_DMMSHOW:NPPM_DMMHIDE, 0, (LPARAM)_hSelf); ::SendMessage(_hParent, toShow?NPPM_DMMSHOW:NPPM_DMMHIDE, 0, (LPARAM)_hSelf);
}; }
bool isClosed() const { bool isClosed() const {
return _isClosed; return _isClosed;
}; }
void setClosed(bool toClose) { void setClosed(bool toClose) {
_isClosed = toClose; _isClosed = toClose;
}; }
const TCHAR * getPluginFileName() const { const TCHAR * getPluginFileName() const {
return _moduleName.c_str(); return _moduleName.c_str();
}; }
protected : protected :
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM, LPARAM lParam) virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM, LPARAM lParam)
@ -144,13 +147,13 @@ protected :
}; };
// Handles // Handles
HWND _HSource; HWND _HSource = NULL;
int _dlgID; int _dlgID = -1;
bool _isFloating; bool _isFloating = true;
int _iDockedPos; int _iDockedPos = 0;
generic_string _moduleName; generic_string _moduleName;
generic_string _pluginName; generic_string _pluginName;
bool _isClosed; bool _isClosed = false;
}; };
#endif // DOCKINGDLGINTERFACE_H #endif // DOCKINGDLGINTERFACE_H

View File

@ -358,7 +358,7 @@ void FunctionParser::funcParse(std::vector<foundInfo> & foundInfos, size_t begin
fi._pos = foundPos; fi._pos = foundPos;
} }
if (classStructName != TEXT("")) if (not classStructName.empty())
{ {
fi._data2 = classStructName; fi._data2 = classStructName;
fi._pos2 = -1; // change -1 valeur for validated data2 fi._pos2 = -1; // change -1 valeur for validated data2
@ -378,26 +378,25 @@ void FunctionParser::funcParse(std::vector<foundInfo> & foundInfos, size_t begin
foundInfos.push_back(fi); foundInfos.push_back(fi);
} }
else else
{
foundInfos.push_back(fi); foundInfos.push_back(fi);
} }
}
begin = targetStart + foundTextLen; begin = targetStart + foundTextLen;
targetStart = (*ppEditView)->searchInTarget(_functionExpr.c_str(), _functionExpr.length(), begin, end); targetStart = (*ppEditView)->searchInTarget(_functionExpr.c_str(), _functionExpr.length(), begin, end);
} }
} }
generic_string FunctionParser::parseSubLevel(size_t begin, size_t end, std::vector< generic_string > dataToSearch, int & foundPos, ScintillaEditView **ppEditView) generic_string FunctionParser::parseSubLevel(size_t begin, size_t end, std::vector< generic_string > dataToSearch, int & foundPos, ScintillaEditView **ppEditView)
{ {
if (begin >= end) if (begin >= end)
{ {
foundPos = -1; foundPos = -1;
return TEXT(""); return generic_string();
} }
if (!dataToSearch.size()) if (!dataToSearch.size())
return TEXT(""); return generic_string();
int flags = SCFIND_REGEXP | SCFIND_POSIX | SCFIND_REGEXP_DOTMATCHESNL; int flags = SCFIND_REGEXP | SCFIND_POSIX | SCFIND_REGEXP_DOTMATCHESNL;
@ -408,7 +407,7 @@ generic_string FunctionParser::parseSubLevel(size_t begin, size_t end, std::vect
if (targetStart == -1 || targetStart == -2) if (targetStart == -1 || targetStart == -2)
{ {
foundPos = -1; foundPos = -1;
return TEXT(""); return generic_string();
} }
int targetEnd = int((*ppEditView)->execute(SCI_GETTARGETEND)); int targetEnd = int((*ppEditView)->execute(SCI_GETTARGETEND));
@ -417,16 +416,15 @@ generic_string FunctionParser::parseSubLevel(size_t begin, size_t end, std::vect
dataToSearch.erase(dataToSearch.begin()); dataToSearch.erase(dataToSearch.begin());
return parseSubLevel(targetStart, targetEnd, dataToSearch, foundPos, ppEditView); return parseSubLevel(targetStart, targetEnd, dataToSearch, foundPos, ppEditView);
} }
else // only one processed element, so we conclude the result
{
TCHAR foundStr[1024];
// only one processed element, so we conclude the result
TCHAR foundStr[1024];
(*ppEditView)->getGenericText(foundStr, 1024, targetStart, targetEnd); (*ppEditView)->getGenericText(foundStr, 1024, targetStart, targetEnd);
foundPos = targetStart; foundPos = targetStart;
return foundStr; return foundStr;
} }
}
bool FunctionParsersManager::parse(std::vector<foundInfo> & foundInfos, const AssociationInfo & assoInfo) bool FunctionParsersManager::parse(std::vector<foundInfo> & foundInfos, const AssociationInfo & assoInfo)
{ {
@ -445,6 +443,7 @@ bool FunctionParsersManager::parse(std::vector<foundInfo> & foundInfos, const As
return true; return true;
} }
size_t FunctionZoneParser::getBodyClosePos(size_t begin, const TCHAR *bodyOpenSymbol, const TCHAR *bodyCloseSymbol, const std::vector< std::pair<int, int> > & commentZones, ScintillaEditView **ppEditView) size_t FunctionZoneParser::getBodyClosePos(size_t begin, const TCHAR *bodyOpenSymbol, const TCHAR *bodyCloseSymbol, const std::vector< std::pair<int, int> > & commentZones, ScintillaEditView **ppEditView)
{ {
size_t cntOpen = 1; size_t cntOpen = 1;
@ -522,15 +521,13 @@ void FunctionZoneParser::classParse(vector<foundInfo> & foundInfos, vector< pair
generic_string classStructName = parseSubLevel(targetStart, targetEnd, _classNameExprArray, foundPos, ppEditView); generic_string classStructName = parseSubLevel(targetStart, targetEnd, _classNameExprArray, foundPos, ppEditView);
if (_openSymbole != TEXT("") && _closeSymbole != TEXT("")) if (not _openSymbole.empty() && not _closeSymbole.empty())
{ {
targetEnd = getBodyClosePos(targetEnd, _openSymbole.c_str(), _closeSymbole.c_str(), commentZones, ppEditView); targetEnd = getBodyClosePos(targetEnd, _openSymbole.c_str(), _closeSymbole.c_str(), commentZones, ppEditView);
} }
if (targetEnd > int(end)) //we found a result but outside our range, therefore do not process it if (targetEnd > int(end)) //we found a result but outside our range, therefore do not process it
{
break; break;
}
scannedZones.push_back(pair<int, int>(targetStart, targetEnd)); scannedZones.push_back(pair<int, int>(targetStart, targetEnd));
@ -549,12 +546,11 @@ void FunctionZoneParser::classParse(vector<foundInfo> & foundInfos, vector< pair
} }
} }
void FunctionParser::getCommentZones(vector< pair<int, int> > & commentZone, size_t begin, size_t end, ScintillaEditView **ppEditView) void FunctionParser::getCommentZones(vector< pair<int, int> > & commentZone, size_t begin, size_t end, ScintillaEditView **ppEditView)
{ {
if ((begin >= end) || (_commentExpr == TEXT(""))) if ((begin >= end) || (_commentExpr.empty()))
{
return; return;
}
int flags = SCFIND_REGEXP | SCFIND_POSIX | SCFIND_REGEXP_DOTMATCHESNL; int flags = SCFIND_REGEXP | SCFIND_POSIX | SCFIND_REGEXP_DOTMATCHESNL;
@ -567,9 +563,7 @@ void FunctionParser::getCommentZones(vector< pair<int, int> > & commentZone, siz
targetStart = int((*ppEditView)->execute(SCI_GETTARGETSTART)); targetStart = int((*ppEditView)->execute(SCI_GETTARGETSTART));
targetEnd = int((*ppEditView)->execute(SCI_GETTARGETEND)); targetEnd = int((*ppEditView)->execute(SCI_GETTARGETEND));
if (targetEnd > int(end)) //we found a result but outside our range, therefore do not process it if (targetEnd > int(end)) //we found a result but outside our range, therefore do not process it
{
break; break;
}
commentZone.push_back(pair<int, int>(targetStart, targetEnd)); commentZone.push_back(pair<int, int>(targetStart, targetEnd));
@ -582,18 +576,18 @@ void FunctionParser::getCommentZones(vector< pair<int, int> > & commentZone, siz
} }
} }
bool FunctionParser::isInZones(int pos2Test, const std::vector< std::pair<int, int> > & zones) bool FunctionParser::isInZones(int pos2Test, const std::vector< std::pair<int, int> > & zones)
{ {
for (size_t i = 0, len = zones.size(); i < len; ++i) for (size_t i = 0, len = zones.size(); i < len; ++i)
{ {
if (pos2Test >= zones[i].first && pos2Test < zones[i].second) if (pos2Test >= zones[i].first && pos2Test < zones[i].second)
{
return true; return true;
} }
}
return false; return false;
} }
void FunctionParser::getInvertZones(vector< pair<int, int> > & destZones, vector< pair<int, int> > & sourceZones, size_t begin, size_t end) void FunctionParser::getInvertZones(vector< pair<int, int> > & destZones, vector< pair<int, int> > & sourceZones, size_t begin, size_t end)
{ {
if (sourceZones.size() == 0) if (sourceZones.size() == 0)
@ -622,6 +616,7 @@ void FunctionParser::getInvertZones(vector< pair<int, int> > & destZones, vecto
} }
} }
void FunctionZoneParser::parse(std::vector<foundInfo> & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName) void FunctionZoneParser::parse(std::vector<foundInfo> & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName)
{ {
vector< pair<int, int> > classZones, commentZones, nonCommentZones; vector< pair<int, int> > classZones, commentZones, nonCommentZones;
@ -647,8 +642,10 @@ void FunctionUnitParser::parse(std::vector<foundInfo> & foundInfos, size_t begin
// //
// SortClass for vector<pair<int, int>> // SortClass for vector<pair<int, int>>
// sort in _selLpos : increased order // sort in _selLpos : increased order
struct SortZones { struct SortZones final
bool operator() (pair<int, int> & l, pair<int, int> & r) { {
bool operator() (pair<int, int> & l, pair<int, int> & r)
{
return (l.first < r.first); return (l.first < r.first);
} }
}; };

View File

@ -24,23 +24,23 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#pragma once;
#ifndef FUNCTIONPARSER_H
#define FUNCTIONPARSER_H
class ScintillaEditView; class ScintillaEditView;
class TiXmlDocument; class TiXmlDocument;
class TiXmlNode; class TiXmlNode;
struct foundInfo {
struct foundInfo final
{
generic_string _data; generic_string _data;
generic_string _data2; generic_string _data2;
int _pos; int _pos = -1;
int _pos2; int _pos2 = -1;
foundInfo(): _data(TEXT("")), _data2(TEXT("")), _pos(-1), _pos2(-1) {};
}; };
class FunctionParser { class FunctionParser
{
friend class FunctionParsersManager; friend class FunctionParsersManager;
public: public:
FunctionParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr, generic_string functionExpr, std::vector<generic_string> functionNameExprArray, std::vector<generic_string> classNameExprArray): FunctionParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr, generic_string functionExpr, std::vector<generic_string> functionNameExprArray, std::vector<generic_string> classNameExprArray):
@ -62,7 +62,8 @@ protected:
}; };
class FunctionZoneParser : public FunctionParser { class FunctionZoneParser : public FunctionParser
{
public: public:
FunctionZoneParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr, generic_string rangeExpr, generic_string openSymbole, generic_string closeSymbole, FunctionZoneParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr, generic_string rangeExpr, generic_string openSymbole, generic_string closeSymbole,
std::vector<generic_string> classNameExprArray, generic_string functionExpr, std::vector<generic_string> functionNameExprArray): std::vector<generic_string> classNameExprArray, generic_string functionExpr, std::vector<generic_string> functionNameExprArray):
@ -84,70 +85,77 @@ private:
class FunctionUnitParser : public FunctionParser { class FunctionUnitParser : public FunctionParser
{
public: public:
FunctionUnitParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr, FunctionUnitParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr,
generic_string mainExpr, std::vector<generic_string> functionNameExprArray, generic_string mainExpr, std::vector<generic_string> functionNameExprArray,
std::vector<generic_string> classNameExprArray): FunctionParser(id, displayName, commentExpr, mainExpr, functionNameExprArray, classNameExprArray){}; std::vector<generic_string> classNameExprArray): FunctionParser(id, displayName, commentExpr, mainExpr, functionNameExprArray, classNameExprArray)
{}
void parse(std::vector<foundInfo> & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName = TEXT("")); void parse(std::vector<foundInfo> & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName = TEXT(""));
}; };
class FunctionMixParser : public FunctionZoneParser { class FunctionMixParser : public FunctionZoneParser
{
public: public:
FunctionMixParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr, generic_string rangeExpr, generic_string openSymbole, generic_string closeSymbole, FunctionMixParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr, generic_string rangeExpr, generic_string openSymbole, generic_string closeSymbole,
std::vector<generic_string> classNameExprArray, generic_string functionExpr, std::vector<generic_string> functionNameExprArray, FunctionUnitParser *funcUnitPaser): std::vector<generic_string> classNameExprArray, generic_string functionExpr, std::vector<generic_string> functionNameExprArray, FunctionUnitParser *funcUnitPaser):
FunctionZoneParser(id, displayName, commentExpr, rangeExpr, openSymbole, closeSymbole, classNameExprArray, functionExpr, functionNameExprArray), _funcUnitPaser(funcUnitPaser){}; FunctionZoneParser(id, displayName, commentExpr, rangeExpr, openSymbole, closeSymbole, classNameExprArray, functionExpr, functionNameExprArray), _funcUnitPaser(funcUnitPaser){};
~FunctionMixParser() { ~FunctionMixParser()
if (_funcUnitPaser) {
delete _funcUnitPaser; delete _funcUnitPaser;
} }
void parse(std::vector<foundInfo> & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName = TEXT("")); void parse(std::vector<foundInfo> & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName = TEXT(""));
private: private:
FunctionUnitParser *_funcUnitPaser; FunctionUnitParser* _funcUnitPaser = nullptr;
}; };
struct AssociationInfo {
struct AssociationInfo final
{
int _id; int _id;
int _langID; int _langID;
generic_string _ext; generic_string _ext;
generic_string _userDefinedLangName; generic_string _userDefinedLangName;
AssociationInfo(int id, int langID, const TCHAR *ext, const TCHAR *userDefinedLangName): _id(id), _langID(langID) { AssociationInfo(int id, int langID, const TCHAR *ext, const TCHAR *userDefinedLangName)
: _id(id), _langID(langID)
{
if (ext) if (ext)
_ext = ext; _ext = ext;
else else
_ext = TEXT(""); _ext.clear();
if (userDefinedLangName) if (userDefinedLangName)
_userDefinedLangName = userDefinedLangName; _userDefinedLangName = userDefinedLangName;
else else
_userDefinedLangName = TEXT(""); _userDefinedLangName.clear();
}; };
}; };
class FunctionParsersManager {
class FunctionParsersManager final
{
public: public:
FunctionParsersManager() : _ppEditView(NULL), _pXmlFuncListDoc(NULL){};
~FunctionParsersManager(); ~FunctionParsersManager();
bool init(generic_string xmlPath, ScintillaEditView ** ppEditView); bool init(generic_string xmlPath, ScintillaEditView ** ppEditView);
bool parse(std::vector<foundInfo> & foundInfos, const AssociationInfo & assoInfo); bool parse(std::vector<foundInfo> & foundInfos, const AssociationInfo & assoInfo);
void writeFunctionListXml(const TCHAR *destFoder) const; void writeFunctionListXml(const TCHAR *destFoder) const;
private: private:
ScintillaEditView **_ppEditView; ScintillaEditView **_ppEditView = nullptr;
std::vector<FunctionParser *> _parsers; std::vector<FunctionParser *> _parsers;
std::vector<AssociationInfo> _associationMap; std::vector<AssociationInfo> _associationMap;
TiXmlDocument *_pXmlFuncListDoc; TiXmlDocument *_pXmlFuncListDoc = nullptr;
bool getFuncListFromXmlTree(); bool getFuncListFromXmlTree();
bool getZonePaserParameters(TiXmlNode *classRangeParser, generic_string &mainExprStr, generic_string &openSymboleStr, generic_string &closeSymboleStr, std::vector<generic_string> &classNameExprArray, generic_string &functionExprStr, std::vector<generic_string> &functionNameExprArray); bool getZonePaserParameters(TiXmlNode *classRangeParser, generic_string &mainExprStr, generic_string &openSymboleStr, generic_string &closeSymboleStr, std::vector<generic_string> &classNameExprArray, generic_string &functionExprStr, std::vector<generic_string> &functionNameExprArray);
bool getUnitPaserParameters(TiXmlNode *functionParser, generic_string &mainExprStr, std::vector<generic_string> &functionNameExprArray, std::vector<generic_string> &classNameExprArray); bool getUnitPaserParameters(TiXmlNode *functionParser, generic_string &mainExprStr, std::vector<generic_string> &functionNameExprArray, std::vector<generic_string> &classNameExprArray);
FunctionParser * getParser(const AssociationInfo & assoInfo); FunctionParser * getParser(const AssociationInfo & assoInfo);
}; };
#endif //FUNCTIONPARSER_H