Use range-for loops for looping over strings when possible

Replace a few loops explicitly using iterators or pointers with
range-for loops.

No real changes, this is just a simplification.
This commit is contained in:
Vadim Zeitlin
2025-02-01 19:22:39 +01:00
parent fd874a616a
commit fe36a53041
5 changed files with 6 additions and 13 deletions
+1 -3
View File
@@ -2241,9 +2241,7 @@ static wxString FilterOutEntryName(const wxString& str)
wxString strResult;
strResult.Alloc(str.Len());
for ( const wxChar *pc = str.c_str(); *pc != wxT('\0'); pc++ ) {
const wxChar c = *pc;
for ( wxUniChar c : str ) {
// NB: note that wxCONFIG_IMMUTABLE_PREFIX and wxCONFIG_PATH_SEPARATOR
// should *not* be quoted
if ( !wxIsalnum(c) && !wxStrchr(wxT("@_/-!.*%()"), c) )
+1 -2
View File
@@ -73,9 +73,8 @@ wxString wxTextBuffer::Translate(const wxString& text, wxTextFileType type)
result.Alloc(text.Len());
wxUniChar chLast = 0;
for ( wxString::const_iterator i = text.begin(); i != text.end(); ++i )
for ( wxUniChar ch : text )
{
wxUniChar ch = *i;
switch ( ch.GetValue() ) {
case wxT('\n'):
// Dos/Unix line termination
+1 -2
View File
@@ -491,9 +491,8 @@ void wxTextOutputStream::WriteString(const wxString& string)
wxString out;
out.reserve(len);
for ( size_t i = 0; i < len; i++ )
for ( wxUniChar c : string )
{
const wxUniChar c = string[i];
if ( c == wxT('\n') )
{
switch ( m_mode )
+2 -3
View File
@@ -887,7 +887,7 @@ void wxHtmlSearchEngine::LookFor(const wxString& keyword, bool case_sensitive, b
}
static inline bool WHITESPACE(wxChar c)
static inline bool WHITESPACE(wxUniChar c)
{
return c == wxT(' ') || c == wxT('\n') || c == wxT('\r') || c == wxT('\t');
}
@@ -899,9 +899,8 @@ static inline wxString CompressSpaces(const wxString & str)
buf.reserve( str.size() );
bool space_counted = false;
for( const wxChar * pstr = str.c_str(); *pstr; ++pstr )
for ( wxUniChar ch: str )
{
wxChar ch = *pstr;
if( WHITESPACE( ch ) )
{
if( space_counted )
+1 -3
View File
@@ -8954,10 +8954,8 @@ bool wxRichTextBuffer::PasteFromClipboard(long position)
#ifdef __WXMSW__
wxString text2;
text2.Alloc(text.length()+1);
size_t i;
for (i = 0; i < text.length(); i++)
for ( wxUniChar ch : text )
{
wxUniChar ch = text[i];
if (ch != wxT('\r'))
text2 += ch;
}