-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
52 lines (47 loc) · 1.14 KB
/
utils.cpp
File metadata and controls
52 lines (47 loc) · 1.14 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
int map(int value, int preLowerBound, int preUpperbound, int postLowerBound, int postUpperbound){
return (value - preLowerBound) * (postUpperbound - postLowerBound) / (preUpperbound - preLowerBound) + postLowerBound;
}
string* getArgs(string input, string delim) {
int delimIndex = 0;
string *args = new string [2];
delimIndex = input.find(delim);
args[0] = input.substr(0, delimIndex);
args[1] = input.erase(0, delimIndex + delim.length());
return args;
}
char* stoch(string x) {
char* array = new char[x.length() + 1];
for (int i =0; i<x.length(); i++)
array[i] = x[i];
array[x.length()] = '\0';
return array;
}
enum STATE {START, DIGIT, TERMINAL};
int stoint(string x){
char* input = stoch(x);
int output = 0;
STATE state = START;
char in;
cout << endl;
for (int i = 0; state != TERMINAL; i++) {
in = input[i];
switch (state) {
case START:
if (in >= '0' && in <= '9') {
output = (int) (in - '0');
state = DIGIT;
}
else
return -1;
break;
case DIGIT:
if (in >= '0' && in <= '9')
output = output * 10 + (int) (in - '0');
else if (in == '\0')
return output;
else
return -1;
break;
}
}
}