/
utils.cpp
63 lines (45 loc) · 1.08 KB
/
utils.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
#include <QFile>
#include "utils.h"
Utils::Utils()
{
}
bool Utils::ParseInfo (const QString &fname, QHash <QString, QString> &map, const QStringList &keys)
{
QFile fd(fname);
fd.open (QIODevice::ReadOnly);
if (fd.isOpen())
{
QString string = fd.readAll();
fd.close ();
QStringList lineList = string.split("\n");
foreach (QString line, lineList)
{
foreach (QString key, keys)
{
int ind = line.indexOf(key);
if (ind >= 0)
{
line.remove (key);
ind = line.indexOf(":");
if (ind >= 0) line.remove (0, ind + 1);
map[key] = line.simplified();
break;
}
}
}
return 1;
}
return 0;
}
QString Utils::readFile (const QString &fname)
{
QFile fd(fname);
fd.open (QIODevice::ReadOnly);
if (fd.isOpen())
{
QString str = fd.readAll();
fd.close ();
return str;
}
return QString();
}