A helper class that temporarily stores error messages and dump the messages to a string which given as as pointer when it is destructed. If the given pointer is a nullptr, this class does not store error message.
| 32 | // to a string which given as as pointer when it is destructed. If the given |
| 33 | // pointer is a nullptr, this class does not store error message. |
| 34 | class ErrorMsgStream { |
| 35 | public: |
| 36 | explicit ErrorMsgStream(std::string* error_msg_sink) |
| 37 | : error_msg_sink_(error_msg_sink) { |
| 38 | if (error_msg_sink_) stream_ = MakeUnique<std::ostringstream>(); |
| 39 | } |
| 40 | ~ErrorMsgStream() { |
| 41 | if (error_msg_sink_ && stream_) *error_msg_sink_ = stream_->str(); |
| 42 | } |
| 43 | template <typename T> |
| 44 | ErrorMsgStream& operator<<(T val) { |
| 45 | if (stream_) *stream_ << val; |
| 46 | return *this; |
| 47 | } |
| 48 | |
| 49 | private: |
| 50 | std::unique_ptr<std::ostringstream> stream_; |
| 51 | // The destination string to which this class dump the error message when |
| 52 | // destructor is called. |
| 53 | std::string* error_msg_sink_; |
| 54 | }; |
| 55 | } // namespace |
| 56 | |
| 57 | EncodeNumberStatus ParseAndEncodeIntegerNumber( |
no outgoing calls
no test coverage detected