72 | | // this needs to be in an un-named namespace because it is not a template |
73 | | // and might get included in several compilation units. This could cause |
74 | | // multiple definition errors at link time. |
75 | | namespace { |
76 | | unsigned hex_char_to_int ( char c ) { |
77 | | if ( c >= '0' && c <= '9' ) return c - '0'; |
78 | | if ( c >= 'A' && c <= 'F' ) return c - 'A' + 10; |
79 | | if ( c >= 'a' && c <= 'f' ) return c - 'a' + 10; |
80 | | BOOST_THROW_EXCEPTION (non_hex_input() << bad_char (c)); |
81 | | return 0; // keep dumb compilers happy |
| 72 | template <typename T> T hex_char_to_int ( T c ) { |
| 73 | T r; |
| 74 | if ( c >= static_cast<T>('0') && c <= static_cast<T>('9') ) r = c - static_cast<T>('0'); |
| 75 | else if ( c >= static_cast<T>('A') && c <= static_cast<T>('F') ) r = c - static_cast<T>('A') + 10; |
| 76 | else if ( c >= static_cast<T>('a') && c <= static_cast<T>('f') ) r = c - static_cast<T>('a') + 10; |
| 77 | else BOOST_THROW_EXCEPTION (non_hex_input() << (boost::error_info<struct bad_char_,T> (c))); |
| 78 | return r; |