Code quality improvement: pass string by reference instead of value

Also remove not implemented methods addBufferToView(), moveBuffer() and doActionOrNot() from Notepad_plus.h

Close #5784
This commit is contained in:
Rajendra Singh 2019-06-13 21:24:42 +05:30 committed by Don HO
parent 57a49c3ba5
commit 9539a892eb
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
22 changed files with 49 additions and 52 deletions

View File

@ -5026,7 +5026,7 @@ bool Notepad_plus::str2Cliboard(const generic_string & str2cpy)
//ONLY CALL IN CASE OF EMERGENCY: EXCEPTION
//This function is destructive
bool Notepad_plus::emergency(generic_string emergencySavedDir)
bool Notepad_plus::emergency(const generic_string& emergencySavedDir)
{
::CreateDirectory(emergencySavedDir.c_str(), NULL);
return dumpFiles(emergencySavedDir.c_str(), TEXT("File"));

View File

@ -197,8 +197,6 @@ public:
bool fileDelete(BufferID id = BUFFER_INVALID);
bool fileRename(BufferID id = BUFFER_INVALID);
bool addBufferToView(BufferID id, int whichOne);
bool moveBuffer(BufferID id, int whereTo); //assumes whereFrom is otherView(whereTo)
bool switchToFile(BufferID buffer); //find buffer in active view then in other view.
//@}
@ -246,7 +244,7 @@ public:
HACCEL getAccTable() const{
return _accelerator.getAccTable();
}
bool emergency(generic_string emergencySavedDir);
bool emergency(const generic_string& emergencySavedDir);
Buffer* getCurrentBuffer() {
return _pEditView->getCurrentBuffer();
}
@ -447,7 +445,6 @@ private:
int doReloadOrNot(const TCHAR *fn, bool dirty);
int doCloseOrNot(const TCHAR *fn);
int doDeleteOrNot(const TCHAR *fn);
int doActionOrNot(const TCHAR *title, const TCHAR *displayText, int type);
void enableMenu(int cmdID, bool doEnable) const;
void enableCommand(int cmdID, bool doEnable, int which) const;
@ -570,7 +567,7 @@ private:
int getLangFromMenuName(const TCHAR * langName);
generic_string getLangFromMenu(const Buffer * buf);
generic_string exts2Filters(generic_string exts) const;
generic_string exts2Filters(const generic_string& exts) const;
int setFileOpenSaveDlgFilters(FileDialog & fDlg, int langType = -1);
Style * getStyleFromName(const TCHAR *styleName);
bool dumpFiles(const TCHAR * outdir, const TCHAR * fileprefix = TEXT("")); //helper func

View File

@ -77,7 +77,7 @@ public:
return _notepad_plus_plus_core.getAccTable();
}
bool emergency(generic_string emergencySavedDir)
bool emergency(const generic_string& emergencySavedDir)
{
return _notepad_plus_plus_core.emergency(emergencySavedDir);
}

View File

