-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.cpp
106 lines (79 loc) · 1.95 KB
/
convert.cpp
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
#include <iostream>
#include <cmath>
double convert_string_to_param(const std::string& string)
{
std::string first;
double power_of_ten = 0;
double mil = 1;
bool done = false;
bool meg_mil = false;
for(int i = 0; i<string.size() && !done; i++) {
if(isdigit(string[i]) || (string[i] == '.'))
{
first.push_back(string[i]);
}
else
{
//std::cout << "letter";
done = true;
switch (string[i])
{
case 'f':
case 'F':
power_of_ten = -15;
break;
case 'p': //pico
case 'P':
power_of_ten = -12;
break;
case 'n': //nano
case 'N':
power_of_ten = -9;
break;
case 'u': //micro, check if the character is right!!!
case 'U':
power_of_ten = -6;
break;
case 'm':
case 'M':
if(string.size()> i + 2) {
if(((string[i+1]=='E' )|| (string[i+1]=='e') )&& ((string[i+2]=='G')||(string[i+2]=='g')))
//prefix is MEG
{
meg_mil = true;
power_of_ten = 6;
}
else if(((string[i+1]=='I') || (string[i+1]=='i' ))&& ((string[i+2]=='L')||(string[i+2]=='l')))
//prefix is MIL
{
power_of_ten = -6;
mil = 25.4;
meg_mil = true;
}
}
if(!meg_mil) //if it wasn't mega nor mil, it's milli
{
power_of_ten = -3;
}
break;
case 'k': //kilo
case 'K':
power_of_ten = 3;
break;
case 'g': //giga
case 'G':
power_of_ten=9;
break;
case 't': //terra
case 'T':
power_of_ten = 12;
break;
default:
std::cerr << "Invalid multiplier";
break;
}
}
}
return (atof(first.c_str()) * mil * pow(10, power_of_ten));
}
*/