mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
52 lines
1.1 KiB
C++
52 lines
1.1 KiB
C++
#ifndef __UTILS__
|
|
#define __UTILS__
|
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
#include <boost/format.hpp>
|
|
|
|
#define nothing() do {} while (0)
|
|
|
|
boost::posix_time::ptime ptEpoch();
|
|
int iToSeconds(boost::posix_time::ptime ptWhen);
|
|
boost::posix_time::ptime ptFromSeconds(int iSeconds);
|
|
|
|
template<class Iterator>
|
|
std::string strJoin(Iterator first, Iterator last, std::string strSeperator)
|
|
{
|
|
std::ostringstream ossValues;
|
|
|
|
for (Iterator start = first; first != last; first++)
|
|
{
|
|
ossValues << str(boost::format("%s%s") % (start == first ? "" : strSeperator) % *first);
|
|
}
|
|
|
|
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
|