File indexing completed on 2024-04-28 03:52:07

0001 /*
0002  * BluezQt - Asynchronous BlueZ wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #include "Comment.h"
0010 
0011 bool Comment::finalize()
0012 {
0013     // Delete last empty lines from comment
0014     while (last().isEmpty()) {
0015         removeLast();
0016     }
0017 
0018     // Find indents
0019     qsizetype indents = 255;
0020     for (const auto &line : *this) {
0021         if (line.isEmpty()) {
0022             continue;
0023         }
0024         indents = std::min(indents, line.count(QStringLiteral("\t")));
0025     }
0026 
0027     // Remove indents
0028     for (auto &line : *this) {
0029         line.remove(0, indents);
0030     }
0031 
0032     // Replace indents
0033     for (auto &line : *this) {
0034         line.replace(QStringLiteral("\t"), QStringLiteral("    "));
0035     }
0036 
0037     return true;
0038 }