NOTE: keep in sync with QString overload below
| 370 | |
| 371 | // NOTE: keep in sync with QString overload below |
| 372 | QByteArray 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 |
| 419 | QString formatComment(const QString& comment) |