From de564874d60233c977c93496da1aa406245c37c2 Mon Sep 17 00:00:00 2001 From: Mattia Barbon Date: Mon, 21 Jul 2003 09:41:26 +0000 Subject: [PATCH] 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 --- src/common/datstrm.cpp | 12 ++++------ src/common/filename.cpp | 9 +++----- src/common/regex.cpp | 4 +--- src/msw/choice.cpp | 2 -- src/msw/dde.cpp | 3 +-- src/msw/listbox.cpp | 3 +-- src/msw/ole/dataobj.cpp | 9 +++----- src/msw/regconf.cpp | 11 +++++---- src/msw/registry.cpp | 7 ++---- src/msw/statbr95.cpp | 3 +-- src/msw/textctrl.cpp | 51 ++++++++++++++++++++++------------------- src/msw/utils.cpp | 7 +++--- src/msw/utilsgui.cpp | 8 +++---- src/msw/window.cpp | 4 +--- 14 files changed, 58 insertions(+), 75 deletions(-) diff --git a/src/common/datstrm.cpp b/src/common/datstrm.cpp index a2c2aa55da..a7bf054ec0 100644 --- a/src/common/datstrm.cpp +++ b/src/common/datstrm.cpp @@ -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; } diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 125aae19f6..6ccdee80d8 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -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); } } } diff --git a/src/common/regex.cpp b/src/common/regex.cpp index 62ffa7c781..e39cde96bf 100644 --- a/src/common/regex.cpp +++ b/src/common/regex.cpp @@ -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 diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index 740d574451..f9629adaab 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -251,8 +251,6 @@ wxString wxChoice::GetString(int n) const { wxLogLastError(wxT("SendMessage(CB_GETLBTEXT)")); } - - str.UngetWriteBuf(); } return str; diff --git a/src/msw/dde.cpp b/src/msw/dde.cpp index ce6914ee5c..28147375dd 100644 --- a/src/msw/dde.cpp +++ b/src/msw/dde.cpp @@ -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; } diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index c84ead3a3b..247ae933c8 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -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; } diff --git a/src/msw/ole/dataobj.cpp b/src/msw/ole/dataobj.cpp index 83a2761aa0..ac37833d0d 100644 --- a/src/msw/ole/dataobj.cpp +++ b/src/msw/ole/dataobj.cpp @@ -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; } diff --git a/src/msw/regconf.cpp b/src/msw/regconf.cpp index 07af68b3a0..2a5325bc15 100644 --- a/src/msw/regconf.cpp +++ b/src/msw/regconf.cpp @@ -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 diff --git a/src/msw/registry.cpp b/src/msw/registry.cpp index 9462ef29f0..c18f1de8d4 100644 --- a/src/msw/registry.cpp +++ b/src/msw/registry.cpp @@ -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; } diff --git a/src/msw/statbr95.cpp b/src/msw/statbr95.cpp index 16fa083f6d..2687370ef4 100644 --- a/src/msw/statbr95.cpp +++ b/src/msw/statbr95.cpp @@ -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; diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 276df78633..cd347f4764 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -468,30 +468,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); + { + // alloc one extra WORD as needed by the control + wxStringBuffer tmp(str, ++len); + wxChar *p = tmp; - TEXTRANGE textRange; - textRange.chrg.cpMin = from; - textRange.chrg.cpMax = to == -1 ? len : to; - textRange.lpstrText = 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); + (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 - for ( ; *p; p++ ) + if ( m_verRichEdit > 1 ) { - if ( *p == _T('\r') ) - *p = _T('\n'); + // 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 ) { // convert to the canonical form - see comment below @@ -1196,13 +1198,16 @@ wxString wxTextCtrl::GetLineText(long lineNo) const len += sizeof(WORD); wxString str; - wxChar *buf = str.GetWriteBuf(len); - - *(WORD *)buf = (WORD)len; - len = (size_t)::SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf); - buf[len] = 0; + { + wxStringBufferLength tmp(str, len); + wxChar *buf = tmp; - str.UngetWriteBuf(len); + *(WORD *)buf = (WORD)len; + len = (size_t)::SendMessage(GetHwnd(), EM_GETLINE, + lineNo, (LPARAM)buf); + buf[len] = 0; + tmp.SetLength(len); + } return str; } diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index ca408de0a6..4ba9ff2a28 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -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; diff --git a/src/msw/utilsgui.cpp b/src/msw/utilsgui.cpp index 9b14ea38ac..418aef7964 100644 --- a/src/msw/utilsgui.cpp +++ b/src/msw/utilsgui.cpp @@ -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 diff --git a/src/msw/window.cpp b/src/msw/window.cpp index a6f3d3a4c1..3d22361214 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -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); -- 2.45.2