Changeset View
Changeset View
Standalone View
Standalone View
src/lib/keywordlist.cpp
Show All 16 Lines | 1 | /* | |||
---|---|---|---|---|---|
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
22 | */ | 22 | */ | ||
23 | 23 | | |||
24 | #include "keywordlist_p.h" | 24 | #include "keywordlist_p.h" | ||
25 | #include "repository.h" | ||||
26 | #include "definition_p.h" | ||||
27 | #include "ksyntaxhighlighting_logging.h" | ||||
25 | 28 | | |||
26 | #include <QDebug> | 29 | #include <QDebug> | ||
27 | #include <QXmlStreamReader> | 30 | #include <QXmlStreamReader> | ||
28 | 31 | | |||
29 | #include <algorithm> | 32 | #include <algorithm> | ||
30 | 33 | | |||
31 | using namespace KSyntaxHighlighting; | 34 | using namespace KSyntaxHighlighting; | ||
32 | 35 | | |||
Show All 20 Lines | 50 | { | |||
53 | while (!reader.atEnd()) { | 56 | while (!reader.atEnd()) { | ||
54 | switch (reader.tokenType()) { | 57 | switch (reader.tokenType()) { | ||
55 | case QXmlStreamReader::StartElement: | 58 | case QXmlStreamReader::StartElement: | ||
56 | if (reader.name() == QLatin1String("item")) { | 59 | if (reader.name() == QLatin1String("item")) { | ||
57 | m_keywords.append(reader.readElementText().trimmed()); | 60 | m_keywords.append(reader.readElementText().trimmed()); | ||
58 | reader.readNextStartElement(); | 61 | reader.readNextStartElement(); | ||
59 | break; | 62 | break; | ||
60 | } | 63 | } | ||
64 | else if (reader.name() == QLatin1String("include")) { | ||||
65 | m_includes.append(reader.readElementText().trimmed()); | ||||
66 | reader.readNextStartElement(); | ||||
67 | break; | ||||
68 | } | ||||
61 | reader.readNext(); | 69 | reader.readNext(); | ||
62 | break; | 70 | break; | ||
63 | case QXmlStreamReader::EndElement: | 71 | case QXmlStreamReader::EndElement: | ||
64 | reader.readNext(); | 72 | reader.readNext(); | ||
65 | return; | 73 | return; | ||
66 | default: | 74 | default: | ||
67 | reader.readNext(); | 75 | reader.readNext(); | ||
68 | break; | 76 | break; | ||
Show All 28 Lines | 104 | for (const auto &keyword : qAsConst(m_keywords)) { | |||
97 | vectorToSort.push_back(&keyword); | 105 | vectorToSort.push_back(&keyword); | ||
98 | } | 106 | } | ||
99 | 107 | | |||
100 | /** | 108 | /** | ||
101 | * sort with right predicate | 109 | * sort with right predicate | ||
102 | */ | 110 | */ | ||
103 | std::sort(vectorToSort.begin(), vectorToSort.end(), [caseSensitive] (const QStringRef &a, const QStringRef &b) { return a.compare(b, caseSensitive) < 0; }); | 111 | std::sort(vectorToSort.begin(), vectorToSort.end(), [caseSensitive] (const QStringRef &a, const QStringRef &b) { return a.compare(b, caseSensitive) < 0; }); | ||
104 | } | 112 | } | ||
113 | | ||||
114 | void KeywordList::resolveIncludeKeywords(DefinitionData &def) | ||||
115 | { | ||||
116 | while (!m_includes.isEmpty()) { | ||||
117 | const auto kw_include = std::move(m_includes.back()); | ||||
118 | m_includes.pop_back(); | ||||
119 | | ||||
120 | const auto idx = kw_include.indexOf(QLatin1String("##")); | ||||
121 | KeywordList *keywords = nullptr; | ||||
122 | | ||||
123 | if (idx >= 0) { | ||||
124 | auto listName = kw_include.left(idx); | ||||
125 | auto defName = kw_include.mid(idx + 2); | ||||
126 | auto includeDef = def.repo->definitionForName(defName); | ||||
127 | if (includeDef.isValid()) { | ||||
128 | auto defData = DefinitionData::get(includeDef); | ||||
129 | defData->load(DefinitionData::OnlyKeywords(true)); | ||||
130 | keywords = defData->keywordList(listName); | ||||
131 | } | ||||
132 | else { | ||||
133 | qCWarning(Log) << "Unable to resolve external include keyword for definition" << defName << "in" << def.name; | ||||
134 | } | ||||
135 | } else { | ||||
136 | keywords = def.keywordList(kw_include); | ||||
137 | } | ||||
138 | | ||||
139 | if (keywords) { | ||||
140 | if (this != keywords) { | ||||
141 | keywords->resolveIncludeKeywords(def); | ||||
142 | } | ||||
143 | m_keywords += keywords->m_keywords; | ||||
144 | } | ||||
145 | else { | ||||
146 | qCWarning(Log) << "Unresolved include keyword" << kw_include << "in" << def.name; | ||||
147 | } | ||||
148 | } | ||||
149 | } |