Show webfinger if displayName is unknown for an author.
[larjonas-pumpa.git] / src / util.h
blobcf8037db2a9f459074941882c69f3597b8390157
1 /*
2 Copyright 2013-2015 Mats Sjöberg
4 This file is part of the Pumpa programme.
6 Pumpa is free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Pumpa is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pumpa. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef _UTIL_H_
21 #define _UTIL_H_
23 #include <QMap>
24 #include <QString>
25 #include <QDateTime>
27 //------------------------------------------------------------------------------
29 #define URL_REGEX "((https?://|(https?://)?www.)[^\\s\"]+\\.[^\\s\"<]+[^\\s\\.\\,\\!\\?\"<])"
30 #define URL_REGEX_STRICT "(https?://[^\\s\"]+\\.[^\\s\"<]+[^\\s\\.\\,\\!\\?\\)\"<])"
31 #define MD_NOGO_ITEMS "\\*`_"
32 #define MD_PAIR_REGEX "%1([^\\s%3][^%3]*[^\\s%3]|[^\\s%3])%2"
33 #define HTML_TAG_REGEX "<([^>]+)>"
35 //------------------------------------------------------------------------------
38 Fixes site url, removes extra / from end, adds https:// if missing.
40 QString siteUrlFixer(QString url, bool useSsl=true);
42 /*
43 Finds things that look like URLs and changes them into a href
44 links.
46 QString linkifyUrls(QString text);
49 /*
50 Finds things delimited by 'begin' and 'end' and changes them to be
51 delimited by 'newBegin' and 'newEnd'.
53 QString changePairedTags(QString text,
54 QString begin, QString end,
55 QString newBegin, QString newEnd,
56 QString nogoItems = MD_NOGO_ITEMS);
59 Transforms foo and https://bar.com to foo@bar.com
61 QString siteUrlToAccountId(QString username, QString url);
63 QString markDown(QString text);
65 QString relativeFuzzyTime(QDateTime sTime, bool longTime=false);
67 bool splitWebfingerId(QString accountId, QString& username, QString& server);
69 template <class T> void deleteMap(QMap<QString, T>& map) {
70 typename QMap<QString, T>::iterator i;
71 for (i = map.begin(); i != map.end(); ++i)
72 delete i.value();
73 map.clear();
76 void checkMemory(QString desc="");
78 QString removeHtml(QString);
80 QString addTextMarkup(QString content, bool useMarkdown);
82 QString processTitle(QString text, bool removeLtgt);
84 QString slashify(QString path);
86 //------------------------------------------------------------------------------
88 #endif /* _UTIL_H_ */