23 #include "metaenumvariable_p.h"
24 #include "nodebuiltins_p.h"
28 #include <QtCore/QRegularExpressionMatchIterator>
38 Q_DECLARE_PUBLIC(
Node)
46 #if defined(Q_CC_MSVC)
49 #define STRING_LITERAL QLatin1String
51 #define STRING_LITERAL QStringLiteral
53 smartSplitRe = QRegularExpression(
59 "(?:[^\"\\\\]|\\\\.)*\""
62 "(?:[^\'\\\\]|\\\\.)*\'"
80 QRegularExpression smartSplitRe;
92 if (input.userType() == qMetaTypeId<QVariantList>()) {
93 inputString = toString(input.value<QVariantList>());
94 }
else if (input.userType() == qMetaTypeId<MetaEnumVariable>()) {
95 const auto mev = input.value<MetaEnumVariable>();
97 (*stream) << QString::number(mev.value);
101 if (c->autoEscape() && !inputString.
isSafe())
102 inputString.setNeedsEscape(
true);
104 (*stream) << inputString;
109 auto _parent = parent();
110 auto ti = qobject_cast<TemplateImpl *>(_parent);
111 while (_parent && !ti) {
112 _parent = _parent->parent();
113 ti = qobject_cast<TemplateImpl *>(_parent);
123 m_containsNonText = list.m_containsNonText;
128 static_cast<QList<Cutelee::Node *> &
>(*this)
129 =
static_cast<QList<Cutelee::Node *>
>(list);
130 m_containsNonText = list.m_containsNonText;
138 auto textNode = qobject_cast<TextNode *>(node);
140 m_containsNonText =
true;
144 m_containsNonText =
false;
151 if (!m_containsNonText) {
152 auto textNode = qobject_cast<TextNode *>(node);
154 m_containsNonText =
true;
157 QList<Cutelee::Node *>::append(node);
162 if (!m_containsNonText) {
164 auto textNode = qobject_cast<const TextNode *>(node);
166 m_containsNonText =
true;
172 QList<Cutelee::Node *>::append(nodeList);
179 for (
auto i = 0; i < this->size(); ++i) {
180 this->at(i)->render(stream, c);
191 QList<FilterExpression>
195 QList<FilterExpression> fes;
196 for (
auto &varString : list) {
207 auto i = d->smartSplitRe.globalMatch(str);
208 while (i.hasNext()) {
209 auto match = i.next();
210 l.append(match.captured());
Base class for all NodeFactories.
~AbstractNodeFactory() override
AbstractNodeFactory(QObject *parent={})
QList< FilterExpression > getFilterExpressionList(const QStringList &list, Parser *p) const
Q_INVOKABLE QStringList smartSplit(const QString &str) const
The Context class holds the context to render a Template with.
A FilterExpression object represents a filter expression in a template.
A list of Nodes with some convenience API for rendering them.
bool containsNonText() const
void render(OutputStream *stream, Context *c) const
void append(Cutelee::Node *node)
Base class for all nodes.
void streamValueInContext(OutputStream *stream, const QVariant &input, Cutelee::Context *c) const
TemplateImpl * containerTemplate() const
The OutputStream class is used to render templates to a QTextStream.
The Parser class processes a string template into a tree of nodes.
A QString wrapper class for containing whether a string is safe or needs to be escaped.
The Cutelee namespace holds all public Cutelee API.
Cutelee::SafeString getSafeString(const QVariant &input)
Utility functions used throughout Cutelee.