From c833f0cdb094f5ff2219ba5d777e18428dbc7c07 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 15 May 2012 10:03:53 +0000 Subject: [PATCH] Use iterators instead of indices in wxStripMenuCodes(). Make the function more efficient when using UTF-8 wxStrings by using iterators instead of indices in the loop searching for "&". Closes #14307. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71434 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/utilscmn.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index 1dae85d7f0..d9ce6b56ff 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -1184,22 +1184,22 @@ wxString wxStripMenuCodes(const wxString& in, int flags) size_t len = in.length(); out.reserve(len); - for ( size_t n = 0; n < len; n++ ) + for ( wxString::const_iterator it = in.begin(); it != in.end(); ++it ) { - wxChar ch = in[n]; + wxChar ch = *it; if ( (flags & wxStrip_Mnemonics) && ch == wxT('&') ) { // skip it, it is used to introduce the accel char (or to quote // itself in which case it should still be skipped): note that it // can't be the last character of the string - if ( ++n == len ) + if ( ++it == in.end() ) { wxLogDebug(wxT("Invalid menu string '%s'"), in.c_str()); } else { // use the next char instead - ch = in[n]; + ch = *it; } } else if ( (flags & wxStrip_Accel) && ch == wxT('\t') ) -- 2.45.2