Audio 1.0.0
utils.h
Go to the documentation of this file.
1
11#ifndef UTILS_H
12#define UTILS_H
13#include <string>
14
20inline void openWebLink(std::string url)
21{
22 std::string op;
23#ifdef _WIN32
24 op = std::string("start ").append(url);
25#else
26 op = std::string("xdg-open ").append(url);
27#endif
28 system(op.c_str());
29}
30
37template <typename T> int min(T value1, T value2)
38{
39 return value1 < value2 ? value1 : value2;
40}
41
47inline std::string getFileName(const std::string& path)
48{
49 size_t lastIndex = path.find_last_of("\\/");
50 std::string filename = path;
51 if (std::string::npos != lastIndex)
52 {
53 filename.erase(0, lastIndex + 1);
54 }
55
56 // Remove file extension if present.
57 const size_t periodIndex = filename.rfind('.');
58 if (std::string::npos != periodIndex)
59 {
60 filename.erase(periodIndex);
61 }
62 return filename;
63}
64#endif
std::string getFileName(const std::string &path)
Get filename from file path.
Definition: utils.h:47
int min(T value1, T value2)
Get min value.
Definition: utils.h:37
void openWebLink(std::string url)
Open url in default web browser.
Definition: utils.h:20