]> git.saurik.com Git - wxWidgets.git/commitdiff
Use wxStringBuffer[Length] instead of explicit calls to
authorMattia Barbon <mbarbon@cpan.org>
Mon, 21 Jul 2003 09:41:26 +0000 (09:41 +0000)
committerMattia Barbon <mbarbon@cpan.org>
Mon, 21 Jul 2003 09:41:26 +0000 (09:41 +0000)
wxString::get/UngetWriteBuffer.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22191 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

14 files changed:
src/common/datstrm.cpp
src/common/filename.cpp
src/common/regex.cpp
src/msw/choice.cpp
src/msw/dde.cpp
src/msw/listbox.cpp
src/msw/ole/dataobj.cpp
src/msw/regconf.cpp
src/msw/registry.cpp
src/msw/statbr95.cpp
src/msw/textctrl.cpp
src/msw/utils.cpp
src/msw/utilsgui.cpp
src/msw/window.cpp

index a2c2aa55da11a219451039603fe6c325e2ac6050..a7bf054ec0ab6651974e34985061c1d849f69c5e 100644 (file)
@@ -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;
   }
index 125aae19f664d39eb88c9525313e8ae3fbf6403a..6ccdee80d8ee939999c6947a24eae36c113a083c 100644 (file)
@@ -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);
             }
         }
     }
index 62ffa7c7816b51818e749aa6f19f622d7632e528..e39cde96bf6880332cf171fd57288fb5f327e387 100644 (file)
@@ -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
index 740d574451f94061b8b0a188b3b7c18c11aed34c..f9629adaabf847fb8bd65cf7795076d0f033a700 100644 (file)
@@ -251,8 +251,6 @@ wxString wxChoice::GetString(int n) const
         {
             wxLogLastError(wxT("SendMessage(CB_GETLBTEXT)"));
         }
-
-        str.UngetWriteBuf();
     }
 
     return str;
index ce6914ee5c22028de5f2c5dd3037ebd196978fe4..28147375dd05de643d8c7840795070712ecd562d 100644 (file)
@@ -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;
 }
index c84ead3a3ba126f42ce9ac9557ea6f8bc0ff338d..247ae933c8c29825ff5bbafcee5bb81810a5c2a9 100644 (file)
@@ -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;
 }
index 83a2761aa0742aa46ca24c0b4d4cb6b7f78d6fff..ac37833d0dc641d830a0c7c7ad7333e7f30811d8 100644 (file)
@@ -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;
 }
index 07af68b3a09ef0595cdc84d1c4f1e9346c750317..2a5325bc154f7d0f6d7dc9523321a91003b1c455 100644 (file)
@@ -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
index 9462ef29f0ed6452b45dd8ce2b467c5671d66009..c18f1de8d4c21b2707faddda9064e5f7e5a2bedb 100644 (file)
@@ -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;
                 }
 
index 16fa083f6d4d11babf70ec863c86da88dc0fd3b9..2687370ef44c04d9638e49a49f2d0fe9b64c83e6 100644 (file)
@@ -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;
index 276df78633511438a047059ca6ee72d3ccac4310..cd347f4764966d4b8d9afdd7168bd504e4d63450 100644 (file)
@@ -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;
 }
index ca408de0a6bfeb2dd38bd1b2543d49b309c7ec9c..4ba9ff2a28917149e8eeb0e7758b40a616edd212 100644 (file)
@@ -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;
index 9b14ea38ac413831d2b49a05e37cb75594280e83..418aef7964fb3898296d042f704d954be7e8d131 100644 (file)
@@ -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
index a6f3d3a4c17c56d6185844d3b6e7e16c295116d6..3d223612143b4bea990573a6a6fe8bee271e0e40 100644 (file)
@@ -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);