mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Add some hex routines to utils.
This commit is contained in:
@@ -19,4 +19,9 @@ boost::posix_time::ptime ptFromSeconds(int iSeconds)
|
||||
: ptEpoch() + boost::posix_time::seconds(iSeconds);
|
||||
}
|
||||
|
||||
char charHex(int iDigit)
|
||||
{
|
||||
return iDigit < 10 ? '0' + iDigit : 'A' - 10 + iDigit;
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
24
src/utils.h
24
src/utils.h
@@ -22,6 +22,30 @@ std::string strJoin(Iterator first, Iterator last, std::string strSeperator)
|
||||
|
||||
return ossValues.str();
|
||||
}
|
||||
|
||||
char charHex(int iDigit);
|
||||
|
||||
template<class Iterator>
|
||||
void strHex(std::string& strDst, Iterator first, int iSize)
|
||||
{
|
||||
strDst.resize(iSize*2);
|
||||
|
||||
for (int i = 0; i < iSize; i++) {
|
||||
unsigned char c = *first++;
|
||||
|
||||
strDst[i*2] = charHex(c >> 4);
|
||||
strDst[i*2+1] = charHex(c & 15);
|
||||
}
|
||||
}
|
||||
|
||||
inline void strHex(std::string& strDst, const std::string& strSrc) {
|
||||
strHex(strDst, strSrc.begin(), strSrc.size());
|
||||
}
|
||||
|
||||
inline void strHex(std::string& strDst, const std::vector<unsigned char> vchData) {
|
||||
strHex(strDst, vchData.begin(), vchData.size());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
Reference in New Issue
Block a user