2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2015 - Scilab Enterprises - Calixte DENIZET
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 * This file is hereby licensed under the terms of the GNU GPL v2.0,
8 * pursuant to article 5.3.4 of the CeCILL v.2.1.
9 * This file was originally licensed under the terms of the CeCILL v2.1,
10 * and continues to be available under such terms.
11 * For more information, see the COPYING file which you should have received
12 * along with this program.
18 #include "output/SLintXmlResult.hxx"
19 #include "checkers/SLintChecker.hxx"
20 #include "FileException.hxx"
22 #include "SciFile.hxx"
27 #include "sci_malloc.h"
28 #include "charEncoding.h"
29 #include "localization.h"
35 SLintXmlResult::SLintXmlResult(const std::wstring & _path) : current(nullptr), path(_path)
37 const std::wstring fullpath = SLint::getFullPath(path);
38 out = new std::ofstream(scilab::UTF8::toUTF8(fullpath), std::ios::out);
43 throw FileException(fullpath, L"Can\'t open it.");
47 (*out) << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
52 SLintXmlResult::~SLintXmlResult()
61 void SLintXmlResult::finalize()
65 (*out) << " </File>\n";
68 (*out) << "</SLintResult>\n";
74 const std::string SLintXmlResult::getStr(const std::wstring & str)
76 return scilab::UTF8::toUTF8(replaceByEntities(str));
79 void SLintXmlResult::handleMessage(SLintContext & context, const Location & loc, const SLintChecker & checker, const unsigned sub, const std::wstring & msg)
81 if (context.getSciFile().get() != current.get())
85 (*out) << " </File>\n";
87 current = context.getSciFile();
90 print(loc, checker, sub, msg);
93 void SLintXmlResult::print(const SciFilePtr & file)
95 (*out) << " <File name=\"" << getStr(file->getFilename()) << "\">\n";
98 void SLintXmlResult::print(const Location & loc, const SLintChecker & checker, const unsigned sub, const std::wstring & msg)
100 (*out) << " <Result>\n";
104 (*out) << " </Result>\n";
107 void SLintXmlResult::print(const Location & loc)
109 (*out) << " <Location first_line=\"" << loc.first_line
110 << "\" first_column=\"" << loc.first_column
111 << "\" last_line=\"" << loc.last_line
112 << "\" last_column=\"" << loc.last_column
116 void SLintXmlResult::print(const SLintChecker & checker, const unsigned sub)
118 (*out) << " <Checker name=\"" << checker.getName()
119 << "\" id=\"" << getStr(checker.getId(sub))
123 void SLintXmlResult::print(const std::wstring & msg)
125 (*out) << " <Message text=\"" << getStr(msg)
129 std::wstring SLintXmlResult::replaceByEntities(const std::wstring & seq)
131 std::vector<wchar_t> buf;
136 pushEntity(buf, L"<", 4);
140 pushEntity(buf, L">", 4);
144 pushEntity(buf, L"'", 6);
148 pushEntity(buf, L""", 6);
152 pushEntity(buf, L"&", 5);
160 return std::wstring(buf.begin(), buf.end());