1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
27 QString nickFromMask(const QString &mask);
28 QString userFromMask(const QString &mask);
29 QString hostFromMask(const QString &mask);
30 bool isChannelName(const QString &str);
32 //! Strip mIRC format codes
33 QString stripFormatCodes(QString);
35 //! Remove accelerator markers (&) from the string
36 QString stripAcceleratorMarkers(const QString &);
38 QString secondsToString(int timeInSeconds);
40 //! Take a string and decode it using the specified text codec, recognizing utf8.
41 /** This function takes a string and first checks if it is encoded in utf8, in which case it is
42 * decoded appropriately. Otherwise, the specified text codec is used to transform the string.
43 * \param input The input string containing encoded data
44 * \param codec The text codec we use if the input is not utf8
45 * \return The decoded string.
47 QString decodeString(const QByteArray &input, QTextCodec *codec = 0);
49 uint editingDistance(const QString &s1, const QString &s2);
52 QVariantList toVariantList(const QList<T> &list)
54 QVariantList variants;
55 for (int i = 0; i < list.count(); i++) {
56 variants << QVariant::fromValue<T>(list[i]);
63 QList<T> fromVariantList(const QVariantList &variants)
66 for (int i = 0; i < variants.count(); i++) {
67 list << variants[i].value<T>();
73 QByteArray prettyDigest(const QByteArray &digest);
76 * Format a string with %%<text>%% to current date/timestamp via QDateTime.
78 * @param[in] formatStr String with format codes
79 * @return String with current date/time substituted in via formatting codes
81 QString formatCurrentDateTimeInString(const QString &formatStr);
83 /** Check if a scope rule matches a string
85 * When isRegEx is false:
86 * Checks that the string does NOT match ANY inverted rules (prefixed by '!'), then checks that
87 * it matches AT LEAST one normal (non-inverted) rule.
89 * If only inverted rules are specified, it'll match so long as the string does not match any
90 * inverted rules (implicit wildcard).
92 * When isRegEx is true:
93 * Checks that the string matches the entire scopeRule as a regular expression. If scopeRule starts
94 * with a '!', check that the string does NOT match the regular expression.
96 * @param string String to test, e.g. network/channel name
97 * @param scopeRule ';'-separated list of wildcard expressions, prefix of '!' inverts subrule
98 * @param isRegEx If true, treat entire scope rule as regular expression, not wildcards
99 * @param isCaseSensitive If true, treat as case-sensitive, else case-insensitive
100 * @return True if matches, otherwise false
102 bool scopeMatch(const QString &string, const QString &scopeRule,
103 const bool &isRegEx = false, const bool &isCaseSensitive = false);
106 * Try to localize a given date/time in seconds from Unix epoch, pass through string if invalid
108 * Allows compatibility with date/time fields that may or may not be in Unix epoch format,
109 * localizing if possible, leaving alone if not.
111 * @param possibleEpochDate Date/time that might be in seconds since Unix epoch format
112 * @param dateFormat Desired format of the date/time string
113 * @param useUTC If true, use UTC timezone, otherwise use local time
114 * @return Localized date/time if parse succeeded, otherwise the source string
116 QString tryFormatUnixEpoch(const QString &possibleEpochDate,
117 Qt::DateFormat dateFormat = Qt::DateFormat::TextDate,
118 bool useUTC = false);
122 * Format the given date/time in ISO 8601 format with timezone offset
124 * @param dateTime Date/time of interest
125 * @return Date/time in ISO 8601 format with timezone offset
127 QString formatDateTimeToOffsetISO(const QDateTime &dateTime);