-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.h
149 lines (123 loc) · 1.97 KB
/
functions.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#pragma once
using namespace std;
bool cal_parity(int value)
{
bool isEven = true;
while (value != 0)
{
if (value & 1)
isEven = !isEven;
value >>= 1;
}
return isEven;
}
string trim(const string inst)
{
string str = "";
string whitespaces = "";
int strlen = inst.length();
bool isFirstCharFound = false;
for (int i = 0; i < strlen; i++)
{
if (inst[i] != ' ')
{
if (!isFirstCharFound)
{
whitespaces = "";
isFirstCharFound = true;
}
str = str + whitespaces + inst[i];
whitespaces = "";
}
else
{
whitespaces += " ";
}
}
return str;
}
int hexToDec(const string hexNum)
{
int decNum = 0;
string dupNum = hexNum;
int exp = 0;
while (!dupNum.empty())
{
int n = (int)dupNum.back();
if ((n >= 65 && n <= 70) ||
(n >= 97 && n <= 102) ||
(n >= 48 && n <= 57))
{
if (n >= 97)
n -= 87;
else
{
if (n >= 65)
n -= 55;
else
n -= 48;
}
}
else
return -1;
decNum += n * (1 << exp);
exp += 4;
dupNum.pop_back();
}
return decNum;
}
vector<string> str_split(string str, string splitpt)
{
vector<string> resStr;
string temp = "";
int strlen = str.length();
int arrlen = splitpt.length();
bool contains = false;
for (int i = 0; i <= strlen; i++)
{
contains = false;
for (int j = 0; j <= arrlen; j++)
{
if (str[i] == splitpt[j])
{
contains = true;
break;
}
}
if (contains)
{
if (temp != "")
resStr.push_back(temp);
temp = "";
}
else
temp += str[i];
}
return resStr;
}
string toLowerCase(string str)
{
string resStr = "";
int strLen = str.length();
for (int i = 0; i < strLen; i++)
{
if (str[i] >= 65 and str[i] <= 90)
resStr += (str[i] + 32);
else
resStr += str[i];
}
return resStr;
}
string toUpperCase(string str)
{
string resStr = "";
int strLen = str.length();
for (int i = 0; i < strLen; i++)
{
if (str[i] >= 97 and str[i] <= 122)
resStr += (str[i] - 32);
else
resStr += str[i];
}
return resStr;
}