Changeset View
Changeset View
Standalone View
Standalone View
src/uint256.cpp
Show All 26 Lines | template <unsigned int BITS> void base_blob<BITS>::SetHex(const char *psz) { | ||||
} | } | ||||
// skip 0x | // skip 0x | ||||
if (psz[0] == '0' && ToLower(psz[1]) == 'x') { | if (psz[0] == '0' && ToLower(psz[1]) == 'x') { | ||||
psz += 2; | psz += 2; | ||||
} | } | ||||
// hex string to uint | // hex string to uint | ||||
const char *pbegin = psz; | size_t digits = 0; | ||||
while (::HexDigit(*psz) != -1) { | while (::HexDigit(psz[digits]) != -1) { | ||||
psz++; | digits++; | ||||
} | } | ||||
psz--; | |||||
uint8_t *p1 = (uint8_t *)data; | uint8_t *p1 = (uint8_t *)data; | ||||
uint8_t *pend = p1 + WIDTH; | uint8_t *pend = p1 + WIDTH; | ||||
while (psz >= pbegin && p1 < pend) { | while (digits > 0 && p1 < pend) { | ||||
*p1 = ::HexDigit(*psz--); | *p1 = ::HexDigit(psz[--digits]); | ||||
if (psz >= pbegin) { | if (digits > 0) { | ||||
*p1 |= uint8_t(::HexDigit(*psz--) << 4); | *p1 |= uint8_t(::HexDigit(psz[--digits])) << 4; | ||||
p1++; | p1++; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
template <unsigned int BITS> | template <unsigned int BITS> | ||||
void base_blob<BITS>::SetHex(const std::string &str) { | void base_blob<BITS>::SetHex(const std::string &str) { | ||||
SetHex(str.c_str()); | SetHex(str.c_str()); | ||||
Show All 15 Lines |