diff options
author | Tobias Markmann <tm@ayena.de> | 2016-11-23 07:09:39 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2016-11-23 11:30:02 (GMT) |
commit | e405ff3561be3d3c0bd79d7d5173923a8828cf02 (patch) | |
tree | 9118ef838ebfaec1df90ec24761944b5d833774c /Swiften/Client/XMLBeautifier.cpp | |
parent | 8a71b91be885652f37c5aab5e1ecf25af4599fbc (diff) | |
download | swift-e405ff3561be3d3c0bd79d7d5173923a8828cf02.zip swift-e405ff3561be3d3c0bd79d7d5173923a8828cf02.tar.bz2 |
Migrate remaining Swiften/Base/foreach.h use to range-based for loop
Test-Information:
Build on macOS 10.12.1 and all tests pass.
Change-Id: Iedaa3fa7e7672c77909fd0568bf30e9393cb87e0
Diffstat (limited to 'Swiften/Client/XMLBeautifier.cpp')
-rw-r--r-- | Swiften/Client/XMLBeautifier.cpp | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/Swiften/Client/XMLBeautifier.cpp b/Swiften/Client/XMLBeautifier.cpp index 9e9c4c5..e2cd58e 100644 --- a/Swiften/Client/XMLBeautifier.cpp +++ b/Swiften/Client/XMLBeautifier.cpp @@ -1,49 +1,48 @@ /* * Copyright (c) 2011 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Client/XMLBeautifier.h> #include <sstream> #include <stack> #include <Swiften/Base/Log.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Parser/PlatformXMLParserFactory.h> namespace Swift { XMLBeautifier::XMLBeautifier(bool indention, bool coloring) : doIndention(indention), doColoring(coloring), intLevel(0), parser(nullptr), lastWasStepDown(false) { factory = new PlatformXMLParserFactory(); } XMLBeautifier::~XMLBeautifier() { delete factory; } std::string XMLBeautifier::beautify(const std::string &text) { parser = factory->createXMLParser(this); intLevel = 0; buffer.str(std::string()); parser->parse(text); delete parser; return buffer.str(); } void XMLBeautifier::indent() { for (int i = 0; i < intLevel; ++i) { buffer << " "; } } // all bold but reset // static const char colorBlue[] = "\x1b[01;34m"; static const char colorCyan[] = "\x1b[01;36m"; @@ -72,61 +71,61 @@ std::string XMLBeautifier::styleNamespace(const std::string& text) const { } std::string XMLBeautifier::styleAttribute(const std::string& text) const { std::string result; result += colorGreen; result += text; result += colorReset; return result; } std::string XMLBeautifier::styleValue(const std::string& text) const { std::string result; result += colorCyan; result += text; result += colorReset; return result; } void XMLBeautifier::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (doIndention) { if (intLevel) buffer << std::endl; } indent(); buffer << "<" << (doColoring ? styleTag(element) : element); if (!ns.empty() && (!parentNSs.empty() && parentNSs.top() != ns)) { buffer << " "; buffer << (doColoring ? styleAttribute("xmlns") : "xmlns"); buffer << "="; buffer << "\"" << (doColoring ? styleNamespace(ns) : ns) << "\""; } if (!attributes.getEntries().empty()) { - foreach(AttributeMap::Entry entry, attributes.getEntries()) { + for (const auto& entry : attributes.getEntries()) { buffer << " "; buffer << (doColoring ? styleAttribute(entry.getAttribute().getName()) : entry.getAttribute().getName()); buffer << "="; buffer << "\"" << (doColoring ? styleValue(entry.getValue()) : entry.getValue()) << "\""; } } buffer << ">"; ++intLevel; lastWasStepDown = false; parentNSs.push(ns); } void XMLBeautifier::handleEndElement(const std::string& element, const std::string& /* ns */) { --intLevel; parentNSs.pop(); if (/*hadCDATA.top() ||*/ lastWasStepDown) { if (doIndention) { buffer << std::endl; } indent(); } buffer << "</" << (doColoring ? styleTag(element) : element) << ">"; lastWasStepDown = true; } void XMLBeautifier::handleCharacterData(const std::string& data) { buffer << data; lastWasStepDown = false; } |