From cd22da1d9e77a9a7b6fe3ecf5bd828977acc6282 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 25 Aug 2017 12:43:58 +0200 Subject: Remove escape function. --- libdevcore/CommonData.cpp | 28 ---------------------------- libsolidity/ast/ASTPrinter.cpp | 14 +++++++++++--- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index 14caf494..db11e61c 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -28,34 +28,6 @@ using namespace std; using namespace dev; -std::string dev::escaped(std::string const& _s, bool _all) -{ - static const map prettyEscapes{{'\r', 'r'}, {'\n', 'n'}, {'\t', 't'}, {'\v', 'v'}}; - std::string ret; - ret.reserve(_s.size() + 2); - ret.push_back('"'); - for (auto i: _s) - if (i == '"' && !_all) - ret += "\\\""; - else if (i == '\\' && !_all) - ret += "\\\\"; - else if (prettyEscapes.count(i) && !_all) - { - ret += '\\'; - ret += prettyEscapes.find(i)->second; - } - else if (i < ' ' || _all) - { - ret += "\\x"; - ret.push_back("0123456789abcdef"[(uint8_t)i / 16]); - ret.push_back("0123456789abcdef"[(uint8_t)i % 16]); - } - else - ret.push_back(i); - ret.push_back('"'); - return ret; -} - int dev::fromHex(char _i, WhenError _throw) { if (_i >= '0' && _i <= '9') diff --git a/libsolidity/ast/ASTPrinter.cpp b/libsolidity/ast/ASTPrinter.cpp index 392179ef..09191433 100644 --- a/libsolidity/ast/ASTPrinter.cpp +++ b/libsolidity/ast/ASTPrinter.cpp @@ -21,9 +21,12 @@ */ #include -#include #include +#include + +#include + using namespace std; namespace dev @@ -579,8 +582,13 @@ void ASTPrinter::printSourcePart(ASTNode const& _node) if (!m_source.empty()) { SourceLocation const& location(_node.location()); - *m_ostream << indentation() << " Source: " - << escaped(m_source.substr(location.start, location.end - location.start), false) << endl; + *m_ostream << + indentation() << + " Source: " << + /// Note: this "abuses" the JSON library to print a string (as it is not a valid root node). + /// It also makes a copy of the string. + jsonCompactPrint(m_source.substr(location.start, location.end - location.start)) << + endl; } } -- cgit From eb33e76416c7e8091bd33365b8b0917a9146868b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 29 Aug 2017 15:51:37 +0100 Subject: Use Json::valueToQuotedString directly --- libsolidity/ast/ASTPrinter.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libsolidity/ast/ASTPrinter.cpp b/libsolidity/ast/ASTPrinter.cpp index 09191433..81e6cc44 100644 --- a/libsolidity/ast/ASTPrinter.cpp +++ b/libsolidity/ast/ASTPrinter.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include @@ -585,9 +585,7 @@ void ASTPrinter::printSourcePart(ASTNode const& _node) *m_ostream << indentation() << " Source: " << - /// Note: this "abuses" the JSON library to print a string (as it is not a valid root node). - /// It also makes a copy of the string. - jsonCompactPrint(m_source.substr(location.start, location.end - location.start)) << + Json::valueToQuotedString(m_source.substr(location.start, location.end - location.start).c_str()) << endl; } } -- cgit