Reworked boost::algorithm::unhex error reporting to play nicer with Boost.Exception (thanks to Emil); added tests

[SVN r78838]
This commit is contained in:
Marshall Clow
2012-06-06 20:38:04 +00:00
parent ea13506795
commit a42d6ebcd7
3 changed files with 151 additions and 9 deletions

View File

@ -51,14 +51,10 @@ namespace boost { namespace algorithm {
\brief Thrown when the input sequence unexpectedly ends
*/
struct hex_decode_error: virtual boost::exception, virtual std::exception {};
struct not_enough_input : public hex_decode_error {};
struct non_hex_input : public hex_decode_error {
non_hex_input ( char ch ) : bad_char ( ch ) {}
char bad_char;
private:
non_hex_input (); // don't allow creation w/o a char
};
struct hex_decode_error : virtual boost::exception, virtual std::exception {};
struct not_enough_input : virtual hex_decode_error {};
struct non_hex_input : virtual hex_decode_error {};
typedef boost::error_info<struct bad_char_,char> bad_char;
namespace detail {
/// \cond DOXYGEN_HIDE
@ -77,7 +73,7 @@ namespace detail {
if ( c >= '0' && c <= '9' ) return c - '0';
if ( c >= 'A' && c <= 'F' ) return c - 'A' + 10;
if ( c >= 'a' && c <= 'f' ) return c - 'a' + 10;
BOOST_THROW_EXCEPTION (non_hex_input (c));
BOOST_THROW_EXCEPTION (non_hex_input() << boost::algorithm::bad_char (c));
return 0; // keep dumb compilers happy
}