Use wxStringBuffer[Length] instead of explicit calls to
wxString::get/UngetWriteBuffer. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22191 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -110,15 +110,13 @@ wxString wxDataInputStream::ReadString()
|
||||
if (len > 0)
|
||||
{
|
||||
#if wxUSE_UNICODE
|
||||
char *tmp = new char[len + 1];
|
||||
m_input->Read(tmp, len);
|
||||
tmp[len] = 0;
|
||||
wxString ret( (const wxChar*) m_conv.cMB2WX(tmp) );
|
||||
delete[] tmp;
|
||||
wxCharBuffer tmp(len + 1);
|
||||
m_input->Read(tmp.data(), len);
|
||||
tmp.data()[len] = '\0';
|
||||
wxString ret(m_conv.cMB2WX(tmp.data()));
|
||||
#else
|
||||
wxString ret;
|
||||
m_input->Read( ret.GetWriteBuf(len), len);
|
||||
ret.UngetWriteBuf();
|
||||
m_input->Read( wxStringBuffer(ret, len), len);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
@@ -1347,10 +1347,9 @@ wxString wxFileName::GetShortPath() const
|
||||
ok = ::GetShortPathName
|
||||
(
|
||||
path,
|
||||
pathOut.GetWriteBuf(sz),
|
||||
wxStringBuffer(pathOut, sz),
|
||||
sz
|
||||
) != 0;
|
||||
pathOut.UngetWriteBuf();
|
||||
}
|
||||
if (ok)
|
||||
return pathOut;
|
||||
@@ -1406,11 +1405,9 @@ wxString wxFileName::GetLongPath() const
|
||||
ok = (*s_pfnGetLongPathName)
|
||||
(
|
||||
path,
|
||||
pathOut.GetWriteBuf(sz),
|
||||
wxStringBuffer(pathOut, sz),
|
||||
sz
|
||||
) != 0;
|
||||
pathOut.UngetWriteBuf();
|
||||
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
@@ -1541,7 +1538,7 @@ void wxFileName::SplitPath(const wxString& fullpathWithVolume,
|
||||
fullpath[posFirstSlash] = wxFILE_SEP_DSK;
|
||||
|
||||
// UNC paths are always absolute, right? (FIXME)
|
||||
fullpath.insert(posFirstSlash + 1, wxFILE_SEP_PATH_DOS);
|
||||
fullpath.insert(posFirstSlash + 1, 1, wxFILE_SEP_PATH_DOS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -148,9 +148,7 @@ wxString wxRegExImpl::GetErrorMsg(int errorcode) const
|
||||
|
||||
msg = wxString(buf.data(), wxConvLibc);
|
||||
#else // !Unicode
|
||||
(void)regerror(errorcode, &m_RegEx, msg.GetWriteBuf(len), len);
|
||||
|
||||
msg.UngetWriteBuf();
|
||||
(void)regerror(errorcode, &m_RegEx, wxStringBuffer(msg, len), len);
|
||||
#endif // Unicode/!Unicode
|
||||
}
|
||||
else // regerror() returned 0
|
||||
|
@@ -251,8 +251,6 @@ wxString wxChoice::GetString(int n) const
|
||||
{
|
||||
wxLogLastError(wxT("SendMessage(CB_GETLBTEXT)"));
|
||||
}
|
||||
|
||||
str.UngetWriteBuf();
|
||||
}
|
||||
|
||||
return str;
|
||||
|
@@ -965,8 +965,7 @@ static wxString DDEStringFromAtom(HSZ hsz)
|
||||
static const size_t len = 256;
|
||||
|
||||
wxString s;
|
||||
(void)DdeQueryString(DDEIdInst, hsz, s.GetWriteBuf(len), len, DDE_CP);
|
||||
s.UngetWriteBuf();
|
||||
(void)DdeQueryString(DDEIdInst, hsz, wxStringBuffer(s, len), len, DDE_CP);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@@ -454,8 +454,7 @@ wxString wxListBox::GetString(int N) const
|
||||
|
||||
// +1 for terminating NUL
|
||||
wxString result;
|
||||
ListBox_GetText(GetHwnd(), N, result.GetWriteBuf(len + 1));
|
||||
result.UngetWriteBuf();
|
||||
ListBox_GetText(GetHwnd(), N, wxStringBuffer(result, len + 1));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@@ -157,8 +157,7 @@ wxString wxDataFormat::GetId() const
|
||||
wxCHECK_MSG( !IsStandard(), s,
|
||||
wxT("name of predefined format cannot be retrieved") );
|
||||
|
||||
int len = ::GetClipboardFormatName(m_format, s.GetWriteBuf(max), max);
|
||||
s.UngetWriteBuf();
|
||||
int len = ::GetClipboardFormatName(m_format, wxStringBuffer(s, max), max);
|
||||
|
||||
if ( !len )
|
||||
{
|
||||
@@ -999,8 +998,7 @@ bool wxFileDataObject::SetData(size_t WXUNUSED(size), const void *pData)
|
||||
// +1 for terminating NUL
|
||||
len = ::DragQueryFile(hdrop, n, NULL, 0) + 1;
|
||||
|
||||
UINT len2 = ::DragQueryFile(hdrop, n, str.GetWriteBuf(len), len);
|
||||
str.UngetWriteBuf();
|
||||
UINT len2 = ::DragQueryFile(hdrop, n, wxStringBuffer(str, len), len);
|
||||
m_filenames.Add(str);
|
||||
|
||||
if ( len2 != len - 1 ) {
|
||||
@@ -1171,8 +1169,7 @@ wxString wxURLDataObject::GetURL() const
|
||||
|
||||
size_t len = m_dataObjectLast->GetDataSize();
|
||||
|
||||
m_dataObjectLast->GetDataHere(url.GetWriteBuf(len));
|
||||
url.UngetWriteBuf();
|
||||
m_dataObjectLast->GetDataHere(wxStringBuffer(url, len));
|
||||
|
||||
return url;
|
||||
}
|
||||
|
@@ -245,7 +245,8 @@ void wxRegConfig::SetPath(const wxString& strPath)
|
||||
size_t len = strFullPath.length();
|
||||
const wxChar *end = src + len;
|
||||
|
||||
wxChar *dst = m_strPath.GetWriteBuf(len);
|
||||
wxStringBufferLength buf(m_strPath, len);
|
||||
wxChar *dst = buf;
|
||||
wxChar *start = dst;
|
||||
|
||||
for ( ; src < end; src++, dst++ )
|
||||
@@ -337,8 +338,7 @@ void wxRegConfig::SetPath(const wxString& strPath)
|
||||
}
|
||||
|
||||
*dst = _T('\0');
|
||||
|
||||
m_strPath.UngetWriteBuf(dst - start);
|
||||
buf.SetLength(dst - start);
|
||||
}
|
||||
|
||||
#ifdef WX_DEBUG_SET_PATH
|
||||
@@ -355,7 +355,8 @@ void wxRegConfig::SetPath(const wxString& strPath)
|
||||
size_t len = m_strPath.length();
|
||||
|
||||
const wxChar *src = m_strPath.c_str();
|
||||
wxChar *dst = strRegPath.GetWriteBuf(len);
|
||||
wxStringBufferLength buf(strRegPath, len);
|
||||
wxChar *dst = buf;
|
||||
|
||||
const wxChar *end = src + len;
|
||||
for ( ; src < end; src++, dst++ )
|
||||
@@ -366,7 +367,7 @@ void wxRegConfig::SetPath(const wxString& strPath)
|
||||
*dst = *src;
|
||||
}
|
||||
|
||||
strRegPath.UngetWriteBuf(len);
|
||||
buf.SetLength(len);
|
||||
}
|
||||
|
||||
// this is not needed any longer as we don't create keys unnecessarily any
|
||||
|
@@ -872,14 +872,12 @@ bool wxRegKey::QueryValue(const wxChar *szValue,
|
||||
strValue.Empty();
|
||||
}
|
||||
else {
|
||||
RegString pBuf = (RegString)strValue.GetWriteBuf(dwSize);
|
||||
m_dwLastError = RegQueryValueEx((HKEY) m_hKey,
|
||||
WXSTRINGCAST szValue,
|
||||
RESERVED,
|
||||
&dwType,
|
||||
pBuf,
|
||||
(RegString)(wxChar*)wxStringBuffer(strValue, dwSize),
|
||||
&dwSize);
|
||||
strValue.UngetWriteBuf();
|
||||
|
||||
// expand the var expansions in the string unless disabled
|
||||
#ifndef __WXWINCE__
|
||||
@@ -893,10 +891,9 @@ bool wxRegKey::QueryValue(const wxChar *szValue,
|
||||
ok = ::ExpandEnvironmentStrings
|
||||
(
|
||||
strValue,
|
||||
strExpValue.GetWriteBuf(dwExpSize),
|
||||
wxStringBuffer(strExpValue, dwExpSize),
|
||||
dwExpSize
|
||||
) != 0;
|
||||
strExpValue.UngetWriteBuf();
|
||||
strValue = strExpValue;
|
||||
}
|
||||
|
||||
|
@@ -191,8 +191,7 @@ wxString wxStatusBar95::GetStatusText(int nField) const
|
||||
int len = StatusBar_GetTextLen(GetHwnd(), nField);
|
||||
if ( len > 0 )
|
||||
{
|
||||
StatusBar_GetText(GetHwnd(), nField, str.GetWriteBuf(len));
|
||||
str.UngetWriteBuf();
|
||||
StatusBar_GetText(GetHwnd(), nField, wxStringBuffer(str, len));
|
||||
}
|
||||
|
||||
return str;
|
||||
|
@@ -467,30 +467,32 @@ wxString wxTextCtrl::GetRange(long from, long to) const
|
||||
{
|
||||
int len = GetWindowTextLength(GetHwnd());
|
||||
if ( len > from )
|
||||
{
|
||||
{
|
||||
// alloc one extra WORD as needed by the control
|
||||
wxChar *p = str.GetWriteBuf(++len);
|
||||
wxStringBuffer tmp(str, ++len);
|
||||
wxChar *p = tmp;
|
||||
|
||||
TEXTRANGE textRange;
|
||||
textRange.chrg.cpMin = from;
|
||||
textRange.chrg.cpMax = to == -1 ? len : to;
|
||||
textRange.lpstrText = p;
|
||||
|
||||
(void)SendMessage(GetHwnd(), EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
|
||||
(void)SendMessage(GetHwnd(), EM_GETTEXTRANGE,
|
||||
0, (LPARAM)&textRange);
|
||||
|
||||
if ( m_verRichEdit > 1 )
|
||||
{
|
||||
// RichEdit 2.0 uses just CR ('\r') for the newlines which is
|
||||
// neither Unix nor Windows style - convert it to something
|
||||
// reasonable
|
||||
// RichEdit 2.0 uses just CR ('\r') for the
|
||||
// newlines which is neither Unix nor Windows
|
||||
// style - convert it to something reasonable
|
||||
for ( ; *p; p++ )
|
||||
{
|
||||
if ( *p == _T('\r') )
|
||||
*p = _T('\n');
|
||||
}
|
||||
}
|
||||
|
||||
str.UngetWriteBuf();
|
||||
}
|
||||
|
||||
if ( m_verRichEdit == 1 )
|
||||
{
|
||||
@@ -1196,13 +1198,16 @@ wxString wxTextCtrl::GetLineText(long lineNo) const
|
||||
len += sizeof(WORD);
|
||||
|
||||
wxString str;
|
||||
wxChar *buf = str.GetWriteBuf(len);
|
||||
{
|
||||
wxStringBufferLength tmp(str, len);
|
||||
wxChar *buf = tmp;
|
||||
|
||||
*(WORD *)buf = (WORD)len;
|
||||
len = (size_t)::SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
|
||||
len = (size_t)::SendMessage(GetHwnd(), EM_GETLINE,
|
||||
lineNo, (LPARAM)buf);
|
||||
buf[len] = 0;
|
||||
|
||||
str.UngetWriteBuf(len);
|
||||
tmp.SetLength(len);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
@@ -408,8 +408,7 @@ const wxChar* wxGetHomeDir(wxString *pstr)
|
||||
|
||||
wxString strPath;
|
||||
::GetModuleFileName(::GetModuleHandle(NULL),
|
||||
strPath.GetWriteBuf(MAX_PATH), MAX_PATH);
|
||||
strPath.UngetWriteBuf();
|
||||
wxStringBuffer(strPath, MAX_PATH), MAX_PATH);
|
||||
|
||||
// extract the dir name
|
||||
wxSplitPath(strPath, &strDir, NULL, NULL);
|
||||
@@ -593,8 +592,8 @@ bool wxGetEnv(const wxString& var, wxString *value)
|
||||
|
||||
if ( value )
|
||||
{
|
||||
(void)::GetEnvironmentVariable(var, value->GetWriteBuf(dwRet), dwRet);
|
||||
value->UngetWriteBuf();
|
||||
(void)::GetEnvironmentVariable(var, wxStringBuffer(*value, dwRet),
|
||||
dwRet);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
@@ -99,7 +99,7 @@ bool wxGetResource(const wxString& section, const wxString& entry, wxChar **valu
|
||||
return FALSE;
|
||||
}
|
||||
if (*value) delete[] (*value);
|
||||
*value = copystring(buf);
|
||||
*value = wxStrcpy(new wxChar[wxStrlen(buf) + 1], buf);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -361,8 +361,7 @@ wxString WXDLLEXPORT wxGetWindowText(WXHWND hWnd)
|
||||
if ( hWnd )
|
||||
{
|
||||
int len = GetWindowTextLength((HWND)hWnd) + 1;
|
||||
::GetWindowText((HWND)hWnd, str.GetWriteBuf(len), len);
|
||||
str.UngetWriteBuf();
|
||||
::GetWindowText((HWND)hWnd, wxStringBuffer(str, len), len);
|
||||
}
|
||||
|
||||
return str;
|
||||
@@ -380,9 +379,8 @@ wxString WXDLLEXPORT wxGetWindowClass(WXHWND hWnd)
|
||||
|
||||
for ( ;; )
|
||||
{
|
||||
int count = ::GetClassName((HWND)hWnd, str.GetWriteBuf(len), len);
|
||||
int count = ::GetClassName((HWND)hWnd, wxStringBuffer(str, len), len);
|
||||
|
||||
str.UngetWriteBuf();
|
||||
if ( count == len )
|
||||
{
|
||||
// the class name might have been truncated, retry with larger
|
||||
|
@@ -3383,9 +3383,7 @@ bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam)
|
||||
|
||||
// and now get the file name
|
||||
::DragQueryFile(hFilesInfo, wIndex,
|
||||
files[wIndex].GetWriteBuf(len), len);
|
||||
|
||||
files[wIndex].UngetWriteBuf();
|
||||
wxStringBuffer(files[wIndex], len), len);
|
||||
}
|
||||
DragFinish (hFilesInfo);
|
||||
|
||||
|
Reference in New Issue
Block a user