MCPcopy Create free account
hub / github.com/KDE/kdevelop / formatComment

Function formatComment

kdevplatform/language/duchain/stringhelpers.cpp:372–416  ·  view source on GitHub ↗

NOTE: keep in sync with QString overload below

Source from the content-addressed store, hash-verified

370
371// NOTE: keep in sync with QString overload below
372QByteArray formatComment(const QByteArray& comment)
373{
374 if (comment.isEmpty())
375 return comment;
376
377 auto lines = comment.split('\n');
378 // remove common leading & trailing chars from the lines
379 for (auto& l : lines) {
380 // don't trigger repeated temporary allocations here
381
382 // possible comment starts, sorted from longest to shortest
383 static const QByteArray startMatches[] = {
384 QByteArrayLiteral("//!<"), QByteArrayLiteral("/*!<"), QByteArrayLiteral("/**<"), QByteArrayLiteral("///<"),
385 QByteArrayLiteral("///"), QByteArrayLiteral("//!"), QByteArrayLiteral("/**"), QByteArrayLiteral("/*!"),
386 QByteArrayLiteral("//"), QByteArrayLiteral("/*"), QByteArrayLiteral("/"), QByteArrayLiteral("*")};
387
388 // possible comment ends, sorted from longest to shortest
389 static const QByteArray endMatches[] = {QByteArrayLiteral("**/"), QByteArrayLiteral("*/")};
390
391 l = l.trimmed();
392
393 // check for ends first, as the starting pattern "*" might interfere with the ending pattern
394 for (const auto& m : endMatches) {
395 if (l.endsWith(m)) {
396 l.chop(m.length());
397 break;
398 }
399 }
400
401 for (const auto& m : startMatches) {
402 if (l.startsWith(m)) {
403 l.remove(0, m.length());
404 break;
405 }
406 }
407 }
408
409 QByteArray ret;
410 for (const auto& line : std::as_const(lines)) {
411 if (!ret.isEmpty())
412 ret += '\n';
413 ret += line;
414 }
415 return ret.trimmed();
416}
417
418// NOTE: keep in sync with QByteArray overload above
419QString formatComment(const QString& comment)

Callers 4

testFormatCommentMethod · 0.85
setDeclDataMethod · 0.85
commentForLocationMethod · 0.85

Calls 5

endsWithMethod · 0.80
isEmptyMethod · 0.45
splitMethod · 0.45
lengthMethod · 0.45
removeMethod · 0.45

Tested by 1

testFormatCommentMethod · 0.68