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"
8using namespace Qt::Literals::StringLiterals;
9
10#include <QRegularExpression>
11#include <QUrl>
12
13QString PimCommon::AddresseeLineEditUtil::adaptPasteMails(const QString &str)
14{
15 QString newText = str;
16 // remove newlines in the to-be-pasted string
17 static QRegularExpression reg2("\r?\n"_L1);
18 QStringList lines = newText.split(reg2, Qt::SkipEmptyParts);
20 for (QStringList::iterator it = lines.begin(); it != end; ++it) {
21 // remove trailing commas and whitespace
22 static QRegularExpression reg1(QRegularExpression(",?\\s*$"_L1));
23 (*it).remove(reg1);
24 }
25 newText = lines.join(", "_L1);
26
27 if (newText.startsWith("mailto:"_L1)) {
28 const QUrl url(newText);
29 newText = url.path();
30 } else if (newText.contains(" at "_L1)) {
31 // Anti-spam stuff
32 newText.replace(QStringLiteral(" at "), QStringLiteral("@"));
33 newText.replace(QStringLiteral(" dot "), QStringLiteral("."));
34 } else if (newText.contains("(at)"_L1)) {
35 static QRegularExpression reg("\\s*\\(at\\)\\s*"_L1);
36 newText.replace(reg, QStringLiteral("@"));
37 }
38 return newText;
39}
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 Sat Dec 21 2024 17:02:56 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.