mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add strHex(Slice)
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <beast/cxx14/type_traits.h> // <type_traits>
|
||||
@@ -142,6 +143,9 @@ make_Slice (std::basic_string<char, Traits, Alloc> const& s)
|
||||
return Slice(s.data(), s.size());
|
||||
}
|
||||
|
||||
std::string
|
||||
strHex (Slice const& slice);
|
||||
|
||||
} // ripple
|
||||
|
||||
#endif
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/basics/Slice.h>
|
||||
#include <ripple/basics/strHex.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace ripple {
|
||||
@@ -50,4 +52,10 @@ int charUnHex (unsigned char c)
|
||||
return xtab[c];
|
||||
}
|
||||
|
||||
std::string
|
||||
strHex(Slice const& slice)
|
||||
{
|
||||
return strHex(slice.data(), slice.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -64,22 +64,18 @@ charUnHex (char c)
|
||||
|
||||
// NIKB TODO cleanup this function and reduce the need for the many overloads
|
||||
// it has in various places.
|
||||
template<class Iterator>
|
||||
std::string strHex (Iterator first, int iSize)
|
||||
template<class FwdIt>
|
||||
std::string strHex (FwdIt first, int size)
|
||||
{
|
||||
std::string strDst;
|
||||
|
||||
strDst.resize (iSize * 2);
|
||||
|
||||
for (int i = 0; i < iSize; i++)
|
||||
std::string s;
|
||||
s.resize (size * 2);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
unsigned char c = *first++;
|
||||
|
||||
strDst[i * 2] = charHex (c >> 4);
|
||||
strDst[i * 2 + 1] = charHex (c & 15);
|
||||
s[i * 2] = charHex (c >> 4);
|
||||
s[i * 2 + 1] = charHex (c & 15);
|
||||
}
|
||||
|
||||
return strDst;
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user