hdac SDK
SDK for hdac blockchain development
utilstrencodings.h
1 #ifndef STRCODECLIB_H
2 #define STRCODECLIB_H
3 
4 #include <string>
5 #include <vector>
6 
7 std::vector<unsigned char> ParseHex(const char* psz);
8 std::vector<unsigned char> ParseHex(const char* psz,bool &fIsHex);
9 std::vector<unsigned char> ParseHex(const std::string& str);
10 
11 signed char HexDigit(char c);
12 bool IsHex(const std::string& str);
13 
14 template<typename T>
15 std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
16 {
17  std::string rv;
18  static const char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
19  '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
20  rv.reserve((itend-itbegin)*3);
21  for(T it = itbegin; it < itend; ++it)
22  {
23  unsigned char val = (unsigned char)(*it);
24  if(fSpaces && it != itbegin)
25  rv.push_back(' ');
26  rv.push_back(hexmap[val>>4]);
27  rv.push_back(hexmap[val&15]);
28  }
29 
30  return rv;
31 }
32 
33 template<typename T>
34 inline std::string HexStr(const T& vch, bool fSpaces=false)
35 {
36  return HexStr(vch.begin(), vch.end(), fSpaces);
37 }
38 
39 int32_t parseHexToInt32Le(const std::string& hexString);
40 
41 #endif // STRCODECLIB_H