1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | #include "unix/TerminalCharacterDecoder.h" |
26 | |
27 | |
28 | #include <QtCore/QTextStream> |
29 | |
30 | PlainTextDecoder::PlainTextDecoder() |
31 | : _output(0) |
32 | , _includeTrailingWhitespace(true) |
33 | { |
34 | |
35 | } |
36 | void PlainTextDecoder::setTrailingWhitespace(bool enable) |
37 | { |
38 | _includeTrailingWhitespace = enable; |
39 | } |
40 | bool PlainTextDecoder::trailingWhitespace() const |
41 | { |
42 | return _includeTrailingWhitespace; |
43 | } |
44 | void PlainTextDecoder::begin(QTextStream* output) |
45 | { |
46 | _output = output; |
47 | } |
48 | void PlainTextDecoder::end() |
49 | { |
50 | _output = 0; |
51 | } |
52 | void PlainTextDecoder::decodeLine(const Character* const characters, int count, LineProperty |
53 | ) |
54 | { |
55 | Q_ASSERT( _output )((!(_output)) ? qt_assert("_output","qterminal/libqterminal/unix/TerminalCharacterDecoder.cpp" ,55) : qt_noop()); |
| 1 | Within the expansion of the macro 'Q_ASSERT':
| |
a | Assuming pointer value is null |
|
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | QString plainText; |
63 | plainText.reserve(count); |
64 | |
65 | int outputCount = count; |
66 | |
67 | |
68 | |
69 | if ( !_includeTrailingWhitespace ) |
| |
70 | { |
71 | for (int i = count-1 ; i >= 0 ; i--) |
72 | { |
73 | if ( characters[i].character != ' ' ) |
74 | break; |
75 | else |
76 | outputCount--; |
77 | } |
78 | } |
79 | |
80 | for (int i=0;i<outputCount;i++) |
| 3 | | Assuming 'i' is >= 'outputCount' | |
|
| 4 | | Loop condition is false. Execution continues on line 85 | |
|
81 | { |
82 | plainText.append( QChar(characters[i].character) ); |
83 | } |
84 | |
85 | *_output << plainText; |
| 5 | | Called C++ object pointer is null |
|
86 | } |
87 | |
88 | HTMLDecoder::HTMLDecoder() : |
89 | _output(0) |
90 | ,_colorTable(base_color_table) |
91 | ,_innerSpanOpen(false) |
92 | ,_lastRendition(DEFAULT_RENDITION0) |
93 | { |
94 | |
95 | } |
96 | |
97 | void HTMLDecoder::begin(QTextStream* output) |
98 | { |
99 | _output = output; |
100 | |
101 | QString text; |
102 | |
103 | |
104 | openSpan(text,"font-family:monospace"); |
105 | |
106 | *output << text; |
107 | } |
108 | |
109 | void HTMLDecoder::end() |
110 | { |
111 | Q_ASSERT( _output )((!(_output)) ? qt_assert("_output","qterminal/libqterminal/unix/TerminalCharacterDecoder.cpp" ,111) : qt_noop()); |
112 | |
113 | QString text; |
114 | |
115 | closeSpan(text); |
116 | |
117 | *_output << text; |
118 | |
119 | _output = 0; |
120 | |
121 | } |
122 | |
123 | |
124 | void HTMLDecoder::decodeLine(const Character* const characters, int count, LineProperty |
125 | ) |
126 | { |
127 | Q_ASSERT( _output )((!(_output)) ? qt_assert("_output","qterminal/libqterminal/unix/TerminalCharacterDecoder.cpp" ,127) : qt_noop()); |
128 | |
129 | QString text; |
130 | |
131 | int spaceCount = 0; |
132 | |
133 | for (int i=0;i<count;i++) |
134 | { |
135 | QChar ch(characters[i].character); |
136 | |
137 | |
138 | if ( characters[i].rendition != _lastRendition || |
139 | characters[i].foregroundColor != _lastForeColor || |
140 | characters[i].backgroundColor != _lastBackColor ) |
141 | { |
142 | if ( _innerSpanOpen ) |
143 | closeSpan(text); |
144 | |
145 | _lastRendition = characters[i].rendition; |
146 | _lastForeColor = characters[i].foregroundColor; |
147 | _lastBackColor = characters[i].backgroundColor; |
148 | |
149 | |
150 | QString style; |
151 | |
152 | if ( _lastRendition & RE_BOLD(1 << 0) || |
153 | (_colorTable && characters[i].isBold(_colorTable)) ) |
154 | style.append("font-weight:bold;"); |
155 | |
156 | |
157 | if ( _lastRendition & RE_UNDERLINE(1 << 2) ) |
158 | style.append("font-decoration:underline;"); |
159 | |
160 | |
161 | if ( _colorTable ) |
162 | { |
163 | style.append( QString("color:%1;").arg(_lastForeColor.color(_colorTable).name() ) ); |
164 | |
165 | if (!characters[i].isTransparent(_colorTable)) |
166 | { |
167 | style.append( QString("background-color:%1;").arg(_lastBackColor.color(_colorTable).name() ) ); |
168 | } |
169 | } |
170 | |
171 | |
172 | openSpan(text,style); |
173 | _innerSpanOpen = true; |
174 | } |
175 | |
176 | |
177 | if (ch.isSpace()) |
178 | spaceCount++; |
179 | else |
180 | spaceCount = 0; |
181 | |
182 | |
183 | |
184 | if (spaceCount < 2) |
185 | { |
186 | |
187 | if ( ch == '<' ) |
188 | text.append("<"); |
189 | else if (ch == '>') |
190 | text.append(">"); |
191 | else |
192 | text.append(ch); |
193 | } |
194 | else |
195 | { |
196 | text.append(" "); |
197 | } |
198 | |
199 | } |
200 | |
201 | |
202 | if ( _innerSpanOpen ) |
203 | closeSpan(text); |
204 | |
205 | |
206 | text.append("<br>"); |
207 | |
208 | *_output << text; |
209 | } |
210 | |
211 | void HTMLDecoder::openSpan(QString& text , const QString& style) |
212 | { |
213 | text.append( QString("<span style=\"%1\">").arg(style) ); |
214 | } |
215 | |
216 | void HTMLDecoder::closeSpan(QString& text) |
217 | { |
218 | text.append("</span>"); |
219 | } |
220 | |
221 | void HTMLDecoder::setColorTable(const ColorEntry* table) |
222 | { |
223 | _colorTable = table; |
224 | } |