-
Notifications
You must be signed in to change notification settings - Fork 1
/
Helper.h
61 lines (52 loc) · 2.06 KB
/
Helper.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 _HELPER_H_
#define _HELPER_H_
#include <string>
#include <sys/stat.h>
#include <vector>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h> // need to use <direct.h> if under windows
#include "global.h"
#define USE_QT
#ifdef USE_QT
#include <qstring.h>
#endif
// This file contains some small utility functions
// remove illegal characters like \, ?, etc. from string intended for filename
std::string validateFilename(std::string s);
// whether file exists
bool fileExists(std::string filename);
// get a lists of string of files (optionally with a certain extension) in a
// directory
int getFileList(std::string dir, std::vector<std::string> &files,
std::string extension);
// get the directory where the program starts from
std::string getCurrentDir();
// concat a list of strings into one, separated by "separator"
std::string joinStrings(std::vector<std::string> strings,
std::string separator);
// remove white spaces from beginning and end of a string
std::string trimString(std::string& s);
// take a string a separator it into two parts, name and value
bool parseNameValuePair(const std::string& s,
std::string& name, std::string& value,
std::string separator = "=");
// convert string to bool
bool atob(const std::string& s);
// convert string to int; wrapper around the standard atoi() for convenience
int atoi(const std::string& s);
// convert string to float; wrapper around the standard atof() for convenience
float atof(const std::string& s);
// convert int to string
std::string itos(const int i);
// convert float to string
std::string ftos(const float);
// get all lines from a file into a vector of strings
void getLines(const std::string& filename, std::vector<std::string>& lines);
// append a line to a file (will be created if not existent)
void appendLine(const std::string& filename, const std::string& line);
#ifdef USE_QT
// shortcut to get std::string to QString without obsessive typing...
QString s(const std::string& str);
#endif // USE_QT
#endif //_HELPER_H_