blob: 3ec6e4c430b3f94bd63bd97f3d6f2124d54d3c3f (
plain)
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 <string>
#include <sstream>
#include <iomanip>
//#include <stdlib.h> /* for abs() */
#include <cmath>
// strip off the directory part of a path, leaving just
// the basic filename
std::string basename(const std::string path){
size_t where = path.rfind("/");
if (where != std::string::npos) return path.substr(1+where);
return path;
}
////////////////
// little utility to help with argument parsing:
//
int prefix(const std::string shorter, const std::string longer){
return shorter == longer.substr(0, shorter.length());
}
///////////////
// print a time as (-)hh:mm:ss
//
std::string time_out(const int _ttt){
using namespace std;
int ttt(abs(_ttt));
int sec(ttt % 60);
int min((ttt / 60) % 60);
int hr(ttt / 3600);
stringstream foo;
int didsome(0);
if (_ttt < 0) foo << "-";
if (hr) {
foo << hr << ":";
didsome++;
}
if (didsome || min){
foo << setw(didsome?2:1) << setfill('0') << min << ":";
didsome++;
}
foo << setw(didsome?2:1) << setfill('0') << sec;
return foo.str();
}
|