undoStudio
The IDE of the undoRT ecosystem
Loading...
Searching...
No Matches
undoAppSTOutput.hpp
Go to the documentation of this file.
1
22#ifndef UNDOSTUDIO_UNDOAPP_STOUTPUTFILTER_HPP
23#define UNDOSTUDIO_UNDOAPP_STOUTPUTFILTER_HPP
24
25#include <cctype>
26#include <cstddef>
27#include <string>
28#include <vector>
29
30namespace undoApp {
31namespace ST {
32
33namespace detail {
34
36inline std::string toLowerText(const std::string& text)
37{
38 std::string lower = text;
39 for (char& c : lower) {
40 c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
41 }
42 return lower;
43}
44
46inline bool startsWith(const std::string& text, const std::string& prefix)
47{
48 return text.size() >= prefix.size() && text.compare(0, prefix.size(), prefix) == 0;
49}
50
51} // namespace detail
52
56enum class OutSeverity
57{
58 Info,
59 Success,
60 Warning,
61 Error
62};
63
75
85{
86 bool showErrors = true;
87 bool showWarnings = true;
88 bool showSuccess = true;
89 bool showInfo = true;
90
92 bool passes(OutSeverity severity) const
93 {
94 switch (severity) {
95 case OutSeverity::Error: return showErrors;
98 case OutSeverity::Info: return showInfo;
99 }
100 return true;
101 }
102
110 std::vector<OutputLine> visible(const std::vector<OutputLine>& lines) const
111 {
112 std::vector<OutputLine> kept;
113 kept.reserve(lines.size());
114 for (const OutputLine& line : lines) {
115 if (passes(line.severity)) {
116 kept.push_back(line);
117 }
118 }
119 return kept;
120 }
121
127 static size_t count(const std::vector<OutputLine>& lines, OutSeverity severity)
128 {
129 size_t total = 0;
130 for (const OutputLine& line : lines) {
131 if (line.severity == severity) {
132 ++total;
133 }
134 }
135 return total;
136 }
137};
138
145inline std::vector<OutputLine> searchOutput(const std::vector<OutputLine>& lines, const std::string& needle)
146{
147 if (needle.empty()) {
148 return lines;
149 }
150 std::vector<OutputLine> found;
151 for (const OutputLine& line : lines) {
152 if (line.text.find(needle) != std::string::npos) {
153 found.push_back(line);
154 }
155 }
156 return found;
157}
158
170inline bool isCountSummary(const std::string& line)
171{
172 for (size_t i = 0; i < line.size(); ++i) {
173 if (!std::isdigit(static_cast<unsigned char>(line[i]))) {
174 continue;
175 }
176 size_t after = i;
177 while (after < line.size() && std::isdigit(static_cast<unsigned char>(line[after]))) {
178 ++after;
179 }
180 size_t word = after;
181 while (word < line.size() && line[word] == ' ') {
182 ++word;
183 }
184 const std::string tail = detail::toLowerText(line.substr(word, 12));
185 if (detail::startsWith(tail, "error") || detail::startsWith(tail, "warning")) {
186 return true;
187 }
188 i = after - 1;
189 }
190 return false;
191}
192
205inline OutSeverity classifyCompilerLine(const std::string& line)
206{
207 if (isCountSummary(line)) {
208 return OutSeverity::Info;
209 }
210
211 const std::string lower = detail::toLowerText(line);
212
213 // "file.st:12:5: error: message", or a line that opens with the word.
214 for (const char* marker : {": error", ": warning", "error:", "warning:"}) {
215 if (lower.find(marker) != std::string::npos) {
216 return (marker[0] == 'e' || marker == std::string(": error")) ? OutSeverity::Error
218 }
219 }
220
221 return OutSeverity::Info;
222}
223
224} // namespace ST
225} // namespace undoApp
226
227#endif // UNDOSTUDIO_UNDOAPP_STOUTPUTFILTER_HPP
std::string toLowerText(const std::string &text)
A lower-case copy, for matching words without caring about their case.
Definition undoAppSTOutput.hpp:36
bool startsWith(const std::string &text, const std::string &prefix)
Whether a string begins with a prefix.
Definition undoAppSTOutput.hpp:46
std::vector< OutputLine > searchOutput(const std::vector< OutputLine > &lines, const std::string &needle)
The lines matching a substring, for the panel's search box.
Definition undoAppSTOutput.hpp:145
OutSeverity
Severity of a line in the Output panel.
Definition undoAppSTOutput.hpp:57
@ Warning
Reported by the analyzer but not blocking.
@ Info
Debug/detail output, and the generated ST dump.
@ Success
Confirmation that a step succeeded.
@ Error
Blocks code generation.
OutSeverity classifyCompilerLine(const std::string &line)
How a line the transpiler printed should be coloured in the panel.
Definition undoAppSTOutput.hpp:205
bool isCountSummary(const std::string &line)
Whether a line from the transpiler is a tally rather than a diagnostic.
Definition undoAppSTOutput.hpp:170
Definition undoAppCpp.hpp:26
Which severities the Output panel shows.
Definition undoAppSTOutput.hpp:85
bool showInfo
Definition undoAppSTOutput.hpp:89
bool showWarnings
Definition undoAppSTOutput.hpp:87
static size_t count(const std::vector< OutputLine > &lines, OutSeverity severity)
How many lines of a severity the list holds, filtered or not.
Definition undoAppSTOutput.hpp:127
std::vector< OutputLine > visible(const std::vector< OutputLine > &lines) const
The lines to draw, in the order they were added.
Definition undoAppSTOutput.hpp:110
bool showSuccess
Definition undoAppSTOutput.hpp:88
bool showErrors
Definition undoAppSTOutput.hpp:86
bool passes(OutSeverity severity) const
Whether a line of this severity is shown.
Definition undoAppSTOutput.hpp:92
One tagged line in the Output panel.
Definition undoAppSTOutput.hpp:71
std::string text
Definition undoAppSTOutput.hpp:73
OutSeverity severity
Definition undoAppSTOutput.hpp:72