Line data Source code
1 : #ifndef FILECONTENT_H
2 : #define FILECONTENT_H
3 :
4 : #include <QList>
5 : #include <QString>
6 :
7 126 : struct NamedValue {
8 : QString name;
9 : QString value;
10 : };
11 :
12 : /**
13 : * @brief The NamedValues class is mostly a list of \link NamedValue
14 : * but also has a method to take a specific NamedValue pair out of the list.
15 : */
16 200 : class NamedValues : public QList<NamedValue> {
17 : public:
18 : NamedValues();
19 : NamedValues(std::initializer_list<NamedValue> values);
20 :
21 : QString takeValue(const QString &name);
22 : };
23 :
24 28 : class FileContent {
25 : public:
26 : /**
27 : * @brief parse parses the given fileContent in a FileContent object.
28 : * The password is accessible through getPassword.
29 : * The named value pairs (name: value) are parsed and depeding on the
30 : * templateFields and allFields parameters accessible through getNamedValues
31 : * or getRemainingData.
32 : *
33 : * @param fileContent the file content to parse.
34 : *
35 : * @param templateFields the fields in the template.
36 : * Fields in the template will always be in getNamedValues() at the beginning
37 : * of the list in the same order.
38 : *
39 : * @param allFields whether all fields should be considered as named values.
40 : * If set to false only templateFields are returned in getNamedValues().
41 : *
42 : * @return
43 : */
44 : static FileContent parse(const QString &fileContent,
45 : const QStringList &templateFields, bool allFields);
46 :
47 : /**
48 : * @return the password from the parsed file.
49 : */
50 : QString getPassword() const;
51 :
52 : /**
53 : * @return the named values in the file in the order of appearence, with
54 : * template values first.
55 : */
56 : NamedValues getNamedValues() const;
57 :
58 : /**
59 : * @return the data that is not the password and not in getNamedValues.
60 : */
61 : QString getRemainingData() const;
62 :
63 : private:
64 : FileContent(const QString &password, const NamedValues &namedValues,
65 : const QString &remainingData);
66 :
67 : QString password;
68 : NamedValues namedValues;
69 : QString remainingData;
70 : };
71 :
72 : #endif // FILECONTENT_H
|