| 25 | |
| 26 | template <unsigned int BITS> |
| 27 | void base_blob<BITS>::SetHex(const char* psz) |
| 28 | { |
| 29 | memset(data, 0, sizeof(data)); |
| 30 | |
| 31 | // skip leading spaces |
| 32 | while (isspace(*psz)) |
| 33 | psz++; |
| 34 | |
| 35 | // skip 0x |
| 36 | if (psz[0] == '0' && tolower(psz[1]) == 'x') |
| 37 | psz += 2; |
| 38 | |
| 39 | // hex string to uint |
| 40 | const char* pbegin = psz; |
| 41 | while (::HexDigit(*psz) != -1) |
| 42 | psz++; |
| 43 | psz--; |
| 44 | unsigned char* p1 = (unsigned char*)data; |
| 45 | unsigned char* pend = p1 + WIDTH; |
| 46 | while (psz >= pbegin && p1 < pend) { |
| 47 | *p1 = ::HexDigit(*psz--); |
| 48 | if (psz >= pbegin) { |
| 49 | *p1 |= ((unsigned char)::HexDigit(*psz--) << 4); |
| 50 | p1++; |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | template <unsigned int BITS> |
| 56 | void base_blob<BITS>::SetHex(const std::string& str) |