-
Notifications
You must be signed in to change notification settings - Fork 284
/
Copy pathutil.cpp
102 lines (83 loc) · 1.86 KB
/
util.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* Created by Ryan Jay 15.11.16
* Covered by the GPL. v3 (see included LICENSE)
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include "util.hpp"
using namespace std;
float scoreMax(vector<float> x)
{
return *max_element(x.begin(), x.end());
}
int scoreArgMax(vector<float> x)
{
return distance(x.begin(), max_element(x.begin(), x.end()));
}
string getFileName(const string& s)
{
char sep = '/';
#ifdef _WIN32
sep = '\\';
#endif
size_t i = s.rfind(sep, s.length());
if( i != string::npos)
return(s.substr(i+1, s.length() -i));
return(s);
}
string getFileExtension(const string& s)
{
char sep = '.';
size_t i = s.rfind(sep, s.length());
if( i != string::npos)
return(s.substr(i, s.length() -i));
return(s);
}
string getBaseName(const string& s)
{
char sep = '.';
size_t i = s.rfind(sep, s.length());
if( i != string::npos)
return(s.substr(0, i));
return(s);
}
bool queryYesNo()
{
cout << "Replace movie with cut? This will delete the movie. [y/N]?";
string input;
getline(cin, input);
if( input == "YES" || input == "Yes" || input == "yes"
|| input == "Y" || input == "y")
return true;
else
return false;
}
string PrettyTime(int seconds)
{
int s, h, m;
string pTime = "";
m = (seconds / 60);
h = int(m / 60)%60;
m = int(m % 60);
s = int(seconds%60);
if(h > 0)
pTime += to_string(h) + "h";
if(seconds >= 60)
pTime += to_string(m) + "m";
pTime += to_string(s) + "s";
return(pTime);
}
std::string getDirectory (const std::string& path)
{
int found = path.find_last_of("/\\");
if(found < 0)
return(".");
else
return(path.substr(0, found));
}