14#include <QCryptographicHash>
16#include <QRegularExpression>
25unsigned int calcHash(
const QString &str)
27 return calcHash(str.
toUtf8());
30unsigned int calcHash(
const QByteArray &array)
35 const char *s = array.
data();
36 unsigned int hash = 5381;
39 hash = ((hash << 5) + hash) + c;
45static uint toTimeT(QDateTime &kdt)
60uint parseISODate(
const QString &str)
66uint parseRFCDate(
const QString &str)
76uint parseDate(
const QString &str, DateFormat hint)
82 if (hint == RFCDate) {
83 time_t t = parseRFCDate(str);
84 return t != 0 ? t : parseISODate(str);
86 time_t t = parseISODate(str);
87 return t != 0 ? t : parseRFCDate(str);
91QString dateTimeToString(uint date)
97 const QString format = QStringLiteral(
"ddd MMM d HH:mm:ss yyyy");
103QString calcMD5Sum(
const QString &str)
106 md5Machine.addData(str.
toUtf8());
107 return QLatin1String(md5Machine.result().toHex().constData());
110QString resolveEntities(
const QString &str)
115QString escapeSpecialCharacters(
const QString &strp)
118 str.
replace(QLatin1Char(
'&'), QLatin1String(
"&"));
119 str.
replace(QLatin1Char(
'\"'), QLatin1String(
"""));
120 str.
replace(QLatin1Char(
'<'), QLatin1String(
"<"));
121 str.
replace(QLatin1Char(
'>'), QLatin1String(
">"));
122 str.
replace(QLatin1Char(
'\''), QLatin1String(
"'"));
126QString convertNewlines(
const QString &strp)
129 str.
replace(QLatin1Char(
'\n'), QLatin1String(
"<br/>"));
133QString plainTextToHtml(
const QString &plainText)
135 QString str(plainText);
136 str.
replace(QLatin1Char(
'&'), QLatin1String(
"&"));
137 str.
replace(QLatin1Char(
'\"'), QLatin1String(
"""));
138 str.
replace(QLatin1Char(
'<'), QLatin1String(
"<"));
140 str.
replace(QLatin1Char(
'\n'), QLatin1String(
"<br/>"));
144QString htmlToPlainText(
const QString &html)
148 str.
remove(QRegularExpression(QStringLiteral(
"<[^>]*?>")));
149 str = resolveEntities(str);
153static QRegularExpression tagRegExp()
155 static QRegularExpression exp(QStringLiteral(
"<\\w+.*/?>"));
159bool stringContainsMarkup(
const QString &str)
162 if (str.
contains(QRegularExpression(QStringLiteral(
"&[a-zA-Z0-9#]+;")))) {
166 const int ltc = str.
count(QLatin1Char(
'<'));
174bool isHtml(
const QString &str)
177 if (str.
contains(QRegularExpression(QStringLiteral(
"&[a-zA-Z0-9#]+;")))) {
181 const int ltc = str.
count(QLatin1Char(
'<'));
189QString normalize(
const QString &str)
191 return isHtml(str) ? str.
trimmed() : plainTextToHtml(str);
194QString normalize(
const QString &strp,
bool isCDATA,
bool containsMarkup)
196 if (containsMarkup) {
200 QString str = resolveEntities(strp);
201 str = escapeSpecialCharacters(str);
202 str = convertNewlines(str);
206 QString str = escapeSpecialCharacters(strp);
213PersonPtr personFromString(
const QString &strp)
217 return PersonPtr(
new PersonImpl());
220 str = resolveEntities(str);
228 const QRegularExpression remail(QStringLiteral(
"<?([^@\\s<]+@[^>\\s]+)>?"));
231 QRegularExpressionMatch
match = remail.match(str);
232 if (
match.hasMatch()) {
233 const QString all =
match.captured(0);
234 email =
match.captured(1);
239 email.
remove(QStringLiteral(
"mailto:"));
240 email.
remove(QRegularExpression(QStringLiteral(
"[()]")));
254 if (
match.hasMatch()) {
259 email = email.
isEmpty() ? QString() : email;
260 uri = uri.
isEmpty() ? QString() : uri;
263 return PersonPtr(
new PersonImpl());
266 return PersonPtr(
new PersonImpl(name, uri, email));
269ElementType::ElementType(
const QString &localnamep,
const QString &nsp)
271 , localname(localnamep)
275bool ElementType::operator==(
const ElementType &other)
const
277 return localname == other.localname && ns == other.ns;
static QString resolveEntities(const QString &text)
KCOREADDONS_EXPORT Result match(QStringView pattern, QStringView str)
KIOCORE_EXPORT SimpleJob * rename(const QUrl &src, const QUrl &dest, JobFlags flags=DefaultFlags)
QString name(StandardAction id)
bool isEmpty() const const
QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
bool isValid() const const
void setMSecsSinceEpoch(qint64 msecs)
void setTimeZone(const QTimeZone &toZone)
Qt::TimeSpec timeSpec() const const
qint64 toMSecsSinceEpoch() const const
QString toString(QStringView format, QCalendar cal) const const
QDateTime toUTC() const const
QString anchoredPattern(QStringView expression)
qsizetype count() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
QString simplified() const const
QByteArray toUtf8() const const
QString trimmed() const const
bool isNull() const const