MCPcopy Create free account
hub / github.com/Kitware/CMake / WriteLiteralTextBlock

Method WriteLiteralTextBlock

Source/cmConfigureLog.cxx:240–314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

238}
239
240void cmConfigureLog::WriteLiteralTextBlock(cm::string_view key,
241 cm::string_view text)
242{
243 this->BeginLine() << key << ": |";
244 this->EndLine();
245
246 auto const l = text.length();
247 if (l) {
248 ++this->Indent;
249 this->BeginLine();
250
251 auto i = decltype(l){ 0 };
252 while (i < l) {
253 // YAML allows ' ', '\t' and "printable characters", but NOT other
254 // ASCII whitespace; those must be escaped, as must the upper UNICODE
255 // control characters (U+0080 - U+009F)
256 static constexpr unsigned int C1_LAST = 0x9F;
257 auto const c = static_cast<unsigned char>(text[i]);
258 switch (c) {
259 case '\r':
260 // Print a carriage return only if it is not followed by a line feed.
261 ++i;
262 if (i == l || text[i] != '\n') {
263 this->WriteEscape(c);
264 }
265 break;
266 case '\n':
267 // Print any line feeds except the very last one
268 if (i + 1 < l) {
269 this->EndLine();
270 this->BeginLine();
271 }
272 ++i;
273 break;
274 case '\t':
275 // Print horizontal tab verbatim
276 this->Stream.put('\t');
277 ++i;
278 break;
279 case '\\':
280 // Escape backslash for disambiguation
281 this->Stream << "\\\\";
282 ++i;
283 break;
284 default:
285 if (c >= 32 && c < 127) {
286 // Print ascii byte.
287 this->Stream.put(text[i]);
288 ++i;
289 break;
290 } else if (c > 127) {
291 // Decode a UTF-8 sequence.
292 unsigned int c32;
293 auto const* const s = text.data() + i;
294 auto const* const e = text.data() + l;
295 auto const* const n = cm_utf8_decode_character(s, e, &c32);
296 if (n > s && c32 > C1_LAST) {
297 auto const k = std::distance(s, n);

Callers 3

WriteMessageEventFunction · 0.45
WriteTryRunEventFunction · 0.45

Calls 7

EndLineMethod · 0.95
WriteEscapeMethod · 0.95
cm_utf8_decode_characterFunction · 0.85
lengthMethod · 0.80
putMethod · 0.45
dataMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected