File indexing completed on 2025-03-09 03:57:06
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-08-08 0007 * Description : a modifier for deleting duplicate words 0008 * 0009 * SPDX-FileCopyrightText: 2009-2012 by Andi Clemens <andi dot clemens at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "removedoublesmodifier.h" 0016 0017 // Qt includes 0018 0019 #include <QSet> 0020 #include <QString> 0021 #include <QStringList> 0022 #include <QRegularExpression> 0023 0024 // KDE includes 0025 0026 #include <klocalizedstring.h> 0027 0028 namespace Digikam 0029 { 0030 0031 RemoveDoublesModifier::RemoveDoublesModifier() 0032 : Modifier(i18n("Remove Doubles"), 0033 i18n("Remove duplicate words"), 0034 QLatin1String("edit-copy")) 0035 { 0036 addToken(QLatin1String("{removedoubles}"), description()); 0037 0038 QRegularExpression reg(QLatin1String("\\{removedoubles\\}")); 0039 reg.setPatternOptions(QRegularExpression::InvertedGreedinessOption); 0040 setRegExp(reg); 0041 } 0042 0043 QString RemoveDoublesModifier::parseOperation(ParseSettings& settings, const QRegularExpressionMatch& /*match*/) 0044 { 0045 QString result = settings.str2Modify; 0046 0047 QSet<QString> knownWords; 0048 QStringList words = result.split(QLatin1Char(' ')); 0049 QStringList newString; 0050 0051 Q_FOREACH (const QString& word, words) 0052 { 0053 if (!knownWords.contains(word)) 0054 { 0055 knownWords.insert(word); 0056 newString << word; 0057 } 0058 } 0059 0060 if (!newString.isEmpty()) 0061 { 0062 result = newString.join(QLatin1Char(' ')); 0063 } 0064 0065 return result; 0066 } 0067 0068 } // namespace Digikam 0069 0070 #include "moc_removedoublesmodifier.cpp"