-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.cpp
More file actions
44 lines (33 loc) · 881 Bytes
/
util.cpp
File metadata and controls
44 lines (33 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "util.h"
#include "exception.h"
#include <string>
#include <iostream>
#include <typeinfo>
#include <boost/format.hpp>
#include <mbedtls/cipher.h>
#include <mbedtls/md.h>
void Util::time_to_string(std::string &dst, const time_t &ticks)
{
struct tm tm;
char timestring[64];
localtime_r(&ticks, &tm);
strftime(timestring, sizeof(timestring), "%Y/%m/%d %H:%M:%S", &tm);
dst = timestring;
}
std::string Util::dumper(const char *id, const std::string text)
{
int ix;
char current;
std::string out;
out = (boost::format("%s[%d]: \"") % id % text.length()).str();
for(ix = 0; (ix < (int)text.length()) && (ix < 512); ix++)
{
current = text.at(ix);
if((current >= ' ') && (current <= '~'))
out.append(1, current);
else
out.append((boost::format("[%02x]") % ((unsigned int)current & 0xff)).str());
}
out.append("\"");
return(out);
}