-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcpptool.cpp
More file actions
81 lines (77 loc) · 1.29 KB
/
cpptool.cpp
File metadata and controls
81 lines (77 loc) · 1.29 KB
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
#include "cpptool.h"
string transform(int x, int y, string s)
{
string res = "";
int sum = 0;
for (unsigned int i = 0; i < s.length(); ++i)
{
if (s[i] == '-') continue;
if (s[i] >= '0' && s[i] <= '9')
{
sum = sum*x + s[i] - '0';
}
else {
sum = sum*x + s[i] - 'A' + 10;
}
}
while (sum)
{
char temp = sum %y;
sum /= y;
if (temp <= 9)
{
temp += '0';
}
else {
temp = temp - 10 + 'A';
}
res = temp + res;
}
if (res.length() == 0) res = "0";
if (s[0] == '-')
res = '-' + res;
return res;
}
bool endWith(const char * str, const char * end)
{
bool result = false;
if (str != NULL && end != NULL)
{
int l1 = strlen(str);
int l2 = strlen(end);
if (l1 >= l2) {
if (strcmp(str + l1 - l2, end) == 0)
{
result = true;
}
}
}
return result;
}
char* boolToStr(int flag)
{
return flag ? "true" : "false";
}
void getCurrentFileList(std::vector<std::string> &filelist, char *ext)
{
long file;
struct _finddata_t find;
_chdir(".");
if ((file = _findfirst("*.*", &find)) == -1L)
{
return ;
}
if (endWith(find.name, ext))
{
filelist.push_back(string(find.name));
}
while (_findnext(file, &find) == 0)
{
//printf("%s\n", find.name);
if (endWith(find.name, ext))
{
filelist.push_back(string(find.name));
}
}
_findclose(file);
}