11// This file is part of Notepad++ project
2- // Copyright (C)2003 Don HO <[email protected] >3- //
4- // This program is free software; you can redistribute it and/or
5- // modify it under the terms of the GNU General Public License
6- // as published by the Free Software Foundation; either
7- // version 2 of the License, or (at your option) any later version.
8- //
9- // Note that the GPL places important restrictions on "derived works", yet
10- // it does not provide a detailed definition of that term. To avoid
11- // misunderstandings, we consider an application to constitute a
12- // "derivative work" for the purpose of this license if it does any of the
13- // following:
14- // 1. Integrates source code from Notepad++.
15- // 2. Integrates/includes/aggregates Notepad++ into a proprietary executable
16- // installer, such as those produced by InstallShield.
17- // 3. Links to a library or executes a program that does any of the above.
2+ // Copyright (C)2021 Don HO <[email protected] >3+
4+ // This program is free software: you can redistribute it and/or modify
5+ // it under the terms of the GNU General Public License as published by
6+ // the Free Software Foundation, either version 3 of the License, or
7+ // at your option any later version.
188//
199// This program is distributed in the hope that it will be useful,
2010// but WITHOUT ANY WARRANTY; without even the implied warranty of
21- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2212// GNU General Public License for more details.
2313//
2414// You should have received a copy of the GNU General Public License
25- // along with this program; if not, write to the Free Software
26- // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
2716#pragma once
2817#include < vector>
2918#include < string>
3019#include < sstream>
3120#include < windows.h>
3221#include < iso646.h>
3322#include < cstdint>
23+ #include < unordered_set>
24+ #include < algorithm>
3425
3526
3627const bool dirUp = true ;
@@ -92,35 +83,41 @@ std::string getFileContent(const TCHAR *file2read);
9283generic_string relativeFilePathToFullFilePath (const TCHAR *relativeFilePath);
9384void writeFileContent (const TCHAR *file2write, const char *content2write);
9485bool matchInList (const TCHAR *fileName, const std::vector<generic_string> & patterns);
86+ bool matchInExcludeDirList (const TCHAR* dirName, const std::vector<generic_string>& patterns, size_t level);
87+ bool allPatternsAreExclusion (const std::vector<generic_string> patterns);
9588
9689class WcharMbcsConvertor final
9790{
9891public:
99- static WcharMbcsConvertor * getInstance () {return _pSelf;}
100- static void destroyInstance () {delete _pSelf;}
92+ static WcharMbcsConvertor& getInstance () {
93+ static WcharMbcsConvertor instance;
94+ return instance;
95+ }
10196
102- const wchar_t * char2wchar (const char *mbStr, UINT codepage, int lenIn =-1 , int * pLenOut=NULL , int * pBytesNotProcessed=NULL );
103- const wchar_t * char2wchar (const char *mbcs2Convert, UINT codepage, int * mstart, int * mend);
104- const char * wchar2char (const wchar_t *wcStr, UINT codepage, int lenIn = -1 , int * pLenOut = NULL );
105- const char * wchar2char (const wchar_t *wcStr, UINT codepage, long * mstart, long * mend);
97+ const wchar_t * char2wchar (const char *mbStr, size_t codepage, int lenMbcs =-1 , int * pLenOut=NULL , int * pBytesNotProcessed=NULL );
98+ const wchar_t * char2wchar (const char *mbcs2Convert, size_t codepage, intptr_t * mstart, intptr_t * mend);
99+ const char * wchar2char (const wchar_t *wcStr, size_t codepage, int lenIn = -1 , int * pLenOut = NULL );
100+ const char * wchar2char (const wchar_t *wcStr, size_t codepage, intptr_t * mstart, intptr_t * mend);
106101
107- const char * encode (UINT fromCodepage, UINT toCodepage, const char *txt2Encode, int lenIn= -1 , int * pLenOut=NULL , int * pBytesNotProcessed=NULL )
102+ const char * encode (UINT fromCodepage, UINT toCodepage, const char *txt2Encode, int lenIn = -1 , int * pLenOut=NULL , int * pBytesNotProcessed=NULL )
108103 {
109104 int lenWc = 0 ;
110105 const wchar_t * strW = char2wchar (txt2Encode, fromCodepage, lenIn, &lenWc, pBytesNotProcessed);
111106 return wchar2char (strW, toCodepage, lenWc, pLenOut);
112107 }
113108
114109protected:
115- WcharMbcsConvertor () {}
116- ~WcharMbcsConvertor () {}
110+ WcharMbcsConvertor () = default ;
111+ ~WcharMbcsConvertor () = default ;
117112
118113 // Since there's no public ctor, we need to void the default assignment operator and copy ctor.
119114 // Since these are marked as deleted does not matter under which access specifier are kept
120115 WcharMbcsConvertor (const WcharMbcsConvertor&) = delete ;
121116 WcharMbcsConvertor& operator = (const WcharMbcsConvertor&) = delete ;
122117
123- static WcharMbcsConvertor* _pSelf;
118+ // No move ctor and assignment
119+ WcharMbcsConvertor (WcharMbcsConvertor&&) = delete ;
120+ WcharMbcsConvertor& operator = (WcharMbcsConvertor&&) = delete ;
124121
125122 template <class T >
126123 class StringBuffer final
@@ -169,26 +166,30 @@ class WcharMbcsConvertor final
169166#define REBARBAND_SIZE sizeof (REBARBANDINFO)
170167
171168generic_string PathRemoveFileSpec (generic_string & path);
172- generic_string PathAppend (generic_string &strDest, const generic_string & str2append);
169+ generic_string pathAppend (generic_string &strDest, const generic_string & str2append);
173170COLORREF getCtrlBgColor (HWND hWnd);
174171generic_string stringToUpper (generic_string strToConvert);
175172generic_string stringToLower (generic_string strToConvert);
176173generic_string stringReplace (generic_string subject, const generic_string& search, const generic_string& replace);
177174std::vector<generic_string> stringSplit (const generic_string& input, const generic_string& delimiter);
175+ bool str2numberVector (generic_string str2convert, std::vector<size_t >& numVect);
178176generic_string stringJoin (const std::vector<generic_string>& strings, const generic_string& separator);
179177generic_string stringTakeWhileAdmissable (const generic_string& input, const generic_string& admissable);
180178double stodLocale (const generic_string& str, _locale_t loc, size_t * idx = NULL );
181179
182180int OrdinalIgnoreCaseCompareStrings (LPCTSTR sz1, LPCTSTR sz2);
183181
184182bool str2Clipboard (const generic_string &str2cpy, HWND hwnd);
183+ class Buffer ;
184+ bool buf2Clipborad (const std::vector<Buffer*>& buffers, bool isFullPath, HWND hwnd);
185185
186186generic_string GetLastErrorAsString (DWORD errorCode = 0 );
187187
188188generic_string intToString (int val);
189189generic_string uintToString (unsigned int val);
190190
191- HWND CreateToolTip (int toolID, HWND hDlg, HINSTANCE hInst, const PTSTR pszText);
191+ HWND CreateToolTip (int toolID, HWND hDlg, HINSTANCE hInst, const PTSTR pszText, bool isRTL);
192+ HWND CreateToolTipRect (int toolID, HWND hWnd, HINSTANCE hInst, const PTSTR pszText, const RECT rc);
192193
193194bool isCertificateValidated (const generic_string & fullFilePath, const generic_string & subjectName2check);
194195bool isAssoCommandExisting (LPCTSTR FullPathName);
@@ -199,3 +200,38 @@ std::string ws2s(const std::wstring& wstr);
199200bool deleteFileOrFolder (const generic_string& f2delete);
200201
201202void getFilesInFolder (std::vector<generic_string>& files, const generic_string& extTypeFilter, const generic_string& inFolder);
203+
204+ template <typename T> size_t vecRemoveDuplicates (std::vector<T>& vec, bool isSorted = false , bool canSort = false )
205+ {
206+ if (!isSorted && canSort)
207+ {
208+ std::sort (vec.begin (), vec.end ());
209+ isSorted = true ;
210+ }
211+
212+ if (isSorted)
213+ {
214+ typename std::vector<T>::iterator it;
215+ it = std::unique (vec.begin (), vec.end ());
216+ vec.resize (distance (vec.begin (), it)); // unique() does not shrink the vector
217+ }
218+ else
219+ {
220+ std::unordered_set<T> seen;
221+ auto newEnd = std::remove_if (vec.begin (), vec.end (), [&seen](const T& value)
222+ {
223+ return !seen.insert (value).second ;
224+ });
225+ vec.erase (newEnd, vec.end ());
226+ }
227+ return vec.size ();
228+ }
229+
230+ void trim (generic_string& str);
231+ bool endsWith (const generic_string& s, const generic_string& suffix);
232+
233+ int nbDigitsFromNbLines (size_t nbLines);
234+
235+ generic_string getDateTimeStrFrom (const generic_string& dateTimeFormat, const SYSTEMTIME& st);
236+
237+ HFONT createFont (const TCHAR* fontName, int fontSize, bool isBold, HWND hDestParent);
0 commit comments