Changeset View
Changeset View
Standalone View
Standalone View
core/KGpgGroupNode.cpp
Show All 23 Lines | |||||
24 | #include "KGpgGroupMemberNode.h" | 24 | #include "KGpgGroupMemberNode.h" | ||
25 | #include "KGpgRootNode.h" | 25 | #include "KGpgRootNode.h" | ||
26 | #include "kgpgsettings.h" | 26 | #include "kgpgsettings.h" | ||
27 | 27 | | |||
28 | #include <KLocalizedString> | 28 | #include <KLocalizedString> | ||
29 | 29 | | |||
30 | 30 | | |||
31 | #include <QFile> | 31 | #include <QFile> | ||
32 | #include <QRegularExpression> | ||||
32 | #include <QStringList> | 33 | #include <QStringList> | ||
33 | #include <QTextStream> | 34 | #include <QTextStream> | ||
34 | 35 | | |||
35 | class KGpgGroupNodePrivate { | 36 | class KGpgGroupNodePrivate { | ||
36 | public: | 37 | public: | ||
37 | KGpgGroupNodePrivate(const QString &name); | 38 | KGpgGroupNodePrivate(const QString &name); | ||
38 | 39 | | |||
39 | QString m_name; | 40 | QString m_name; | ||
40 | 41 | | |||
41 | /** | 42 | /** | ||
42 | * @brief find the line that defines this group in the configuration | 43 | * @brief find the line that defines this group in the configuration | ||
43 | * @param conffile file object (will be initialized) | 44 | * @param conffile file object (will be initialized) | ||
44 | * @param stream text stream (will be initialized and connected to conffile) | 45 | * @param stream text stream (will be initialized and connected to conffile) | ||
45 | * @param lines the lines found in conffile (will be filled) | 46 | * @param lines the lines found in conffile (will be filled) | ||
46 | * @return the index in lines of the entry defining this group | 47 | * @return the index in lines of the entry defining this group | ||
47 | * @retval -1 no entry defining this group was found | 48 | * @retval -1 no entry defining this group was found | ||
48 | * | 49 | * | ||
49 | * stream will be positioned at the beginning. | 50 | * stream will be positioned at the beginning. | ||
50 | */ | 51 | */ | ||
51 | int findGroupEntry(QFile &conffile, QTextStream &stream, QStringList &lines); | 52 | int findGroupEntry(QFile &conffile, QTextStream &stream, QStringList &lines); | ||
52 | 53 | | |||
53 | static const QRegExp &groupPattern(); | 54 | static const QRegularExpression &groupPattern(); | ||
54 | static const QString &groupTag(); | 55 | static const QString &groupTag(); | ||
55 | }; | 56 | }; | ||
56 | 57 | | |||
57 | KGpgGroupNodePrivate::KGpgGroupNodePrivate(const QString &name) | 58 | KGpgGroupNodePrivate::KGpgGroupNodePrivate(const QString &name) | ||
58 | : m_name(name) | 59 | : m_name(name) | ||
59 | { | 60 | { | ||
60 | } | 61 | } | ||
61 | 62 | | |||
Show All 12 Lines | 65 | { | |||
74 | int index = -1; | 75 | int index = -1; | ||
75 | int i = -1; | 76 | int i = -1; | ||
76 | 77 | | |||
77 | while (!stream.atEnd()) { | 78 | while (!stream.atEnd()) { | ||
78 | const QString rawLine = stream.readLine(); | 79 | const QString rawLine = stream.readLine(); | ||
79 | i++; | 80 | i++; | ||
80 | QString parsedLine = rawLine.simplified().section(QLatin1Char('#'), 0, 0); | 81 | QString parsedLine = rawLine.simplified().section(QLatin1Char('#'), 0, 0); | ||
81 | 82 | | |||
82 | if (groupPattern().exactMatch(parsedLine)) { | 83 | if (groupPattern().match(parsedLine).hasMatch()) { | ||
83 | // remove "group " | 84 | // remove "group " | ||
84 | parsedLine.remove(0, 6); | 85 | parsedLine.remove(0, 6); | ||
85 | if (parsedLine.startsWith(m_name)) { | 86 | if (parsedLine.startsWith(m_name)) { | ||
86 | if (parsedLine.midRef(m_name.length()).trimmed().startsWith(QLatin1Char('='))) { | 87 | if (parsedLine.midRef(m_name.length()).trimmed().startsWith(QLatin1Char('='))) { | ||
87 | if (index >= 0) { | 88 | if (index >= 0) { | ||
88 | // multiple definitions of the same group, drop the second one | 89 | // multiple definitions of the same group, drop the second one | ||
89 | continue; | 90 | continue; | ||
90 | } else { | 91 | } else { | ||
91 | index = i; | 92 | index = i; | ||
92 | } | 93 | } | ||
93 | } | 94 | } | ||
94 | } | 95 | } | ||
95 | } | 96 | } | ||
96 | 97 | | |||
97 | lines << rawLine; | 98 | lines << rawLine; | ||
98 | } | 99 | } | ||
99 | 100 | | |||
100 | stream.seek(0); | 101 | stream.seek(0); | ||
101 | 102 | | |||
102 | return index; | 103 | return index; | ||
103 | } | 104 | } | ||
104 | 105 | | |||
105 | const QRegExp & | 106 | const QRegularExpression & | ||
106 | KGpgGroupNodePrivate::groupPattern() | 107 | KGpgGroupNodePrivate::groupPattern() | ||
107 | { | 108 | { | ||
108 | static const QRegExp groupre(QLatin1String("^group [^ ]+ ?= ?([0-9a-fA-F]{8,} ?)*$")); | 109 | static const QRegularExpression groupre(QStringLiteral("^group [^ ]+ ?= ?([0-9a-fA-F]{8,} ?)*$")); | ||
109 | 110 | | |||
110 | return groupre; | 111 | return groupre; | ||
111 | } | 112 | } | ||
112 | 113 | | |||
113 | const QString & | 114 | const QString & | ||
114 | KGpgGroupNodePrivate::groupTag() | 115 | KGpgGroupNodePrivate::groupTag() | ||
115 | { | 116 | { | ||
116 | static const QString grouptag(QLatin1String("group ")); | 117 | static const QString grouptag(QLatin1String("group ")); | ||
▲ Show 20 Lines • Show All 141 Lines • Show Last 20 Lines |