From b5430ab45be78154e355f1e1dcb4bd66a5742953 Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Tue, 23 Jul 2019 18:49:47 +0200 Subject: [PATCH] Fix parse tree dot-file output when dealing with strings String must be escaped to prevent dot-file bad syntax --- src/language/ASTDotPrinter.cpp | 2 +- src/utils/EscapedString.hpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/language/ASTDotPrinter.cpp b/src/language/ASTDotPrinter.cpp index 7339d6230..c01b90642 100644 --- a/src/language/ASTDotPrinter.cpp +++ b/src/language/ASTDotPrinter.cpp @@ -11,7 +11,7 @@ ASTDotPrinter::_print(std::ostream& os, const ASTNode& node) const } else { if (node.has_content()) { os << " x" << m_node_number_map.at(&node) << " [ label=\"" << node.name() << "\\n" - << node.string_view() << "\\n" + << escapeString(node.string_view()) << "\\n" << dataTypeName(node.m_data_type) << "\" ]\n"; } else { os << " x" << m_node_number_map.at(&node) << " [ label=\"" << node.name() << "\\n" diff --git a/src/utils/EscapedString.hpp b/src/utils/EscapedString.hpp index a89fea027..08b384abc 100644 --- a/src/utils/EscapedString.hpp +++ b/src/utils/EscapedString.hpp @@ -3,11 +3,12 @@ #include <sstream> #include <string> +#include <string_view> #include <PugsMacros.hpp> PUGS_INLINE std::string -unescapeString(const std::string& input_string) +unescapeString(const std::string_view& input_string) { std::stringstream ss; for (size_t i = 1; i < input_string.size() - 1; ++i) { @@ -70,7 +71,7 @@ unescapeString(const std::string& input_string) } PUGS_INLINE std::string -escapeString(const std::string& input_string) +escapeString(const std::string_view& input_string) { std::stringstream ss; for (size_t i = 0; i < input_string.size(); ++i) { -- GitLab