Rev 969 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 969 | Rev 976 | ||
|---|---|---|---|
| 1 | /*************************************************************************** |
1 | /*************************************************************************** |
| 2 | * Copyright (C) 2003 by Mattias Runge * |
2 | * Copyright (C) 2003 by Mattias Runge * |
| 3 | * mattias@mrunge.se * |
3 | * mattias@mrunge.se * |
| 4 | * * |
4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 2 of the License, or * |
7 | * the Free Software Foundation; either version 2 of the License, or * |
| 8 | * (at your option) any later version. * |
8 | * (at your option) any later version. * |
| 9 | * * |
9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
13 | * GNU General Public License for more details. * |
| 14 | * * |
14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program; if not, write to the * |
16 | * along with this program; if not, write to the * |
| 17 | * Free Software Foundation, Inc., * |
17 | * Free Software Foundation, Inc., * |
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 19 | ***************************************************************************/ |
19 | ***************************************************************************/ |
| 20 | #ifndef _TOOLS_H |
20 | #ifndef _TOOLS_H |
| 21 | #define _TOOLS_H |
21 | #define _TOOLS_H |
| 22 | 22 | ||
| 23 | #include <string> |
23 | #include <string> |
| 24 | #include <vector> |
24 | #include <vector> |
| 25 | #include <fstream> |
25 | #include <fstream> |
| 26 | #include <sstream> |
26 | #include <sstream> |
| 27 | 27 | ||
| 28 | using namespace std; |
28 | using namespace std; |
| 29 | 29 | ||
| 30 | #include <cmath> |
30 | #include <cmath> |
| 31 | #include <sys/types.h> |
31 | #include <sys/types.h> |
| 32 | #include <dirent.h> |
32 | #include <dirent.h> |
| 33 | 33 | ||
| 34 | string hex2bin(string hex); |
34 | string hex2bin(string hex); |
| 35 | string bin2hex(string bin); |
35 | string bin2hex(string bin); |
| 36 | 36 | ||
| 37 | float bin2float(string bin); |
37 | float bin2float(string bin); |
| 38 | string float2bin(float num, int length); |
38 | string float2bin(float num, int length); |
| 39 | 39 | ||
| 40 | unsigned int bin2uint(string bin); |
40 | unsigned int bin2uint(string bin); |
| 41 | string uint2bin(unsigned int num, int length); |
41 | string uint2bin(unsigned int num, int length); |
| 42 | 42 | ||
| 43 | vector<string> explode(string delimiter, string str); |
43 | vector<string> explode(string delimiter, string str); |
| 44 | string strtoupper(string s); |
44 | string strtoupper(string s); |
| 45 | string strtolower(string s); |
45 | string strtolower(string s); |
| 46 | string trim(string s); |
46 | string trim(string s); |
| 47 | string trim(string s, char c); |
47 | string trim(string s, char c); |
| 48 | int stoi(const string s); |
48 | int stoi(const string s); |
| 49 | string itos(int i); |
49 | string itos(int i); |
| 50 | float stof(const string s); |
50 | float stof(const string s); |
| 51 | string ftos(float f); |
51 | string ftos(float f); |
| 52 | string str_replace(string search, string replace, string str); |
52 | string str_replace(string search, string replace, string str); |
| 53 | string file_get_contents(string filename); |
53 | string file_get_contents(string filename); |
| 54 | bool file_exists(string filename); |
54 | bool file_exists(string filename); |
| 55 | string escape(string in); |
55 | string escape(string in); |
| - | 56 | string rpad(string in, int length, char c); |
|
| - | 57 | string lpad(string in, int length, char c); |
|
| 56 | 58 | ||
| 57 | class FileTools |
59 | class FileTools |
| 58 | { |
60 | { |
| 59 | public: |
61 | public: |
| 60 | static vector<string> GetDirList(string path); |
62 | static vector<string> GetDirList(string path); |
| 61 | static string GetUniqeFilename(string path, string prefix, string postfix); |
63 | static string GetUniqeFilename(string path, string prefix, string postfix); |
| 62 | static string GetUniqeFilename(string path) { return GetUniqeFilename(path, "", ""); } |
64 | static string GetUniqeFilename(string path) { return GetUniqeFilename(path, "", ""); } |
| 63 | static bool SaveFile(string filepath, string data); |
65 | static bool SaveFile(string filepath, string data); |
| 64 | static string Get(string src); |
66 | static string Get(string src); |
| 65 | static bool Copy(string src, string dest); |
67 | static bool Copy(string src, string dest); |
| 66 | static bool Exist(string filename); |
68 | static bool Exist(string filename); |
| 67 | 69 | ||
| 68 | }; |
70 | }; |
| 69 | 71 | ||
| 70 | #endif // _TOOLS_H |
72 | #endif // _TOOLS_H |
| 71 | 73 | ||