From: Miquel G. <gbm...@gm...> - 2010-11-10 08:25:26
|
2010/11/10 Knut Franke <Knu...@gm...>: > > What findStringPos() *should* do is guarantee that the read position does not > change (i.e. seekg(startPos) before any return) and clearly indicate failure. > There are different conventions for that (-1, a special value a la > std::string::npos, returning bool or error code and writing the actual result > to a pointer as offered by the GSL, throwing an exception). I think it would > help if we could try to stick to one such convention. Yes, you are right, but, since the generalized parser will not need findStringPos() at all, I saw no need to enhance it. You should not return -1 in an unsigned int, unless you use it to represent the largest available unsigned int. On the other hand <cstring> header uses string::npos = static_cast<size_type>(-1). In the case of findStringPos, I agree that a better patch would be: size_t Origin800Parser::findStringPos(const string& name) { ... return std::string::npos; } since to represent a position is what size_t is designed for. However, I would better spend time in the generalized parser that finding a good patch for each bug in OriginNNNParser. Miquel |