Skip to content
Permalink
Browse files

Port java-style iterators to stl-style

  • Loading branch information
steveire committed Dec 5, 2019
1 parent 5f53c24 commit 00db5a1dd46a0a97e16e4b4f750f0b94a25a055e
@@ -102,10 +102,7 @@ QVariant EscapeJsFilter::doFilter(const QVariant &input,

static const auto jsEscapes = getJsEscapes();

QListIterator<QPair<QString, QString>> it(jsEscapes);

while (it.hasNext()) {
auto escape = it.next();
for (auto &escape : jsEscapes) {
retString = retString.replace(escape.first, escape.second);
}
return retString;
@@ -40,9 +40,7 @@ void DebugNode::render(OutputStream *stream, Context *c) const

ret += QStringLiteral("\n\nContext:\n");
while (!h.isEmpty()) {
QHashIterator<QString, QVariant> it(h);
while (it.hasNext()) {
it.next();
for (auto it = h.begin(), end = h.end(); it != end; ++it) {
ret += QStringLiteral("key ") + it.key() + QStringLiteral(", ")
+ QStringLiteral("type ") + QLatin1String(it.value().typeName())
+ QLatin1Char('\n');
@@ -83,10 +83,9 @@ void IfChangedNode::render(OutputStream *stream, Context *c) const
if (m_filterExpressions.isEmpty()) {
m_trueList.render(watchedStream.data(), c);
}
QListIterator<FilterExpression> i(m_filterExpressions);
QVariantList watchedVars;
while (i.hasNext()) {
auto var = i.next().resolve(c);
for (auto &i : m_filterExpressions) {
auto var = i.resolve(c);
if (!var.isValid()) {
// silent error
return;
@@ -37,10 +37,8 @@ Node *LoadNodeFactory::getNode(const QString &tagContent, Parser *p) const

expr.takeAt(0);

QListIterator<QString> i(expr);
while (i.hasNext()) {
auto libName = i.next();
p->loadLib(libName);
for (auto &i : expr) {
p->loadLib(i);
}

return new LoadNode(p);
@@ -90,9 +90,7 @@ void RegroupNode::render(OutputStream *stream, Context *c) const

QVariantList contextList;
const QString keyName = getSafeString(m_expression.resolve(c));
QListIterator<QVariant> i(objList);
while (i.hasNext()) {
const auto var = i.next();
for (auto &var : objList) {
c->push();
c->insert(QStringLiteral("var"), var);
const QString key = getSafeString(
@@ -101,9 +101,7 @@ QVariant Context::lookup(const QString &str) const
Q_D(const Context);

// return a variant from the stack.
QListIterator<QVariantHash> i(d->m_variantHashStack);
while (i.hasNext()) {
const auto h = i.next();
for (auto &h : d->m_variantHashStack) {
if (h.contains(str)) {
auto var = h.value(str);
// If the user passed a string into the context, turn it into a
@@ -74,11 +74,9 @@ void Engine::addTemplateLoader(QSharedPointer<AbstractTemplateLoader> loader)
QPair<QString, QString> Engine::mediaUri(const QString &fileName) const
{
Q_D(const Engine);
QListIterator<QSharedPointer<AbstractTemplateLoader>> it(d->m_loaders);

QPair<QString, QString> uri;
while (it.hasNext()) {
const auto loader = it.next();
for (auto &loader : d->m_loaders) {
uri = loader->getMediaUri(fileName);
if (!uri.second.isEmpty())
break;
@@ -361,10 +359,7 @@ Template Engine::loadByName(const QString &name) const
{
Q_D(const Engine);

QListIterator<QSharedPointer<AbstractTemplateLoader>> it(d->m_loaders);
while (it.hasNext()) {
const auto loader = it.next();

for (auto &loader : d->m_loaders) {
if (!loader->canLoadTemplate(name))
continue;

@@ -193,9 +193,7 @@ AbstractNodeFactory::getFilterExpressionList(const QStringList &list,
Parser *p) const
{
QList<FilterExpression> fes;
QListIterator<QString> it(list);
while (it.hasNext()) {
const auto varString = it.next();
for (auto &varString : list) {
fes << FilterExpression(varString, p);
}
return fes;
@@ -66,23 +66,22 @@ class ParserPrivate
void ParserPrivate::openLibrary(TagLibraryInterface *library)
{
Q_Q(Parser);
QHashIterator<QString, AbstractNodeFactory *> nodeIt(
library->nodeFactories());

auto ti = qobject_cast<TemplateImpl *>(q->parent());

auto cengine = ti->engine();
Q_ASSERT(cengine);
auto engine = const_cast<Engine *>(cengine);

while (nodeIt.hasNext()) {
nodeIt.next();
auto factories = library->nodeFactories();
for (auto nodeIt = factories.begin(), nodeEnd = factories.end();
nodeIt != nodeEnd; ++nodeIt) {
nodeIt.value()->setEngine(engine);
m_nodeFactories.insert(nodeIt.key(), nodeIt.value());
}
QHashIterator<QString, Filter *> filterIt(library->filters());
while (filterIt.hasNext()) {
filterIt.next();
auto filters = library->filters();
for (auto filterIt = filters.begin(), filterEnd = filters.end();
filterIt != filterEnd; ++filterIt) {
auto f = QSharedPointer<Filter>(filterIt.value());
m_filters.insert(filterIt.key(), f);
}
@@ -54,9 +54,8 @@ Node *BlockNodeFactory::getNode(const QString &tagContent, Parser *p) const
if (loadedBlocksVariant.isValid()
&& loadedBlocksVariant.userType() == qMetaTypeId<QVariantList>()) {
blockVariantList = loadedBlocksVariant.value<QVariantList>();
QListIterator<QVariant> it(blockVariantList);
while (it.hasNext()) {
const auto blockNodeName = it.next().value<QString>();
for (auto &item : blockVariantList) {
const auto blockNodeName = item.value<QString>();

if (blockNodeName == blockName) {
throw Grantlee::Exception(
@@ -30,8 +30,6 @@
#include "template.h"
#include "util.h"

#include <QtCore/QListIterator>

using namespace Grantlee;

ExtendsNodeFactory::ExtendsNodeFactory(QObject *parent)
@@ -141,10 +139,8 @@ void ExtendsNode::render(OutputStream *stream, Context *c) const

const auto parentBlocks
= createNodeMap(parentTemplate->findChildren<BlockNode *>());
QListIterator<Node *> i(nodeList);

while (i.hasNext()) {
auto n = i.next();
for (auto n : nodeList) {
auto tn = qobject_cast<TextNode *>(n);
if (!tn) {
auto en = qobject_cast<ExtendsNode *>(n);
@@ -45,9 +45,8 @@ void ScriptableContext::pop() { m_c->pop(); }
QString ScriptableContext::render(const QList<QObject *> &list) const
{
NodeList nodeList;
QListIterator<QObject *> it(list);
while (it.hasNext()) {
auto node = qobject_cast<Node *>(it.next());
for (auto n : list) {
auto node = qobject_cast<Node *>(n);
if (node)
nodeList << node;
}
@@ -59,9 +59,8 @@ QList<QObject *> ScriptableParser::parse(QObject *parent,

auto nodeList = m_p->parse(node, stopAt);
QList<QObject *> objList;
QListIterator<Node *> it(nodeList);
while (it.hasNext()) {
objList << it.next();
for (auto n : nodeList) {
objList << n;
}
return objList;
}
@@ -232,9 +232,8 @@ QHash<QString, Filter *> ScriptableTagLibrary::filters(const QString &name)
QHash<QString, AbstractNodeFactory *> ScriptableTagLibrary::getFactories()
{
QHash<QString, AbstractNodeFactory *> factories;
QHashIterator<QString, QString> it(m_factoryNames);
while (it.hasNext()) {
it.next();
for (auto it = m_factoryNames.begin(), end = m_factoryNames.end(); it != end;
++it) {
auto factoryName = it.value();
auto tagName = it.key();

@@ -254,9 +253,9 @@ QHash<QString, Filter *> ScriptableTagLibrary::getFilters()
{
QHash<QString, Filter *> filters;

QListIterator<QString> it(m_filterNames);
while (it.hasNext()) {
auto filterObject = m_scriptEngine->globalObject().property(it.next());
for (auto &filterNameString : m_filterNames) {
auto filterObject
= m_scriptEngine->globalObject().property(filterNameString);
auto filterName
= filterObject.property(QStringLiteral("filterName")).toString();
auto filter = new ScriptableFilter(filterObject, m_scriptEngine);
@@ -39,9 +39,8 @@ QList<QObject *> ScriptableTemplate::nodeList() const
auto nodeList = m_template->nodeList();
QList<QObject *> objList;

QListIterator<Node *> it(nodeList);
while (it.hasNext()) {
objList << it.next();
for (auto n : nodeList) {
objList << n;
}
return objList;
}
@@ -50,10 +49,8 @@ void ScriptableTemplate::setNodeList(const QList<QObject *> &list)
{
NodeList nodeList;

QListIterator<QObject *> it(list);

while (it.hasNext()) {
auto n = qobject_cast<Node *>(it.next());
for (auto obj : list) {
auto n = qobject_cast<Node *>(obj);
if (n) {
nodeList << n;
}
@@ -151,10 +151,8 @@ class JSOutputStream : public OutputStream
+ QStringLiteral("%1").arg(i, 2, 16, QLatin1Char('0')).toUpper());
}

QListIterator<QPair<QString, QString>> it(jsEscapes);
auto retString = input;
while (it.hasNext()) {
auto escape = it.next();
for (auto escape : jsEscapes) {
retString = retString.replace(escape.first, escape.second);
}
return retString;
@@ -350,12 +350,14 @@ MarkupDirector::processFragment(QTextBlock::iterator it,
// setHtml, LineSeparator characters are inserted. Here I make sure to
// put them back.
auto sl = fragment.text().split(QChar(QChar::LineSeparator));
QStringListIterator i(sl);
auto i = sl.begin();
auto end = sl.end();
auto paraClosed = false;
while (i.hasNext()) {
m_builder->appendLiteralText(i.next());
if (i.hasNext()) {
if (i.peekNext().isEmpty()) {
while (i != end) {
m_builder->appendLiteralText(*i);
++i;
if (i != end) {
if (i->isEmpty()) {
if (!paraClosed) {
m_builder->endParagraph();
paraClosed = true;

0 comments on commit 00db5a1

Please sign in to comment.
You can’t perform that action at this time.