@ -728,7 +728,7 @@ void Notepad_plus::doClose(BufferID id, int whichOne, bool doDeleteBackup)
return;
}
generic_string Notepad_plus::exts2Filters(generic_string exts) const
generic_string Notepad_plus::exts2Filters(const generic_string& exts) const
{
const TCHAR *extStr = exts.c_str();
TCHAR aExt[MAX_PATH];

View File

@ -691,7 +691,7 @@ std::wstring LocalizationSwitcher::getXmlFilePathFromLangName(const wchar_t *lan
}
bool LocalizationSwitcher::addLanguageFromXml(wstring xmlFullPath)
bool LocalizationSwitcher::addLanguageFromXml(const std::wstring& xmlFullPath)
{
wchar_t * fn = ::PathFindFileNameW(xmlFullPath.c_str());
wstring foundLang = getLangFromXmlFileName(fn);
@ -1599,7 +1599,7 @@ void NppParameters::setFontList(HWND hWnd)
::EnumFontFamiliesEx(hDC, &lf, EnumFontFamExProc, reinterpret_cast<LPARAM>(&_fontlist), 0);
}
bool NppParameters::isInFontList(const generic_string fontName2Search) const
bool NppParameters::isInFontList(const generic_string& fontName2Search) const
{
if (fontName2Search.empty())
return false;
@ -1826,7 +1826,7 @@ bool NppParameters::reloadContextMenuFromXmlTree(HMENU mainMenuHadle, HMENU plug
return getContextMenuFromXmlTree(mainMenuHadle, pluginsMenu);
}
int NppParameters::getCmdIdFromMenuEntryItemName(HMENU mainMenuHadle, generic_string menuEntryName, generic_string menuItemName)
int NppParameters::getCmdIdFromMenuEntryItemName(HMENU mainMenuHadle, const generic_string& menuEntryName, const generic_string& menuItemName)
{
int nbMenuEntry = ::GetMenuItemCount(mainMenuHadle);
for (int i = 0; i < nbMenuEntry; ++i)
@ -1886,7 +1886,7 @@ int NppParameters::getCmdIdFromMenuEntryItemName(HMENU mainMenuHadle, generic_st
return -1;
}
int NppParameters::getPluginCmdIdFromMenuEntryItemName(HMENU pluginsMenu, generic_string pluginName, generic_string pluginCmdName)
int NppParameters::getPluginCmdIdFromMenuEntryItemName(HMENU pluginsMenu, const generic_string& pluginName, const generic_string& pluginCmdName)
{
int nbPlugins = ::GetMenuItemCount(pluginsMenu);
for (int i = 0; i < nbPlugins; ++i)
@ -2676,7 +2676,7 @@ std::pair<unsigned char, unsigned char> NppParameters::feedUserLang(TiXmlNode *n
return pair<unsigned char, unsigned char>(iBegin, iEnd);
}
bool NppParameters::importUDLFromFile(generic_string sourceFile)
bool NppParameters::importUDLFromFile(const generic_string& sourceFile)
{
TiXmlDocument *pXmlUserLangDoc = new TiXmlDocument(sourceFile);
bool loadOkay = pXmlUserLangDoc->LoadFile();
@ -2696,7 +2696,7 @@ bool NppParameters::importUDLFromFile(generic_string sourceFile)
return loadOkay;
}
bool NppParameters::exportUDLToFile(size_t langIndex2export, generic_string fileName2save)
bool NppParameters::exportUDLToFile(size_t langIndex2export, const generic_string& fileName2save)
{
if (langIndex2export >= NB_MAX_USER_LANG)
return false;

View File

@ -620,7 +620,7 @@ struct LangMenuItem final
int _cmdID;
generic_string _langName;
LangMenuItem(LangType lt, int cmdID = 0, generic_string langName = TEXT("")):
LangMenuItem(LangType lt, int cmdID = 0, const generic_string& langName = TEXT("")):
_langType(lt), _cmdID(cmdID), _langName(langName){};
};
@ -1170,7 +1170,7 @@ public:
const wchar_t *_xmlFileName;
};
bool addLanguageFromXml(std::wstring xmlFullPath);
bool addLanguageFromXml(const std::wstring& xmlFullPath);
std::wstring getLangFromXmlFileName(const wchar_t *fn) const;
std::wstring getXmlFilePathFromLangName(const wchar_t *langName) const;
@ -1211,12 +1211,12 @@ class ThemeSwitcher final
friend class NppParameters;
public:
void addThemeFromXml(generic_string xmlFullPath)
void addThemeFromXml(const generic_string& xmlFullPath)
{
_themeList.push_back(std::pair<generic_string, generic_string>(getThemeFromXmlFileName(xmlFullPath.c_str()), xmlFullPath));
}
void addDefaultThemeFromXml(generic_string xmlFullPath)
void addDefaultThemeFromXml(const generic_string& xmlFullPath)
{
_themeList.push_back(std::pair<generic_string, generic_string>(TEXT("Default (stylers.xml)"), xmlFullPath));
}
@ -1407,7 +1407,7 @@ public:
void setCurLineHilitingColour(COLORREF colour2Set);
void setFontList(HWND hWnd);
bool isInFontList(const generic_string fontName2Search) const;
bool isInFontList(const generic_string& fontName2Search) const;
const std::vector<generic_string>& getFontList() const { return _fontlist; }
int getNbUserLang() const {return _nbUserLang;}
@ -1519,7 +1519,7 @@ public:
void setWorkingDir(const TCHAR * newPath);
void setStartWithLocFileName(generic_string locPath) {
void setStartWithLocFileName(const generic_string& locPath) {
_startWithLocFileName = locPath;
};
@ -1585,8 +1585,8 @@ public:
}
PluginList & getPluginList() {return _pluginList;};
bool importUDLFromFile(generic_string sourceFile);
bool exportUDLToFile(size_t langIndex2export, generic_string fileName2save);
bool importUDLFromFile(const generic_string& sourceFile);
bool exportUDLToFile(size_t langIndex2export, const generic_string& fileName2save);
NativeLangSpeaker* getNativeLangSpeaker() {
return _pNativeLangSpeaker;
}
@ -1827,8 +1827,8 @@ private:
void writePrintSetting(TiXmlElement *element);
void initMenuKeys(); //initialise menu keys and scintilla keys. Other keys are initialized on their own
void initScintillaKeys(); //these functions have to be called first before any modifications are loaded
int getCmdIdFromMenuEntryItemName(HMENU mainMenuHadle, generic_string menuEntryName, generic_string menuItemName); // return -1 if not found
int getPluginCmdIdFromMenuEntryItemName(HMENU pluginsMenu, generic_string pluginName, generic_string pluginCmdName); // return -1 if not found
int getCmdIdFromMenuEntryItemName(HMENU mainMenuHadle, const generic_string& menuEntryName, const generic_string& menuItemName); // return -1 if not found
int getPluginCmdIdFromMenuEntryItemName(HMENU pluginsMenu, const generic_string& pluginName, const generic_string& pluginCmdName); // return -1 if not found
winVer getWindowsVersion();
};

View File

@ -33,7 +33,7 @@
using namespace std;
static bool isInList(generic_string word, const vector<generic_string> & wordArray)
static bool isInList(const generic_string& word, const vector<generic_string> & wordArray)
{
for (size_t i = 0, len = wordArray.size(); i < len; ++i)
if (wordArray[i] == word)
@ -171,7 +171,7 @@ void AutoCompletion::getWordArray(vector<generic_string> & wordArray, TCHAR *beg
}
}
static generic_string addTrailingSlash(generic_string path)
static generic_string addTrailingSlash(const generic_string& path)
{
if (path.length() >=1 && path[path.length() - 1] == '\\')
return path;
@ -179,7 +179,7 @@ static generic_string addTrailingSlash(generic_string path)
return path + L"\\";
}
static generic_string removeTrailingSlash(generic_string path)
static generic_string removeTrailingSlash(const generic_string& path)
{
if (path.length() >= 1 && path[path.length() - 1] == '\\')
return path.substr(0, path.length() - 1);
@ -187,13 +187,13 @@ static generic_string removeTrailingSlash(generic_string path)
return path;
}
static bool isDirectory(generic_string path)
static bool isDirectory(const generic_string& path)
{
DWORD type = ::GetFileAttributes(path.c_str());
return type != INVALID_FILE_ATTRIBUTES && (type & FILE_ATTRIBUTE_DIRECTORY);
}
static bool isFile(generic_string path)
static bool isFile(const generic_string& path)
{
DWORD type = ::GetFileAttributes(path.c_str());
return type != INVALID_FILE_ATTRIBUTES && ! (type & FILE_ATTRIBUTE_DIRECTORY);
@ -205,7 +205,7 @@ static bool isAllowedBeforeDriveLetter(TCHAR c)
return c == '\'' || c == '"' || c == '(' || std::isspace(c, loc);
}
static bool getRawPath(generic_string input, generic_string &rawPath_out)
static bool getRawPath(const generic_string& input, generic_string &rawPath_out)
{
// Try to find a path in the given input.
// Algorithm: look for a colon. The colon must be preceded by an alphabetic character.
@ -226,7 +226,7 @@ static bool getRawPath(generic_string input, generic_string &rawPath_out)
return true;
}
static bool getPathsForPathCompletion(generic_string input, generic_string &rawPath_out, generic_string &pathToMatch_out)
static bool getPathsForPathCompletion(const generic_string& input, generic_string &rawPath_out, generic_string &pathToMatch_out)
{
generic_string rawPath;
if (! getRawPath(input, rawPath))

View File

@ -326,7 +326,7 @@ public:
bool isModified() const { return _isModified; }
void setModifiedStatus(bool isModified) { _isModified = isModified; }
generic_string getBackupFileName() const { return _backupFileName; }
void setBackupFileName(generic_string fileName) { _backupFileName = fileName; }
void setBackupFileName(const generic_string& fileName) { _backupFileName = fileName; }
FILETIME getLastModifiedTimestamp() const { return _timeStamp; }
bool isLoadedDirty() const

View File

@ -2570,7 +2570,7 @@ void FindReplaceDlg::setStatusbarMessage(const generic_string & msg, FindStatus
}
}
void FindReplaceDlg::execSavedCommand(int cmd, uptr_t intValue, generic_string stringValue)
void FindReplaceDlg::execSavedCommand(int cmd, uptr_t intValue, const generic_string& stringValue)
{
try
{

View File

@ -329,7 +329,7 @@ public :
}
};
void execSavedCommand(int cmd, uptr_t intValue, generic_string stringValue);
void execSavedCommand(int cmd, uptr_t intValue, const generic_string& stringValue);
void setStatusbarMessage(const generic_string & msg, FindStatus staus);
Finder * createFinder();
bool removeFinder(Finder *finder2remove);

View File

@ -74,7 +74,7 @@ class DebugInfoDlg : public StaticDialog
public:
DebugInfoDlg() : StaticDialog() {};
void init(HINSTANCE hInst, HWND parent, bool isAdmin, generic_string loadedPlugins) {
void init(HINSTANCE hInst, HWND parent, bool isAdmin, const generic_string& loadedPlugins) {
_isAdmin = isAdmin;
_loadedPlugins = loadedPlugins;
Window::init(hInst, parent);

View File

@ -482,7 +482,7 @@ void WordStyleDlg::loadLangListFromNppParam()
setStyleListFromLexer(index2Begin);
}
void WordStyleDlg::updateThemeName(generic_string themeName)
void WordStyleDlg::updateThemeName(const generic_string& themeName)
{
NppParameters *pNppParam = NppParameters::getInstance();
NppGUI & nppGUI = (NppGUI & )pNppParam->getNppGUI();

View File

@ -182,7 +182,7 @@ private :
void updateFontSize();
void updateUserKeywords();
void switchToTheme();
void updateThemeName(generic_string themeName);
void updateThemeName(const generic_string& themeName);
void loadLangListFromNppParam();

View File

@ -36,7 +36,7 @@ struct MenuItemUnit final
generic_string _parentFolderName;
MenuItemUnit() = default;
MenuItemUnit(unsigned long cmdID, generic_string itemName, generic_string parentFolderName = generic_string())
MenuItemUnit(unsigned long cmdID, const generic_string& itemName, const generic_string& parentFolderName = generic_string())
: _cmdID(cmdID), _itemName(itemName), _parentFolderName(parentFolderName){};
MenuItemUnit(unsigned long cmdID, const TCHAR *itemName, const TCHAR *parentFolderName = nullptr);
};

View File

@ -990,7 +990,7 @@ HTREEITEM FileBrowser::getRootFromFullPath(const generic_string & rootPath) cons
return node;
}
HTREEITEM FileBrowser::findChildNodeFromName(HTREEITEM parent, generic_string label)
HTREEITEM FileBrowser::findChildNodeFromName(HTREEITEM parent, const generic_string& label)
{
HTREEITEM childNodeFound = nullptr;

View File

@ -147,7 +147,7 @@ public:
void addRootFolder(generic_string);
HTREEITEM getRootFromFullPath(const generic_string & rootPath) const;
HTREEITEM findChildNodeFromName(HTREEITEM parent, generic_string);
HTREEITEM findChildNodeFromName(HTREEITEM parent, const generic_string&);
bool addInTree(const generic_string& rootPath, const generic_string& addItemFullPath, HTREEITEM node, std::vector<generic_string> linarPathArray);
HTREEITEM findInTree(const generic_string& rootPath, HTREEITEM node, std::vector<generic_string> linarPathArray);

View File

@ -78,7 +78,7 @@ Version::Version(const generic_string& versionStr)
}
}
void Version::setVersionFrom(generic_string filePath)
void Version::setVersionFrom(const generic_string& filePath)
{
if (not filePath.empty() && ::PathFileExists(filePath.c_str()))
{
@ -215,7 +215,7 @@ bool findStrNoCase(const generic_string & strHaystack, const generic_string & st
return (it != strHaystack.end());
}
bool PluginsAdminDlg::isFoundInAvailableListFromIndex(int index, generic_string str2search, bool inWhichPart) const
bool PluginsAdminDlg::isFoundInAvailableListFromIndex(int index, const generic_string& str2search, bool inWhichPart) const
{
PluginUpdateInfo* pui = _availableList.getPluginInfoFromUiIndex(index);
generic_string searchIn;
@ -227,7 +227,7 @@ bool PluginsAdminDlg::isFoundInAvailableListFromIndex(int index, generic_string
return (findStrNoCase(searchIn, str2search));
}
long PluginsAdminDlg::searchFromCurrentSel(generic_string str2search, bool inWhichPart, bool isNextMode) const
long PluginsAdminDlg::searchFromCurrentSel(const generic_string& str2search, bool inWhichPart, bool isNextMode) const
{
// search from curent selected item or from the beginning
long currentIndex = _availableList.getSelectedIndex();

View File

@ -47,7 +47,7 @@ struct Version
Version() {};
Version(const generic_string& versionStr);
void setVersionFrom(generic_string filePath);
void setVersionFrom(const generic_string& filePath);
generic_string toString();
bool isNumber(const generic_string& s) const {
return !s.empty() &&
@ -229,13 +229,13 @@ private :
bool searchInPlugins(bool isNextMode) const;
const bool _inNames = true;
const bool _inDescs = false;
bool isFoundInAvailableListFromIndex(int index, generic_string str2search, bool inWhichPart) const;
long searchFromCurrentSel(generic_string str2search, bool inWhichPart, bool isNextMode) const;
long searchInNamesFromCurrentSel(generic_string str2search, bool isNextMode) const {
bool isFoundInAvailableListFromIndex(int index, const generic_string& str2search, bool inWhichPart) const;
long searchFromCurrentSel(const generic_string& str2search, bool inWhichPart, bool isNextMode) const;
long searchInNamesFromCurrentSel(const generic_string& str2search, bool isNextMode) const {
return searchFromCurrentSel(str2search, _inNames, isNextMode);
};
long searchInDescsFromCurrentSel(generic_string str2search, bool isNextMode) const {
long searchInDescsFromCurrentSel(const generic_string& str2search, bool isNextMode) const {
return searchFromCurrentSel(str2search, _inDescs, isNextMode);
};

View File

@ -70,7 +70,7 @@ struct LangID_Name
{
LangType _id;
generic_string _name;
LangID_Name(LangType id, generic_string name) : _id(id), _name(name){};
LangID_Name(LangType id, const generic_string& name) : _id(id), _name(name){};
};
class DefaultNewDocDlg : public StaticDialog

View File

@ -41,7 +41,7 @@ class Command {
public :
Command(){};
explicit Command(TCHAR *cmd) : _cmdLine(cmd){};
explicit Command(generic_string cmd) : _cmdLine(cmd){};
explicit Command(const generic_string& cmd) : _cmdLine(cmd){};
HINSTANCE run(HWND hWnd);
HINSTANCE run(HWND hWnd, const TCHAR* cwd);

View File

@ -43,7 +43,7 @@ struct TaskLstFnStatus {
generic_string _fn;
int _status = 0;
void *_bufID = nullptr;
TaskLstFnStatus(generic_string str, int status) : _fn(str), _status(status){};
TaskLstFnStatus(const generic_string& str, int status) : _fn(str), _status(status){};
TaskLstFnStatus(int iView, int docIndex, generic_string str, int status, void *bufID) :
_iView(iView), _docIndex(docIndex), _fn(str), _status(status), _bufID(bufID) {};
};

View File

@ -56,7 +56,7 @@ struct iconLocator {
int iconIndex;
generic_string iconLocation;
iconLocator(int iList, int iIcon, const generic_string iconLoc)
iconLocator(int iList, int iIcon, const generic_string& iconLoc)
: listIndex(iList), iconIndex(iIcon), iconLocation(iconLoc){};
};