On Monday 21 July 2003 11:14 am, Martin Vermeer wrote:
> > Can 's' belong to multiple branches?
>
> No.
>
> > If not you should have a 'break' in
> > there. Your Assert isn't doing much at the moment ;-)
>
> It should catch the 'branch not existing' condition and return an
> empty string. I believe Assert(false) will do that.
>
> > +void BranchList::setColor(string const & s, string const & val)
> > +{
> > +       List::iterator it = list.begin();
> > +       List::iterator end = list.end();
> > +       for (; it != end; it++) {
> > +               if (s.find(it->getBranch(), 0) != string::npos) {
> > +                       it->setColor(val);
> >                         break;
> > +               }
> > +       }
> > +       Assert(true);
> >         Assert(false);
> > +}
>
> Now *I* don't understand.

If 's' can't belong to multiple branches, then once you
        s.find(it->getBranch(), 0) != string::npos
and set the color, there's no need to continue the loop. So, break.
>
> ...
>
> > I think the logic here is wrong.
> > +void BranchList::add(string const & s)
> > +{
> > +       string name;
> > +       size_t i = 0;
> > +       size_t j = 0;
> > +       Branch br;
> > +       while (j < string::npos) {
> > +               j = s.find_first_of(separator(), i);
> > +               name = s.substr(i, j - i);
> > +               br.setBranch(name);
> > +               br.setSelected(false);
> > +               br.setBranch(name);
> > +               br.setColor("none");
> > +               list.push_back(br);
> > +               i = j;
> > +               i++;
> > +       }
> > +}

> I don't think it's wrong, but yours looks better. Compiling now.

Well and good. Nonetheless, it is wrong:
        while (j < string::npos) {
                 j = s.find_first_of(separator(), i);
                // j can now be string::npos
                // j-i makes no sense
                name = s.substr(i, j - i);

Angus

Reply via email to