KSyntaxHighlighting

contextswitch.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
3 SPDX-FileCopyrightText: 2024 Jonathan Poelen <jonathan.poelen@gmail.com>
4
5 SPDX-License-Identifier: MIT
6*/
7
8#include "contextswitch_p.h"
9#include "definition_p.h"
10#include "ksyntaxhighlighting_logging.h"
11
12using namespace KSyntaxHighlighting;
13
14void ContextSwitch::resolve(DefinitionData &def, QStringView context)
15{
16 if (context.isEmpty() || context == QStringLiteral("#stay")) {
17 return;
18 }
19
20 while (context.startsWith(QStringLiteral("#pop"))) {
21 ++m_popCount;
22 if (context.size() > 4 && context.at(4) == QLatin1Char('!')) {
23 context = context.sliced(5);
24 break;
25 }
26 context = context.sliced(4);
27 }
28
29 m_isStay = !m_popCount;
30
31 if (context.isEmpty()) {
32 return;
33 }
34
35 const qsizetype defNameIndex = context.indexOf(QStringLiteral("##"));
36 auto defName = (defNameIndex <= -1) ? QStringView() : context.sliced(defNameIndex + 2);
37 auto contextName = (defNameIndex <= -1) ? context : context.sliced(0, defNameIndex);
38
39 m_context = def.resolveIncludedContext(defName, contextName).context;
40
41 if (m_context) {
42 m_isStay = false;
43 } else {
44 qCWarning(Log) << "cannot find context" << contextName << "in" << def.name;
45 }
46}
Syntax highlighting engine for Kate syntax definitions.
QChar at(qsizetype n) const const
qsizetype indexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
qsizetype size() const const
QStringView sliced(qsizetype pos) const const
bool startsWith(QChar ch) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:09:06 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.