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