-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpp-utils.h
59 lines (53 loc) · 1.71 KB
/
cpp-utils.h
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
#ifndef FILENAME_UTILS_H
#define FILENAME_UTILS_H
#include <ctime>
#include <stdarg.h>
#include <stdio.h>
#ifdef _WIN32
#include <wchar.h>
#endif
#include <string>
#include <vector>
#ifdef _WIN32
#define __attribute__(x)
#endif
std::string filename_sans_directory(const std::string &filename);
std::string filename_directory(const std::string &filename);
std::string filename_sans_suffix(const std::string &filename);
std::string filename_suffix(const std::string &filename);
std::string string_vprintf(const char *fmt, va_list args);
std::string string_printf(const char *fmt, ...) __attribute__((format(printf,1,2)));
void make_directory(const std::string &dirname);
void make_directory_and_parents(const std::string &dirname);
bool filename_exists(const std::string &filename);
void rename_file(const std::string &src, const std::string &dest);
FILE *fopen_utf8(const std::string &path, const char *mode);
bool iequals(const std::string &a, const std::string &b);
std::string temporary_path(const std::string &path);
std::string hostname();
void throw_error(const char *fmt, ...) __attribute__((format(printf,1,2))) __attribute__((noreturn));
std::string executable_suffix();
std::string executable_path();
std::string application_user_state_directory(const std::string &application_name);
std::string os(); // osx, windows, linux
void get_cpu_usage(double &user, double &system);
class Unicode {
std::string m_utf8;
#ifdef _WIN32
std::vector<wchar_t> m_utf16;
#endif
public:
Unicode(const std::string &utf8);
Unicode(const char *utf8);
#ifdef _WIN32
Unicode(const wchar_t *utf16);
const wchar_t *path();
const wchar_t *utf16();
#else
const char *path();
#endif
const char *utf8();
private:
void init_from_utf8();
};
#endif