Stop using wxWidgets 1.xx wxString compatibility functions

Replace them with std::string-like equivalents when possible (i.e.
replace Length() with length(), IsNull() with empty()) or, at least,
with wx 2 functions if not (e.g. Remove() with Truncate(), First() with
Find(), LowerCase() with MakeLower() etc).

Closes #22638.
This commit is contained in:
Tim Stahlhut 2022-07-18 23:54:35 -04:00 committed by Vadim Zeitlin
parent 541be26e78
commit c69ee439d9
26 changed files with 58 additions and 58 deletions

View file

@ -255,7 +255,7 @@ MyConnection::OnRequest(const wxString& topic,
m_sRequestDate = wxDateTime::Now().FormatTime() +
" " + wxDateTime::Now().FormatDate();
data = m_sRequestDate.c_str();
*size = m_sRequestDate.Length() + 1;
*size = m_sRequestDate.length() + 1;
}
else if (item == "bytes[3]")
{

View file

@ -184,7 +184,7 @@ void MyApp::DecorateSplashScreen(wxBitmap& bmp)
// create a copyright notice that uses the year that this file was compiled
wxString year(__DATE__);
wxString copyrightLabel = wxString::Format("%s%s wxWidgets. %s",
wxString::FromUTF8("\xc2\xa9"), year.Mid(year.Length() - 4),
wxString::FromUTF8("\xc2\xa9"), year.Mid(year.length() - 4),
"All rights reserved.");
// draw the (white) labels inside of our orange box (at the bottom of the splashscreen)

View file

@ -166,7 +166,7 @@ wxString wxAuiChopText(wxDC& dc, const wxString& text, int max_size)
if (x <= max_size)
return text;
size_t i, len = text.Length();
size_t i, len = text.length();
size_t last_good_length = 0;
for (i = 0; i < len; ++i)
{

View file

@ -863,7 +863,7 @@ wxDateTime::ParseRfc822Date(const wxString& originalDate, wxString::const_iterat
// 1. week day (optional)
// if there is a week day present, it must be separated
// by a comma at position [3].
if ( date.Length() > 3 && date[3] == ',' )
if ( date.length() > 3 && date[3] == ',' )
{
const wxDateTime::WeekDay
wd = GetWeekDayFromName(p, pEnd, Name_Abbr, DateLang_English);

View file

@ -1281,7 +1281,7 @@ bool wxGCDCImpl::DoGetPartialTextExtents(const wxString& text, wxArrayInt& width
{
wxCHECK_MSG( m_graphicContext, false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
widths.Clear();
widths.Add(0,text.Length());
widths.Add(0,text.length());
if ( text.IsEmpty() )
return true;

View file

@ -367,7 +367,7 @@ static wxString MakeCorrectPath(const wxString& path)
if (j >= 0 && r.GetChar(j) != wxT(':'))
{
for (j = j - 1; j >= 0 && r.GetChar(j) != wxT('/') && r.GetChar(j) != wxT(':'); j--) {}
r.Remove(j + 1);
r.Truncate(j + 1);
}
}
}
@ -417,7 +417,7 @@ void wxFileSystem::ChangePathTo(const wxString& location, bool is_dir)
{
if (m_Path[(unsigned int) i] == wxT(':'))
{
m_Path.Remove(i+1);
m_Path.Truncate(i+1);
break;
}
}
@ -426,7 +426,7 @@ void wxFileSystem::ChangePathTo(const wxString& location, bool is_dir)
}
else
{
m_Path.Remove(pathpos+1);
m_Path.Truncate(pathpos+1);
}
}
}

View file

@ -126,7 +126,7 @@ static const char hexArray[] = "0123456789ABCDEF";
// Convert 2-digit hex number to decimal
int wxHexToDec(const wxString& str)
{
wxCHECK_MSG( str.Length() >= 2, -1, wxS("Invalid argument") );
wxCHECK_MSG( str.length() >= 2, -1, wxS("Invalid argument") );
char buf[2];
buf[0] = str.GetChar(0);

View file

@ -747,7 +747,7 @@ void wxFileListCtrl::OnListEndLabelEdit( wxListEvent &event )
if ((event.GetLabel().empty()) ||
(event.GetLabel() == wxT(".")) ||
(event.GetLabel() == wxT("..")) ||
(event.GetLabel().First( wxFILE_SEP_PATH ) != wxNOT_FOUND))
(event.GetLabel().Find( wxFILE_SEP_PATH ) != wxNOT_FOUND))
{
wxMessageDialog dialog(this, _("Illegal directory name."), _("Error"), wxOK | wxICON_ERROR );
dialog.ShowModal();

View file

@ -2985,7 +2985,7 @@ void wxCairoContext::GetPartialTextExtents(const wxString& text, wxArrayDouble&
while (i++ < len)
widths.Add(PANGO_PIXELS(w));
#else
for (size_t i = 0; i < text.Length(); i++)
for (size_t i = 0; i < text.length(); i++)
{
const wxCharBuffer data = text.SubString(0, i).utf8_str();

View file

@ -399,7 +399,7 @@ bool wxExtHelpController::KeywordSearch(const wxString& k,
if (! showAll)
{
compA = k;
compA.LowerCase();
compA.MakeLower();
}
while (node)
@ -410,7 +410,7 @@ bool wxExtHelpController::KeywordSearch(const wxString& k,
bool testTarget = ! compB.empty();
if (testTarget && ! showAll)
{
compB.LowerCase();
compB.MakeLower();
testTarget = compB.Contains(compA);
}

View file

@ -891,7 +891,7 @@ void wxHtmlSearchEngine::LookFor(const wxString& keyword, bool case_sensitive, b
m_Keyword = keyword;
if (!m_CaseSensitive)
m_Keyword.LowerCase();
m_Keyword.MakeLower();
}
@ -937,7 +937,7 @@ bool wxHtmlSearchEngine::Scan(const wxFSFile& file)
wxString bufStr = filter.ReadFile(file);
if (!m_CaseSensitive)
bufStr.LowerCase();
bufStr.MakeLower();
{ // remove html tags
wxString bufStrCopy;

View file

@ -479,7 +479,7 @@ void wxHtmlWordCell::Draw(wxDC& dc, int x, int y,
}
int part1 = s->GetFromCell()==this ? s->GetFromCharacterPos() : 0;
int part2 = s->GetToCell()==this ? s->GetToCharacterPos() : m_Word.Length();
int part2 = s->GetToCell()==this ? s->GetToCharacterPos() : m_Word.length();
if ( part1 > 0 )
{
@ -581,7 +581,7 @@ wxString wxHtmlWordCell::ConvertToText(wxHtmlSelection *s) const
if ( s->AreFromToCharacterPosSet() )
{
const int part1 = s->GetFromCell()==this ? s->GetFromCharacterPos() : 0;
const int part2 = s->GetToCell()==this ? s->GetToCharacterPos() : m_Word.Length();
const int part2 = s->GetToCell()==this ? s->GetToCharacterPos() : m_Word.length();
if ( part1 == part2 )
return wxEmptyString;
return GetPartAsText(part1, part2);

View file

@ -63,7 +63,7 @@ wxHtmlStyleParams::wxHtmlStyleParams(const wxHtmlTag& tag)
m_names.Add(tempString);
// Extract and trim values
tempString = token.SubString(colonIndex + 1, token.Length() - 1);
tempString = token.SubString(colonIndex + 1, token.length() - 1);
tempString.Trim(true).Trim(false);
// Add to values list
m_values.Add(tempString);

View file

@ -3239,11 +3239,11 @@ wxD2DFontData::wxD2DFontData(wxGraphicsRenderer* renderer, const wxFont& font, c
// The length of the font name must not exceed LF_FACESIZE TCHARs,
// including the terminating NULL.
wxString name = font.GetFaceName().Mid(0, WXSIZEOF(logfont.lfFaceName)-1);
for (unsigned int i = 0; i < name.Length(); ++i)
for (unsigned int i = 0; i < name.length(); ++i)
{
logfont.lfFaceName[i] = name.GetChar(i);
}
logfont.lfFaceName[name.Length()] = L'\0';
logfont.lfFaceName[name.length()] = L'\0';
}
wxCOMPtr<IDWriteFontFamily> fontFamily;
@ -3860,7 +3860,7 @@ public:
static void GetPartialTextExtents(wxD2DFontData* fontData, const wxString& text, wxArrayDouble& widths)
{
for (unsigned int i = 0; i < text.Length(); ++i)
for (unsigned int i = 0; i < text.length(); ++i)
{
wxDouble width;
GetTextExtent(fontData, text.SubString(0, i), &width, NULL, NULL, NULL);

View file

@ -161,7 +161,7 @@ wxWindow* wxWindow::CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd)
wxCHECK_MSG( parent, NULL, wxT("must have valid parent for a control") );
wxString str(wxGetWindowClass(hWnd));
str.UpperCase();
str.MakeUpper();
long id = wxGetWindowId(hWnd);
long style = GetWindowLong((HWND) hWnd, GWL_STYLE);

View file

@ -408,7 +408,7 @@ WXHRGN wxStaticBox::MSWGetRegionWithoutChildren()
wxMSWWinStyleUpdater updateStyle(child);
wxString str(wxGetWindowClass(child));
str.UpperCase();
str.MakeUpper();
if ( str == wxT("BUTTON") && updateStyle.IsOn(BS_GROUPBOX) )
{
if ( child == GetHwnd() )

View file

@ -92,7 +92,7 @@ wxString wxStringProperty::ValueToString( wxVariant& value,
// If string is password and value is for visual purposes,
// then return asterisks instead the actual string.
if ( (m_flags & wxPG_PROP_PASSWORD) && !(argFlags & (wxPG_FULL_VALUE|wxPG_EDITABLE_VALUE)) )
return wxString(wxS('*'), s.Length());
return wxString(wxS('*'), s.length());
return s;
}

View file

@ -428,7 +428,7 @@ public:
QVector<int> roles;
if ( (info.m_mask & wxLIST_MASK_TEXT) && !info.GetText().IsNull() )
if ( (info.m_mask & wxLIST_MASK_TEXT) && !info.GetText().empty() )
{
columnItem.m_label = wxQtConvertString(info.GetText());
roles.push_back(Qt::DisplayRole);

View file

@ -4750,7 +4750,7 @@ bool wxRichTextParagraphLayoutBox::FindNextParagraphNumber(wxRichTextParagraph*
int pos = text.Find(wxT('.'), true);
if (pos != wxNOT_FOUND)
{
text = text.Mid(0, text.Length() - pos - 1);
text = text.Mid(0, text.length() - pos - 1);
}
else
text.clear();
@ -6831,7 +6831,7 @@ bool wxRichTextPlainText::Draw(wxDC& dc, wxRichTextDrawingContext& context, cons
const wxString* pWholeString = &m_text;
if (context.HasVirtualText(this))
{
if (context.GetVirtualText(this, stringWhole) && stringWhole.Length() == m_text.Length())
if (context.GetVirtualText(this, stringWhole) && stringWhole.length() == m_text.length())
pWholeString = &stringWhole;
}
@ -6852,7 +6852,7 @@ bool wxRichTextPlainText::Draw(wxDC& dc, wxRichTextDrawingContext& context, cons
stringWhole = m_text;
if (context.HasVirtualText(this))
{
if (!context.GetVirtualText(this, stringWhole) || stringWhole.Length() != m_text.Length())
if (!context.GetVirtualText(this, stringWhole) || stringWhole.length() != m_text.length())
stringWhole = m_text;
}
@ -7264,7 +7264,7 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz
const wxString* pWholeString = &m_text;
if (context.HasVirtualText(this))
{
if (context.GetVirtualText(this, stringWhole) && stringWhole.Length() == m_text.Length())
if (context.GetVirtualText(this, stringWhole) && stringWhole.length() == m_text.length())
pWholeString = &stringWhole;
}
@ -7535,7 +7535,7 @@ bool wxRichTextPlainText::CanSplit(wxRichTextDrawingContext& context) const
// If this object has any virtual attributes at all, whether for the whole object
// or individual ones, we should try splitting it by calling Split.
// Must be more than one character in order to be able to split.
return m_text.Length() > 1 && context.HasVirtualAttributes(const_cast<wxRichTextPlainText*>(this));
return m_text.length() > 1 && context.HasVirtualAttributes(const_cast<wxRichTextPlainText*>(this));
}
wxRichTextObject* wxRichTextPlainText::Split(wxRichTextDrawingContext& context)
@ -7558,7 +7558,7 @@ wxRichTextObject* wxRichTextPlainText::Split(wxRichTextDrawingContext& context)
// We will gather up runs of text with the same virtual attributes
int len = m_text.Length();
int len = m_text.length();
int i = 0;
// runStart and runEnd represent the accumulated run with a consistent attribute
@ -8955,9 +8955,9 @@ bool wxRichTextBuffer::PasteFromClipboard(long position)
wxString text(data.GetText());
#ifdef __WXMSW__
wxString text2;
text2.Alloc(text.Length()+1);
text2.Alloc(text.length()+1);
size_t i;
for (i = 0; i < text.Length(); i++)
for (i = 0; i < text.length(); i++)
{
wxChar ch = text[i];
if (ch != wxT('\r'))
@ -8969,7 +8969,7 @@ bool wxRichTextBuffer::PasteFromClipboard(long position)
container->InsertTextWithUndo(this, position+1, text2, GetRichTextCtrl(), wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE);
if (GetRichTextCtrl())
GetRichTextCtrl()->ShowPosition(position + text2.Length());
GetRichTextCtrl()->ShowPosition(position + text2.length());
success = true;
}

View file

@ -934,7 +934,7 @@ void wxRichTextFontPage::OnFaceTextCtrlUpdated( wxCommandEvent& WXUNUSED(event)
size_t i;
for (i = 0; i < arr.GetCount(); i++)
{
if (arr[i].Mid(0, facename.Length()).Lower() == facename.Lower())
if (arr[i].Mid(0, facename.length()).Lower() == facename.Lower())
{
m_faceListBox->ScrollToRow(i);
break;

View file

@ -510,7 +510,7 @@ bool wxRichTextPlainText::ExportXML(wxOutputStream& stream, int indent, wxRichTe
int i;
int last = 0;
const wxString& text = GetText();
int len = (int) text.Length();
int len = (int) text.length();
if (len == 0)
{
@ -624,7 +624,7 @@ bool wxRichTextPlainText::ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* han
int i;
int last = 0;
const wxString& text = GetText();
int len = (int) text.Length();
int len = (int) text.length();
if (len == 0)
{

View file

@ -767,7 +767,7 @@ SurfaceFontDataD2D::SurfaceFontDataD2D(const FontParameters& fp)
m_pTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
hr = pDWriteFactory->CreateTextLayout(extentTest.wc_str(),
extentTest.Length(), m_pTextFormat, FLT_MAX, FLT_MAX,
extentTest.length(), m_pTextFormat, FLT_MAX, FLT_MAX,
&pTextLayout);
}
@ -791,7 +791,7 @@ SurfaceFontDataD2D::SurfaceFontDataD2D(const FontParameters& fp)
m_ascent = lineMetrics[0].baseline;
m_descent = lineMetrics[0].height - lineMetrics[0].baseline;
m_internalLeading = lineMetrics[0].height - emHeight;
m_averageCharWidth = textmetrics.width/extentTest.Length();
m_averageCharWidth = textmetrics.width/extentTest.length();
switch ( fp.extraFontFlag & wxSTC_EFF_QUALITY_MASK )
{
@ -1525,7 +1525,7 @@ XYPOSITION SurfaceD2D::WidthText(Font &font_, const char *s, int len)
DWRITE_TEXT_METRICS textMetrics = {0,0,0,0,0,0,0,0,0};
HRESULT hr = m_pDWriteFactory->CreateTextLayout(tbuf.wc_str(),
tbuf.Length(), m_pTextFormat, FLT_MAX, FLT_MAX, &pTextLayout);
tbuf.length(), m_pTextFormat, FLT_MAX, FLT_MAX, &pTextLayout);
if ( SUCCEEDED(hr) )
{
@ -1546,10 +1546,10 @@ void SurfaceD2D::MeasureWidths(Font &font_, const char *s, int len,
int fit = 0;
wxString tbuf = stc2wx(s,len);
wxVector<FLOAT> poses;
poses.reserve(tbuf.Length());
poses.resize(tbuf.Length());
poses.reserve(tbuf.length());
poses.resize(tbuf.length());
fit = tbuf.Length();
fit = tbuf.length();
const int clusters = 1000;
DWRITE_CLUSTER_METRICS clusterMetrics[clusters];
UINT32 count = 0;
@ -1560,7 +1560,7 @@ void SurfaceD2D::MeasureWidths(Font &font_, const char *s, int len,
wxCOMPtr<IDWriteTextLayout> pTextLayout;
HRESULT hr = m_pDWriteFactory->CreateTextLayout(tbuf.wc_str(),
tbuf.Length(), m_pTextFormat, FLT_MAX, FLT_MAX, &pTextLayout);
tbuf.length(), m_pTextFormat, FLT_MAX, FLT_MAX, &pTextLayout);
if ( !SUCCEEDED(hr) )
return;
@ -1583,7 +1583,7 @@ void SurfaceD2D::MeasureWidths(Font &font_, const char *s, int len,
}
position += clusterMetrics[ci].width;
}
PLATFORM_ASSERT(ti == tbuf.Length());
PLATFORM_ASSERT(ti == tbuf.length());
}
if (m_unicodeMode)
{
@ -1628,7 +1628,7 @@ void SurfaceD2D::MeasureWidths(Font &font_, const char *s, int len,
{
const size_t buflen = static_cast<size_t>(len);
// One character per position
PLATFORM_ASSERT(buflen == tbuf.Length());
PLATFORM_ASSERT(buflen == tbuf.length());
for ( size_t kk=0; kk<buflen; kk++ )
{
positions[kk] = poses[kk];
@ -1808,7 +1808,7 @@ void SurfaceD2D::DrawTextCommon(PRectangle rc, Font &font_, XYPOSITION ybase,
D2D1_ANTIALIAS_MODE_ALIASED);
}
hr = m_pDWriteFactory->CreateTextLayout(tbuf.wc_str(), tbuf.Length(),
hr = m_pDWriteFactory->CreateTextLayout(tbuf.wc_str(), tbuf.length(),
m_pTextFormat, rc.Width(), rc.Height(), &pTextLayout);
if ( SUCCEEDED(hr) )

View file

@ -2540,7 +2540,7 @@ void wxTextCtrl::SetMaxLength(unsigned long len)
{
// if the existing value in the text control is too long,
// then it is clipped to the newly imposed limit.
if ( m_value.Length() > len )
if ( m_value.length() > len )
{
// block the wxEVT_TEXT event temporaryly
// otherwise Remove will generate a wxEVT_TEXT event

View file

@ -1097,7 +1097,7 @@ bool OutputNode(wxOutputStream& stream,
case wxXML_TEXT_NODE:
if (node->GetNoConversion())
{
stream.Write(node->GetContent().c_str(), node->GetContent().Length());
stream.Write(node->GetContent().c_str(), node->GetContent().length());
rc = true;
}
else

View file

@ -812,7 +812,7 @@ void TextCtrlTestCase::DoPositionToXYMultiLine(long style)
// empty field
m_text->Clear();
const long numChars_0 = 0;
wxASSERT(numChars_0 == text.Length());
wxASSERT(numChars_0 == text.length());
XYPos coords_0[numChars_0+1] =
{ { 0, 0 } };
@ -832,7 +832,7 @@ void TextCtrlTestCase::DoPositionToXYMultiLine(long style)
text = wxS("1234");
m_text->SetValue(text);
const long numChars_1 = 4;
wxASSERT( numChars_1 == text.Length() );
wxASSERT( numChars_1 == text.length() );
XYPos coords_1[numChars_1+1] =
{ { 0, 0 }, { 1, 0 }, { 2, 0}, { 3, 0 }, { 4, 0 } };
@ -864,7 +864,7 @@ void TextCtrlTestCase::DoPositionToXYMultiLine(long style)
#endif // WXMSW
const long numChars_2 = 8;
wxASSERT(numChars_2 == text.Length());
wxASSERT(numChars_2 == text.length());
XYPos coords_2[numChars_2 + 1] =
{ { 0, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 },
{ 0, 1 }, { 1, 1 }, { 2, 1 },
@ -913,7 +913,7 @@ void TextCtrlTestCase::DoPositionToXYMultiLine(long style)
#endif // WXMSW
const long numChars_3 = 3;
wxASSERT(numChars_3 == text.Length());
wxASSERT(numChars_3 == text.length());
XYPos coords_3[numChars_3+1] =
{ { 0, 0 },
{ 0, 1 },
@ -965,7 +965,7 @@ void TextCtrlTestCase::DoPositionToXYMultiLine(long style)
#endif // WXMSW
const long numChars_4 = 10;
wxASSERT(numChars_4 == text.Length());
wxASSERT(numChars_4 == text.length());
XYPos coords_4[numChars_4+1] =
{ { 0, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 },
{ 0, 1 }, { 1, 1 },
@ -1200,7 +1200,7 @@ void TextCtrlTestCase::PositionToXYSingleLine()
// pure one line
text = wxS("1234");
m_text->SetValue(text);
const long numChars_1 = text.Length();
const long numChars_1 = text.length();
CPPUNIT_ASSERT_EQUAL( numChars_1, m_text->GetLastPosition() );
for ( long i = 0; i <= numChars_1; i++ )
{
@ -1216,7 +1216,7 @@ void TextCtrlTestCase::PositionToXYSingleLine()
// with new line characters
text = wxS("123\nab\nX");
m_text->SetValue(text);
const long numChars_2 = text.Length();
const long numChars_2 = text.length();
CPPUNIT_ASSERT_EQUAL( numChars_2, m_text->GetLastPosition() );
for ( long i = 0; i <= numChars_2; i++ )
{

View file

@ -622,7 +622,7 @@ static wxString FileToCppArray(wxString filename, int num)
output << wxT("\n");
}
output << tmp;
linelng += tmp.Length()+1;
linelng += tmp.length()+1;
}
delete[] buffer;
@ -780,7 +780,7 @@ static wxString FileToPythonArray(wxString filename, int num)
output << wxT("\\\n");
}
output << tmp;
linelng += tmp.Length();
linelng += tmp.length();
}
delete[] buffer;