Strange loop in vcl/source/control/combobox

Jean-Noël Rouvignac jn.rouvignac at gmail.com
Wed Feb 13 02:38:39 PST 2013


Hello,

I have been looking at the following code, but struggle a bit to understand
how this loop is working in IMPL_LINK_NOARG(ComboBox, ImplSelectHdl) :
            xub_StrLen nIndex = 0;
            while ( nIndex != STRING_NOTFOUND )
            {
                xub_StrLen  nPrevIndex = nIndex;
                XubString   aToken = aText.GetToken( 0, mcMultiSep, nIndex
);
                xub_StrLen  nTokenLen = aToken.Len();
                aToken = comphelper::string::strip(aToken, ' ');
                sal_uInt16      nP = mpImplLB->GetEntryList()->FindEntry(
aToken );
                if ( (nP != LISTBOX_ENTRY_NOTFOUND) &&
(!mpImplLB->GetEntryList()->IsEntryPosSelected( nP )) )
                {
                    aText.Erase( nPrevIndex, nTokenLen );
                    nIndex = sal::static_int_cast<xub_StrLen>(nIndex -
nTokenLen);
                    if ( (nPrevIndex < aText.Len()) && (aText.GetChar(
nPrevIndex ) == mcMultiSep) )
                    {
                        aText.Erase( nPrevIndex, 1 );
                        nIndex--;
                    }
                }
                aText = comphelper::string::strip(aText, ' ');
            }

My problem lies with how the nIndex variable gets updated, I don't see how
it can reach STRING_NOTFOUND any other way than by luck. I must be missing
something.
Does anybody have a better read than me here?

BTW I am trying to convert this code to use OUString, so any suggestion in
this direction is more than welcome :)

Cheers,
Jean--Noël
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20130213/355df146/attachment.html>


More information about the LibreOffice mailing list