File indexing completed on 2024-05-05 05:04:33
0001 /*************************************************************************** 0002 * SPDX-License-Identifier: GPL-2.0-or-later 0003 * * 0004 * SPDX-FileCopyrightText: 2004-2017 Thomas Fischer <fischer@unix-ag.uni-kl.de> 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, * 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0014 * GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License * 0017 * along with this program; if not, see <https://www.gnu.org/licenses/>. * 0018 ***************************************************************************/ 0019 0020 #ifndef KBIBTEX_NAMESPACE_H 0021 #define KBIBTEX_NAMESPACE_H 0022 0023 #include <QVariant> 0024 #include <QRegExp> 0025 #include <QUrl> 0026 0027 namespace KBibTeX 0028 { 0029 0030 const QString extensionTeX = QLatin1String(".tex"); 0031 const QString extensionAux = QLatin1String(".aux"); 0032 const QString extensionBBL = QLatin1String(".bbl"); 0033 const QString extensionBLG = QLatin1String(".blg"); 0034 const QString extensionBibTeX = QLatin1String(".bib"); 0035 const QString extensionPDF = QLatin1String(".pdf"); 0036 const QString extensionPostScript = QLatin1String(".ps"); 0037 const QString extensionRTF = QLatin1String(".rtf"); 0038 0039 enum Casing { 0040 cLowerCase = 0, 0041 cInitialCapital = 1, 0042 cUpperCamelCase = 2, 0043 cLowerCamelCase = 3, 0044 cUpperCase = 4 0045 }; 0046 0047 enum FieldInputType { 0048 SingleLine = 1, 0049 MultiLine = 2, 0050 List = 3, 0051 URL = 4, 0052 Month = 5, 0053 Color = 6, 0054 PersonList = 7, 0055 UrlList = 8, 0056 KeywordList = 9, 0057 CrossRef = 10, 0058 StarRating = 11 0059 }; 0060 0061 enum TypeFlag { 0062 tfPlainText = 0x1, 0063 tfReference = 0x2, 0064 tfPerson = 0x4, 0065 tfKeyword = 0x8, 0066 tfVerbatim = 0x10, 0067 tfSource = 0x100 0068 }; 0069 Q_DECLARE_FLAGS(TypeFlags, TypeFlag) 0070 0071 Q_DECLARE_OPERATORS_FOR_FLAGS(TypeFlags) 0072 0073 static const QString MonthsTriple[] = { 0074 QLatin1String("jan"), QLatin1String("feb"), QLatin1String("mar"), QLatin1String("apr"), QLatin1String("may"), QLatin1String("jun"), QLatin1String("jul"), QLatin1String("aug"), QLatin1String("sep"), QLatin1String("oct"), QLatin1String("nov"), QLatin1String("dec") 0075 }; 0076 0077 static const QRegExp fileListSeparatorRegExp(QStringLiteral("[ \\t]*[;\\n]+[ \\t]*")); 0078 static const QRegExp fileRegExp(QStringLiteral("(\\bfile:)?[^{}\\t]+\\.\\w{2,4}\\b"), Qt::CaseInsensitive); 0079 static const QRegExp urlRegExp(QStringLiteral("\\b(http|s?ftp|webdav|file)s?://[^ {}\"]+(\\b|[/])"), Qt::CaseInsensitive); 0080 static const QRegExp doiRegExp(QStringLiteral("10([.][0-9]+)+/[/-a-z0-9.()<>_:;\\\\]+"), Qt::CaseInsensitive); 0081 static const QRegExp mendeleyFileRegExp(QStringLiteral(":(.*):pdf"), Qt::CaseInsensitive); 0082 static const QString doiUrlPrefix = QLatin1String("https://dx.doi.org/"); ///< use FileInfo::doiUrlPrefix() instead 0083 static const QRegExp domainNameRegExp(QStringLiteral("[a-z0-9.-]+\\.((a[cdefgilmnoqrstuwxz]|aero|arpa)|(b[abdefghijmnorstvwyz]|biz)|(c[acdfghiklmnorsuvxyz]|cat|com|coop)|d[ejkmoz]|(e[ceghrstu]|edu)|f[ijkmor]|(g[abdefghilmnpqrstuwy]|gov)|h[kmnrtu]|(i[delmnoqrst]|info|int)|(j[emop]|jobs)|k[eghimnprwyz]|l[abcikrstuvy]|(m[acdghklmnopqrstuvwxyz]|me|mil|mobi|museum)|(n[acefgilopruz]|name|net)|(om|org)|(p[aefghklmnrstwy]|pro)|qa|r[eouw]|s[abcdeghijklmnortvyz]|(t[cdfghjklmnoprtvwz]|travel)|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw])\\b"), Qt::CaseInsensitive); 0084 static const QRegExp htmlRegExp = QRegExp(QStringLiteral("</?(a|pre|p|br|span|i|b|italic)\\b[^>{}]{,32}>"), Qt::CaseInsensitive); 0085 0086 } 0087 0088 inline static bool isLocalOrRelative(const QUrl &url) 0089 { 0090 return url.isLocalFile() || url.isRelative() || url.scheme().isEmpty(); 0091 } 0092 0093 /** 0094 * Poor man's variant of a text-squeezing function. 0095 * Effect is similar as observed in KSqueezedTextLabel: 0096 * If the text is longer as n characters, the middle part 0097 * will be cut away and replaced by "..." to get a 0098 * string of max n characters. 0099 */ 0100 inline static QString squeezeText(const QString &text, int n) 0101 { 0102 return text.length() <= n ? text : text.left(n / 2 - 1) + QLatin1String("...") + text.right(n / 2 - 2); 0103 } 0104 0105 inline static QString leftSqueezeText(const QString &text, int n) 0106 { 0107 return text.length() <= n ? text : text.left(n) + QLatin1String("..."); 0108 } 0109 0110 #define squeeze_text(text, n) ((text).length()<=(n)?(text):(text).left((n)/2-1)+QLatin1String("...")+(text).right((n)/2-2)) 0111 0112 #endif // KBIBTEX_NAMESPACE_H