| 1 |
/* |
| 2 |
* BluezQt - Asynchronous BlueZ wrapper library |
| 3 |
* |
| 4 |
* SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <[email protected]> |
| 5 |
* |
| 6 |
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "Comment.h" |
| 10 |
|
| 11 |
bool Comment::finalize() |
| 12 |
{ |
| 13 |
// Delete last empty lines from comment |
| 14 |
while (last().isEmpty()) { |
| 15 |
removeLast(); |
| 16 |
} |
| 17 |
|
| 18 |
// Find indents |
| 19 |
qsizetype indents = 255; |
| 20 |
for (const auto &line : *this) { |
| 21 |
if (line.isEmpty()) { |
| 22 |
continue; |
| 23 |
} |
| 24 |
indents = std::min(indents, line.count(QStringLiteral("\t"))); |
| 25 |
} |
| 26 |
|
| 27 |
// Remove indents |
| 28 |
for (auto &line : *this) { |
| 29 |
line.remove(0, indents); |
| 30 |
} |
| 31 |
|
| 32 |
// Replace indents |
| 33 |
for (auto &line : *this) { |
| 34 |
line.replace(QStringLiteral("\t"), QStringLiteral(" ")); |
| 35 |
} |
| 36 |
|
| 37 |
return true; |
| 38 |
} |