• R/O
  • SSH
  • HTTPS

befoo: Commit


Commit MetaInfo

Revision118 (tree)
Zeit2013-01-03 05:58:32
Autorz0rac

Log Message

(empty log message)

Ändern Zusammenfassung

Diff

--- trunk/extend/settingdlg.cpp (revision 117)
+++ trunk/extend/settingdlg.cpp (revision 118)
@@ -10,22 +10,6 @@
1010 #include <vector>
1111 #include <shlwapi.h>
1212
13-/** textbuf - temporary text buffer
14- */
15-namespace {
16- struct textbuf {
17- char* data;
18- textbuf() : data(NULL) {}
19- ~textbuf() { delete [] data; }
20- char* operator()(size_t n)
21- {
22- assert(n);
23- delete [] data, data = NULL;
24- return data = new char[n];
25- }
26- };
27-}
28-
2913 /*
3014 * Functions of the class dialog
3115 */
@@ -92,7 +76,7 @@
9276 string
9377 dialog::gettext(int id) const
9478 {
95- textbuf buf;
79+ win32::textbuf<char> buf;
9680 int size = 0;
9781 for (int n = 0; n <= size + 1;) {
9882 n += 256;
@@ -134,7 +118,7 @@
134118 HWND h = item(id);
135119 int i = ListBox_GetCurSel(h);
136120 int n = ListBox_GetTextLen(h, i);
137- textbuf buf;
121+ win32::textbuf<char> buf;
138122 return n > 0 && ListBox_GetText(h, i, buf(n + 1)) == n ?
139123 string(buf.data, n) : string();
140124 }
--- trunk/src/win32.cpp (revision 117)
+++ trunk/src/win32.cpp (revision 118)
@@ -28,25 +28,11 @@
2828 GetLastError() == ERROR_ALREADY_EXISTS)) throw error();
2929 }
3030
31-namespace {
32- struct textbuf {
33- char* data;
34- textbuf() : data(NULL) {}
35- textbuf(size_t n) : data(new char[n]) {}
36- ~textbuf() { delete [] data; }
37- char* operator()(size_t n)
38- {
39- delete [] data, data = NULL;
40- return data = new char[n];
41- }
42- };
43-}
44-
4531 string
4632 win32::profile(LPCSTR section, LPCSTR key, LPCSTR file)
4733 {
4834 if (!file) return string();
49- textbuf buf;
35+ textbuf<char> buf;
5036 DWORD size = 0;
5137 for (DWORD n = 0; n <= size + 2;) {
5238 n += 256;
@@ -65,9 +51,9 @@
6551 string
6652 win32::xenv(const string& s)
6753 {
54+ textbuf<char> buf;
6855 DWORD n = static_cast<DWORD>(s.size() + 1);
69- textbuf buf(n);
70- n = ExpandEnvironmentStrings(s.c_str(), buf.data, n);
56+ n = ExpandEnvironmentStrings(s.c_str(), buf(n), n);
7157 if (n > s.size() + 1) ExpandEnvironmentStrings(s.c_str(), buf(n), n);
7258 return buf.data;
7359 }
@@ -82,12 +68,10 @@
8268 FileTimeToLocalFileTime(&ft, &lt);
8369 FileTimeToSystemTime(&lt, &st);
8470 }
71+ textbuf<char> buf;
8572 int n = fn(LOCALE_USER_DEFAULT, flags, &st, NULL, NULL, 0);
86- textbuf buf(n);
87- if (n && fn(LOCALE_USER_DEFAULT, flags, &st, NULL, buf.data, n)) {
88- return buf.data;
89- }
90- return string();
73+ return n && fn(LOCALE_USER_DEFAULT, flags, &st, NULL, buf(n), n) ?
74+ string(buf.data, n - 1) : string();
9175 }
9276
9377 HANDLE
@@ -95,7 +79,7 @@
9579 {
9680 assert(!(flags & ~(SEE_MASK_CONNECTNETDRV | SEE_MASK_FLAG_DDEWAIT |
9781 SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS)));
98- textbuf tmp(cmd.size() + 1);
82+ textbuf<char> tmp(cmd.size() + 1);
9983 lstrcpyA(tmp.data, cmd.c_str());
10084 PathRemoveArgs(tmp.data);
10185 string::size_type i = lstrlen(tmp.data);
@@ -205,7 +189,7 @@
205189 string
206190 win32::module::text(UINT id) const
207191 {
208- textbuf buf;
192+ textbuf<char> buf;
209193 int size = 0;
210194 for (int n = 0; n <= size + 1;) {
211195 n += 256;
@@ -218,7 +202,7 @@
218202 win32::module::textf(UINT id, ...) const
219203 {
220204 string s = text(id);
221- textbuf buf;
205+ textbuf<char> buf;
222206 int size = 0;
223207 for (int n = 0; n <= size + 1;) {
224208 n += 512;
@@ -295,11 +279,10 @@
295279 win32::wstr::mbstr(LPCWSTR ws, UINT cp)
296280 {
297281 if (!ws) return string();
298- int size = WideCharToMultiByte(cp, 0, ws, -1, NULL, 0, NULL, NULL);
299- if (!size) return string();
300- textbuf buf(size);
301- WideCharToMultiByte(cp, 0, ws, -1, buf.data, size, NULL, NULL);
302- return string(buf.data, size - 1);
282+ textbuf<char> buf;
283+ int n = WideCharToMultiByte(cp, 0, ws, -1, NULL, 0, NULL, NULL);
284+ return n && WideCharToMultiByte(cp, 0, ws, -1, buf(n), n, NULL, NULL) ?
285+ string(buf.data, n - 1) : string();
303286 }
304287
305288 /*
--- trunk/src/win32.h (revision 117)
+++ trunk/src/win32.h (revision 118)
@@ -89,6 +89,17 @@
8989 friend class trylock;
9090 };
9191
92+ // textbuf - text buffer template
93+ template<typename _Ty>
94+ struct textbuf {
95+ _Ty* data;
96+ textbuf() : data(NULL) {}
97+ textbuf(size_t n) : data(new _Ty[n]) {}
98+ ~textbuf() { delete [] data; }
99+ _Ty* operator()(size_t n)
100+ { delete [] data, data = NULL; return data = new _Ty[n]; }
101+ };
102+
92103 // wstr - wide character string
93104 class wstr {
94105 LPWSTR _data;
--- trunk/src/setting.cpp (revision 117)
+++ trunk/src/setting.cpp (revision 118)
@@ -259,12 +259,6 @@
259259 void put(const char* key, const char* value);
260260 void erase(const char* key);
261261 list<string> keys() const;
262- public:
263- struct buf {
264- char* data;
265- buf(DWORD size) : data(new char[size]) {}
266- ~buf() { delete [] data; }
267- };
268262 };
269263 }
270264
@@ -288,7 +282,7 @@
288282 if (_key &&
289283 RegQueryValueEx(_key, key, NULL, &type, NULL, &size) == ERROR_SUCCESS &&
290284 type == REG_SZ) {
291- regkey::buf buf(size);
285+ win32::textbuf<char> buf(size);
292286 if (RegQueryValueEx(_key, key, NULL, NULL, LPBYTE(buf.data), &size) == ERROR_SUCCESS) {
293287 return buf.data;
294288 }
@@ -315,7 +309,7 @@
315309 DWORD size;
316310 if (_key && RegQueryInfoKey(_key, NULL, NULL, NULL, NULL, NULL,
317311 NULL, NULL, &size, NULL, NULL, NULL) == ERROR_SUCCESS) {
318- regkey::buf buf(++size);
312+ win32::textbuf<char> buf(++size);
319313 DWORD i = 0, n;
320314 while (n = size, RegEnumValue(_key, i++, buf.data, &n,
321315 NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
@@ -353,7 +347,7 @@
353347 DWORD size;
354348 if (_key && RegQueryInfoKey(HKEY(_key), NULL, NULL, NULL, NULL, &size,
355349 NULL, NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
356- regkey::buf buf(++size);
350+ win32::textbuf<char> buf(++size);
357351 DWORD i = 0, n;
358352 while (n = size, RegEnumKeyEx(HKEY(_key), i++, buf.data, &n,
359353 NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
--- trunk/src/mail.cpp (revision 117)
+++ trunk/src/mail.cpp (revision 118)
@@ -145,11 +145,7 @@
145145 }
146146 int n = 0;
147147 if (_mb2u(&_mode, _codepage, text.c_str(), NULL, NULL, &n) != S_OK) throw text;
148- struct buf {
149- LPWSTR data;
150- buf(int size) : data(new WCHAR[size]) {}
151- ~buf() { delete [] data; }
152- } buf(n + 1);
148+ win32::textbuf<WCHAR> buf(n + 1);
153149 _mb2u(&_mode, _codepage, text.c_str(), NULL, buf.data, &n);
154150 buf.data[n] = 0;
155151 return win32::wstr::mbstr(buf.data, CP_UTF8);
--- trunk/src/summary.cpp (revision 117)
+++ trunk/src/summary.cpp (revision 118)
@@ -181,17 +181,7 @@
181181 }
182182 }
183183
184- struct textbuf {
185- LPWSTR data;
186- textbuf() : data(NULL) {}
187- ~textbuf() { delete [] data; }
188- LPWSTR operator()(size_t n)
189- {
190- assert(n);
191- delete [] data, data = NULL;
192- return data = new WCHAR[n];
193- }
194- } tb[2];
184+ win32::textbuf<WCHAR> tb[2];
195185 WPARAM si[] = { s1, s2 };
196186 for (int i = 0; i < 2; ++i) {
197187 LVITEMW lv = { LVIF_TEXT };
Show on old repository browser