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()
63 (*out) << "</SLintResult>\n";
69 const std::string SLintXmlResult::getStr(const std::wstring & str)
71 return scilab::UTF8::toUTF8(replaceByEntities(str));
74 void SLintXmlResult::handleMessage(SLintContext & context, const Location & loc, const SLintChecker & checker, const unsigned sub, const std::wstring & msg)
76 if (context.getSciFile().get() != current.get())
80 (*out) << " </File>\n";
82 current = context.getSciFile();
85 print(loc, checker, sub, msg);
88 void SLintXmlResult::print(const SciFilePtr & file)
90 (*out) << " <File name=\"" << getStr(file->getFilename()) << "\">\n";
93 void SLintXmlResult::print(const Location & loc, const SLintChecker & checker, const unsigned sub, const std::wstring & msg)
95 (*out) << " <Result>\n";
99 (*out) << " </Result>\n";
102 void SLintXmlResult::print(const Location & loc)
104 (*out) << " <Location first_line=\"" << loc.first_line
105 << "\" first_column=\"" << loc.first_column
106 << "\" last_line=\"" << loc.last_line
107 << "\" last_column=\"" << loc.last_column
111 void SLintXmlResult::print(const SLintChecker & checker, const unsigned sub)
113 (*out) << " <Checker name=\"" << checker.getName()
114 << "\" id=\"" << getStr(checker.getId(sub))
118 void SLintXmlResult::print(const std::wstring & msg)
120 (*out) << " <Message text=\"" << getStr(msg)
124 std::wstring SLintXmlResult::replaceByEntities(const std::wstring & seq)
126 std::vector<wchar_t> buf;
131 pushEntity(buf, L"<", 4);
135 pushEntity(buf, L">", 4);
139 pushEntity(buf, L"'", 6);
143 pushEntity(buf, L""", 6);
147 pushEntity(buf, L"&", 5);
155 return std::wstring(buf.begin(), buf.end());