1
1
// 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.
18
8
//
19
9
// This program is distributed in the hope that it will be useful,
20
10
// 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
22
12
// GNU General Public License for more details.
23
13
//
24
14
// 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/>.
27
16
#pragma once
28
17
#include < vector>
29
18
#include < string>
30
19
#include < sstream>
31
20
#include < windows.h>
32
21
#include < iso646.h>
33
22
#include < cstdint>
23
+ #include < unordered_set>
24
+ #include < algorithm>
34
25
35
26
36
27
const bool dirUp = true ;
@@ -92,12 +83,16 @@ std::string getFileContent(const TCHAR *file2read);
92
83
generic_string relativeFilePathToFullFilePath (const TCHAR *relativeFilePath);
93
84
void writeFileContent (const TCHAR *file2write, const char *content2write);
94
85
bool 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);
95
88
96
89
class WcharMbcsConvertor final
97
90
{
98
91
public:
99
- static WcharMbcsConvertor * getInstance () {return _pSelf;}
100
- static void destroyInstance () {delete _pSelf;}
92
+ static WcharMbcsConvertor& getInstance () {
93
+ static WcharMbcsConvertor instance;
94
+ return instance;
95
+ }
101
96
102
97
const wchar_t * char2wchar (const char *mbStr, UINT codepage, int lenIn=-1 , int *pLenOut=NULL , int *pBytesNotProcessed=NULL );
103
98
const wchar_t * char2wchar (const char *mbcs2Convert, UINT codepage, int *mstart, int *mend);
@@ -112,15 +107,17 @@ class WcharMbcsConvertor final
112
107
}
113
108
114
109
protected:
115
- WcharMbcsConvertor () {}
116
- ~WcharMbcsConvertor () {}
110
+ WcharMbcsConvertor () = default ;
111
+ ~WcharMbcsConvertor () = default ;
117
112
118
113
// Since there's no public ctor, we need to void the default assignment operator and copy ctor.
119
114
// Since these are marked as deleted does not matter under which access specifier are kept
120
115
WcharMbcsConvertor (const WcharMbcsConvertor&) = delete ;
121
116
WcharMbcsConvertor& operator = (const WcharMbcsConvertor&) = delete ;
122
117
123
- static WcharMbcsConvertor* _pSelf;
118
+ // No move ctor and assignment
119
+ WcharMbcsConvertor (WcharMbcsConvertor&&) = delete ;
120
+ WcharMbcsConvertor& operator = (WcharMbcsConvertor&&) = delete ;
124
121
125
122
template <class T >
126
123
class StringBuffer final
@@ -169,26 +166,30 @@ class WcharMbcsConvertor final
169
166
#define REBARBAND_SIZE sizeof (REBARBANDINFO)
170
167
171
168
generic_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);
173
170
COLORREF getCtrlBgColor (HWND hWnd);
174
171
generic_string stringToUpper (generic_string strToConvert);
175
172
generic_string stringToLower (generic_string strToConvert);
176
173
generic_string stringReplace (generic_string subject, const generic_string& search, const generic_string& replace);
177
174
std::vector<generic_string> stringSplit (const generic_string& input, const generic_string& delimiter);
175
+ bool str2numberVector (generic_string str2convert, std::vector<size_t >& numVect);
178
176
generic_string stringJoin (const std::vector<generic_string>& strings, const generic_string& separator);
179
177
generic_string stringTakeWhileAdmissable (const generic_string& input, const generic_string& admissable);
180
178
double stodLocale (const generic_string& str, _locale_t loc, size_t * idx = NULL );
181
179
182
180
int OrdinalIgnoreCaseCompareStrings (LPCTSTR sz1, LPCTSTR sz2);
183
181
184
182
bool str2Clipboard (const generic_string &str2cpy, HWND hwnd);
183
+ class Buffer ;
184
+ bool buf2Clipborad (const std::vector<Buffer*>& buffers, bool isFullPath, HWND hwnd);
185
185
186
186
generic_string GetLastErrorAsString (DWORD errorCode = 0 );
187
187
188
188
generic_string intToString (int val);
189
189
generic_string uintToString (unsigned int val);
190
190
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);
192
193
193
194
bool isCertificateValidated (const generic_string & fullFilePath, const generic_string & subjectName2check);
194
195
bool isAssoCommandExisting (LPCTSTR FullPathName);
@@ -199,3 +200,38 @@ std::string ws2s(const std::wstring& wstr);
199
200
bool deleteFileOrFolder (const generic_string& f2delete);
200
201
201
202
void 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