File indexing completed on 2023-12-03 04:55:08

0001 /*
0002     SPDX-FileCopyrightText: 2023 Julius K├╝nzel <jk.kdedev@smartlab.uber.space>
0003     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 #include "qstringutils.h"
0007 
0008 #include <QString>
0009 #include <QStringList>
0010 
0011 QString QStringUtils::getUniqueName(const QStringList &names, const QString &name)
0012 {
0013     int i = 0;
0014     QString newName = name;
0015     while (names.contains(newName)) {
0016         // name is not unique, add a suffix
0017         newName = name + QString("-%1").arg(i);
0018         i++;
0019     }
0020     return newName;
0021 }
0022 
0023 QString QStringUtils::appendToFilename(const QString &filename, const QString &appendix)
0024 {
0025     QString name = filename.section(QLatin1Char('.'), 0, -2);
0026     QString extension = filename.section(QLatin1Char('.'), -1);
0027     return name + appendix + QLatin1Char('.') + extension;
0028 }