|
|
@ -361,15 +361,20 @@ inline int64 abs64(int64 n)
|
|
|
|
template<typename T>
|
|
|
|
template<typename T>
|
|
|
|
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
|
|
|
|
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (itbegin == itend)
|
|
|
|
std::vector<char> rv;
|
|
|
|
return "";
|
|
|
|
static char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
|
|
|
const unsigned char* pbegin = (const unsigned char*)&itbegin[0];
|
|
|
|
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
|
|
|
const unsigned char* pend = pbegin + (itend - itbegin) * sizeof(itbegin[0]);
|
|
|
|
rv.reserve((itend-itbegin)*3);
|
|
|
|
std::string str;
|
|
|
|
for(T it = itbegin; it < itend; ++it)
|
|
|
|
str.reserve((pend-pbegin) * (fSpaces ? 3 : 2));
|
|
|
|
{
|
|
|
|
for (const unsigned char* p = pbegin; p != pend; p++)
|
|
|
|
unsigned char val = (unsigned char)(*it);
|
|
|
|
str += strprintf((fSpaces && p != pend-1 ? "%02x " : "%02x"), *p);
|
|
|
|
if(fSpaces && it != itbegin)
|
|
|
|
return str;
|
|
|
|
rv.push_back(' ');
|
|
|
|
|
|
|
|
rv.push_back(hexmap[val>>4]);
|
|
|
|
|
|
|
|
rv.push_back(hexmap[val&15]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return std::string(rv.begin(), rv.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline std::string HexStr(const std::vector<unsigned char>& vch, bool fSpaces=false)
|
|
|
|
inline std::string HexStr(const std::vector<unsigned char>& vch, bool fSpaces=false)
|
|
|
|