-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenFunc.cpp
65 lines (56 loc) · 1.76 KB
/
GenFunc.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
//
// Created by shahaf on 12/22/18.
//
#include "GenFunc.h"
// true if sign is an operator, false otherwise
bool GenFunc::isOperator(char sign) {
return sign == '+' || sign == '-' || sign == '*' || sign == '/';
}
// true if given string is a number, false otherwise
bool GenFunc::isNumber(string &str) {
bool hasOneDigit = false;
for (int i = 0; i < str.length(); ++i) {
if (!isdigit(str[i]) && str[i] != '.' && (str.length() == 1 || i != 0 || str[0] != '-')) {
return false;
}
if (hasOneDigit && str[i] == '.') {
return false;
}
if (str[i] == '.') {
hasOneDigit = true;
}
}
return true;
}
string GenFunc::replaceByVal(string vari, map<string, double> &symbols) {
// check for existing var.
for (auto &var : symbols) {
// check if exist.
int startIndex = vari.find(var.first);
// if its really there.
while (startIndex != vari.npos) {
vari.erase(startIndex, var.first.length());
vari.insert(startIndex, to_string(var.second));
startIndex = vari.find(var.first);
}
}
// return the string.
return vari;
}
bool GenFunc::isSimulatorVar(map<string, string> &paths, string var) {
for(auto &varName: paths){
// its in the binding map and connected to path in the simulator.
if((var == varName.first) &&(varName.second[0] == '/')){
return true;
}
}
return false;
}
string GenFunc::getPath(map<string, string> &paths, string var) {
for (auto &varName : paths) {
// its in the binding map and connected to path in the simulator.
if((var == varName.first) &&(varName.second[0] == '/')){
return varName.second;
}
}
}