-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.cpp
More file actions
119 lines (103 loc) · 2.54 KB
/
test.cpp
File metadata and controls
119 lines (103 loc) · 2.54 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
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
#include <string>
#include <regex>
#include <string>
#include <iostream>
#include <fstream>
#include <map>
//#include "libconfig.h++"
//#define S "M[TA]+\\+[SL][0-9]+<;>.*"
using namespace std;
//using namespace libconfig;
string cleanchar(string val,char c){
int i = val.find(c);
string s = val;
while (i > 0){
s.erase(i,1);
cout << "cleaning:" << s << endl;
i = s.find(c);
}
return s;
}
string cleanString(string val){
int i;
string s;
s = cleanchar(val, '"');
s = cleanchar(s,';');
s = cleanchar(s,' ');
return s;
}
pair <string,string> getpair(string val){
pair <string,string> ret;
string key;
string value;
string s;
s = cleanString(val);
cout << "cleaned:" << s << endl;
int i = val.find("=");
if (i > 0){
key = s.substr(0,i);
value = s.substr(i + 1, s.length());
cout << "key: " << key << endl;
cout << "value: " << value << endl;
ret = std::make_pair(key, value);
return ret;
}
return std::make_pair("0","0");
}
int main (){
/*
string s = "MT+L300<;>L300";
string se = S;
regex e = regex (se);
cout << "start" << endl;
if (regex_match(s,e)){
cout << "got a match" << endl;
}
Config cfg;
string key,value;
try
{
cfg.readFile("teste.cfg");
cout << "key: ";
cin >> key;
cout <<"value: ";
cin >> value;
cout << "key :" << key << " value: " << value << endl;
if (cfg.exists(key)){
libconfig::Setting &varkey = cfg.lookup(key);
varkey = atoi(value.c_str());
cfg.writeFile("teste.cfg");
}
}
catch(const FileIOException &fioex)
{
std::cerr << "File I/O error" << std::endl;
}
catch(const ParseException &pex)
{
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
<< " - " << pex.getError() << std::endl;
}
*/
ifstream myfile;
string line;
map <string,string> m;
pair <string,string> p;
myfile.open ("canpi.cfg",ios::in);
if (myfile.is_open ()){
while ( getline (myfile, line) ){
cout << line << endl;
p = getpair (line);
if ( (get<0>(p)) != "0") m.insert(p);
}
myfile.close();
}
else{
cout << "Failed to open the file" << endl;
}
if (m.size() > 0){
map<string,string>::iterator it = m.begin();
for (it = m.begin(); it != m.end(); it++)
cout << "key:" << it->first << " value:" << it->second << endl;
}
}