Pimcommon

addresseelineeditutil.cpp
1/*
2 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "addresseelineeditutil.h"
8#include <QRegularExpression>
9#include <QUrl>
10
11QString PimCommon::AddresseeLineEditUtil::adaptPasteMails(const QString &str)
12{
13 QString newText = str;
14 // remove newlines in the to-be-pasted string
15 static QRegularExpression reg2(QStringLiteral("\r?\n"));
16 QStringList lines = newText.split(reg2, Qt::SkipEmptyParts);
18 for (QStringList::iterator it = lines.begin(); it != end; ++it) {
19 // remove trailing commas and whitespace
20 static QRegularExpression reg1(QRegularExpression(QStringLiteral(",?\\s*$")));
21 (*it).remove(reg1);
22 }
23 newText = lines.join(QLatin1StringView(", "));
24
25 if (newText.startsWith(QLatin1StringView("mailto:"))) {
26 const QUrl url(newText);
27 newText = url.path();
28 } else if (newText.contains(QLatin1StringView(" at "))) {
29 // Anti-spam stuff
30 newText.replace(QStringLiteral(" at "), QStringLiteral("@"));
31 newText.replace(QStringLiteral(" dot "), QStringLiteral("."));
32 } else if (newText.contains(QLatin1StringView("(at)"))) {
33 static QRegularExpression reg((QStringLiteral("\\s*\\(at\\)\\s*")));
34 newText.replace(reg, QStringLiteral("@"));
35 }
36 return newText;
37}
const QList< QKeySequence > & end()
iterator begin()
iterator end()
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QString join(QChar separator) const const
SkipEmptyParts
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:23 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.