Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

shellext: remove unused ReplaceParams

Changeset 2f70efc4a754

Parent 2b7189079f30

by Adrian Buehlmann

Changes to 2 files · Browse files at 2f70efc4a754 Showing diff from parent 2b7189079f30 Diff from another changeset...

 
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
 
218
219
220
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -218,83 +218,3 @@
 }    #endif - - -// Replace parameters (%something) -std::string ReplaceParams(const std::string& str, - const std::map<std::string, std::string> params) -{ - std::stringstream result; - unsigned int i = 0; - char c; - int state = 0; - unsigned int var_start = 0; - bool hasMore; - while (i < str.length()) - { - c = str[i]; - hasMore = (i < str.length() - 1); - switch(state) - { - // Normal processing - case 0: - { - if (c == '%' && hasMore) - { - var_start = i + 1; - state = 1; - } - else - { - result << c; - } - break; - } - - // Found '%' - case 1: - { - if ((c == '_' || isalnum(c)) && hasMore) - { - // do nothing - } - else - { - // replace variable - if (var_start < i) - { - std::string var = str.substr(var_start, i - var_start); - std::map<std::string, std::string>::const_iterator it = - params.find(var); - if (it != params.end()) - { - result << it->second; - } - else - { - result << '%' << var; - } - } - else - { - result << '%'; - } - result << c; - if (c != '%') - { - state = 0; - } - } - break; - } - - // should never get here - default: - ASSERT(false); - } - i++; - } - - return result.str(); -} -
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
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
 
 
 
 
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
 // TortoiseCVS - a Windows shell extension for easy version control    // Copyright (C) 2002 - Francis Irving  // <francis@flourish.org> - May 2002    // This program is free software; you can redistribute it and/or  // modify it under the terms of the GNU General Public License  // as published by the Free Software Foundation; either version 2  // of the License, or (at your option) any later version.    // This program is distributed in the hope that it will be useful,  // but WITHOUT ANY WARRANTY; without even the implied warranty of  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  // GNU General Public License for more details.    // You should have received a copy of the GNU General Public License  // along with this program; if not, write to the Free Software  // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.    #ifndef _STRING_UTILS_H  #define _STRING_UTILS_H    #include <string>  #include <vector>  #include <map>  #include <windows.h>      #ifdef _MSC_VER   // Fancier GUI Visual C++ asserts   #include <crtdbg.h>  #else   // Standard C assert   #include <assert.h>  #ifndef _ASSERT   #define _ASSERT assert  #endif  #endif    #ifndef ASSERT   #define ASSERT _ASSERT  #endif    // From: http://www.kbcafe.com/articles/cplusplus.tricks.html  template<class T> void FindAndReplace(T& source, const T& find, const T& replace)  {   size_t j;   for (j = 0; (j = source.find(find, j)) != T::npos;)   {   source.replace(j, find.length(), replace);   j += replace.length();   }  }    // Return the length of the longest string in the vector.  int MaxStringLength(const std::vector<std::string>& stringvec);    void MakeLowerCase(std::string& s);    void MakeUpperCase(std::string& s);    // Remove leading whitespaces from a string  std::string TrimLeft(const std::string& str);      // Remove trailing whitespaces from a string  std::string TrimRight(const std::string& str);      // Remove leading and trailing whitespaces from a string  std::string Trim(const std::string& str);    // Test if string starts with substr  bool StartsWith(const std::string& str, const std::string& substr);    // Quotes a string  std::string Quote(const std::string& str);    // Cuts the first token off a delimited list  std::string CutFirstToken(std::string& sList, const std::string sDelimiter);    // Convert Unicode string to multibyte string  std::string WideToMultibyte(const std::wstring& wide, UINT CodePage = CP_ACP);    // Convert multibyte string to Unicode string  std::wstring MultibyteToWide(const std::string& multibyte, UINT CodePage = CP_ACP);    #if wxUSE_UNICODE  #define wxText(xxx) MultibyteToWide(xxx)  #define wxTextCStr(xxx) MultibyteToWide(xxx).c_str()  #define wxAscii(xxx) WideToMultibyte(xxx)  #else  #define wxText(xxx) xxx  #define wxTextCStr(xxx) (xxx).c_str()  #define wxAscii(xxx) xxx  #endif    // Serialize a vector of strings  std::string SerializeStringVector(const std::vector<std::string>& vStrings,   const std::string& sDelimiter);    // Expand environment strings  std::string ExpandEnvStrings(const std::string& str);    #if wxUSE_UNICODE  wxString ExpandEnvStrings(const wxString& str);  #endif   -// Replace parameters (%something) -std::string ReplaceParams(const std::string& str, - const std::map<std::string, std::string> params); -  // comparison function object  class less_nocase  {  public:   bool operator()(const std::string& x, const std::string& y) const   {   std::string::const_iterator p = x.begin();   std::string::const_iterator q = y.begin();     while (p != x.end() && q != y.end() && toupper(*p) == toupper(*q))   ++p, ++q;     if (p == x.end()) // Reached end of x: Return true if y is longer than x   return q != y.end();     if (q == y.end()) // Reached end of y, but not x, so x is longer than y   return false;     return toupper(*p) < toupper(*q);   }  };      #endif