On Mon, Jul 21, 2003 at 02:48:47PM +0000, Angus Leeming spake thusly: > Martin Vermeer wrote: > > > On Mon, Jul 21, 2003 at 12:03:13PM +0000, Angus Leeming spake thusly:
... > This is going to bomb unless you add a return statement > +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); > return; > + } > + } > + Assert(false); > +} Right. So Alfredo said too. > Presumably, this one would benefit from either a 'return' or a 'break' > +void BranchList::setSelected(string const & s, bool val) > +{ > + List::iterator it = list.begin(); > + List::iterator end = list.end(); > + for (; it != end; it++) { > + if (s.find(it->getBranch(), 0) != string::npos) { > + it->setSelected(val); > return > } > + } > +} No, I don't agree with you here. No Assert, no npos problem. I really want to traverse all branches and set/clear only those in s. > Here you should move the (j == string::npos) test to immediately after the j > = s.find_first_of line, else the very next line is going to be nasty. Can't do that Angus :-) I need to capture the last branch name in s. What about: > +void BranchList::add(string const & s) > +{ > + string name; > + string::size_type i = 0; > + Branch br; > + for (;;) { > + string::size_type const j = s.find_first_of(separator(), i); if (j == string::npos) name = s.substr(i) else > + name = s.substr(i, j - i); > + br.setBranch(name); > + br.setSelected(false); > + br.setColor("none"); > + list.push_back(br); > + if (j == string::npos) > + break; > + i = j; > + i++; > + } > +} > > > Does it make sense to setColor here if j == npos? Same here. I want to get at the last colour in the string s, which is *not* terminated by a '|'. > +void BranchList::setColors(string const & s) > +{ > + string name; > + string::size_type i = 0; > + List::iterator it = list.begin(); > + for (;;) { > + string::size_type const j = s.find_first_of(separator(), i); if (j == string::npos) name = s.substr(i) else > + name = s.substr(i, j - i); > + it->setColor(name); > + if (j == string::npos) > + break; > + it++; > + Assert(it != list.end()); > + i = j; > + i++; > + } > +} > > > Trivia: > indent with a tab: > +class InsetBranch : public InsetCollapsable { > + InsetBranchParams params_; > +}; > > -- > Angus Martin -- Martin Vermeer [EMAIL PROTECTED] Helsinki University of Technology Dept. of Surveying, Inst. of Geodesy P.O. Box 1200, FIN-02015 HUT, Finland :wq
pgp00000.pgp
Description: PGP signature