document Alloc() vs returning bool (part of bug 1933693)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53030 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1729,7 +1729,7 @@ public:
|
|||||||
// raw access to string memory
|
// raw access to string memory
|
||||||
// ensure that string has space for at least nLen characters
|
// ensure that string has space for at least nLen characters
|
||||||
// only works if the data of this string is not shared
|
// only works if the data of this string is not shared
|
||||||
bool Alloc(size_t nLen) { reserve(nLen); /*return capacity() >= nLen;*/ return true; }
|
bool Alloc(size_t nLen) { reserve(nLen); return capacity() >= nLen; }
|
||||||
// minimize the string's memory
|
// minimize the string's memory
|
||||||
// only works if the data of this string is not shared
|
// only works if the data of this string is not shared
|
||||||
bool Shrink();
|
bool Shrink();
|
||||||
|
@@ -146,18 +146,43 @@ public:
|
|||||||
wxString AfterLast(wxChar ch) const;
|
wxString AfterLast(wxChar ch) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Preallocate enough space for wxString to store @a nLen characters. This function
|
Preallocate enough space for wxString to store @a nLen characters.
|
||||||
may be used to increase speed when the string is constructed by repeated
|
|
||||||
concatenation as in
|
|
||||||
|
|
||||||
because it will avoid the need to reallocate string memory many times (in case
|
Please note that this method does the same thing as the standard
|
||||||
of long strings). Note that it does not set the maximal length of a string - it
|
reserve() one and shouldn't be used in new code.
|
||||||
will still expand if more than @a nLen characters are stored in it. Also, it
|
|
||||||
does not truncate the existing string (use
|
This function may be used to increase speed when the string is
|
||||||
Truncate() for this) even if its current length is
|
constructed by repeated concatenation as in
|
||||||
greater than @e nLen
|
|
||||||
|
@code
|
||||||
|
// delete all vowels from the string
|
||||||
|
wxString DeleteAllVowels(const wxString& original)
|
||||||
|
{
|
||||||
|
wxString result;
|
||||||
|
|
||||||
|
size_t len = original.length();
|
||||||
|
|
||||||
|
result.Alloc(len);
|
||||||
|
|
||||||
|
for ( size_t n = 0; n < len; n++ )
|
||||||
|
{
|
||||||
|
if ( strchr("aeuio", tolower(original[n])) == NULL )
|
||||||
|
result += original[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@endcode
|
||||||
|
|
||||||
|
because it will avoid the need to reallocate string memory many times
|
||||||
|
(in case of long strings). Note that it does not set the maximal length
|
||||||
|
of a string -- it will still expand if more than @a nLen characters are
|
||||||
|
stored in it. Also, it does not truncate the existing string (use
|
||||||
|
Truncate() for this) even if its current length is greater than @a nLen.
|
||||||
|
|
||||||
|
@return @true if memory was successfully allocated, @false otherwise.
|
||||||
*/
|
*/
|
||||||
void Alloc(size_t nLen);
|
bool Alloc(size_t nLen);
|
||||||
|
|
||||||
//@{
|
//@{
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user