1 /***************************************************************************
2 * Copyright (C) 2004-2017 by Thomas Fischer <fischer@unix-ag.uni-kl.de> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 ***************************************************************************/
17
18 #ifndef KBIBTEX_NAMESPACE_H
19 #define KBIBTEX_NAMESPACE_H
20
21 #include <QVariant>
22 #include <QRegExp>
23 #include <QUrl>
24
25 namespace KBibTeX
26 {
27
28 const QString extensionTeX = QLatin1String(".tex");
29 const QString extensionAux = QLatin1String(".aux");
30 const QString extensionBBL = QLatin1String(".bbl");
31 const QString extensionBLG = QLatin1String(".blg");
32 const QString extensionBibTeX = QLatin1String(".bib");
33 const QString extensionPDF = QLatin1String(".pdf");
34 const QString extensionPostScript = QLatin1String(".ps");
35 const QString extensionRTF = QLatin1String(".rtf");
36
37 enum Casing {
38 cLowerCase = 0,
39 cInitialCapital = 1,
40 cUpperCamelCase = 2,
41 cLowerCamelCase = 3,
42 cUpperCase = 4
43 };
44
45 enum FieldInputType {
46 SingleLine = 1,
47 MultiLine = 2,
48 List = 3,
49 URL = 4,
50 Month = 5,
51 Color = 6,
52 PersonList = 7,
53 UrlList = 8,
54 KeywordList = 9,
55 CrossRef = 10,
56 StarRating = 11
57 };
58
59 enum TypeFlag {
60 tfPlainText = 0x1,
61 tfReference = 0x2,
62 tfPerson = 0x4,
63 tfKeyword = 0x8,
64 tfVerbatim = 0x10,
65 tfSource = 0x100
66 };
67 Q_DECLARE_FLAGS(TypeFlags, TypeFlag)
68
69 Q_DECLARE_OPERATORS_FOR_FLAGS(TypeFlags)
70
71 static const QString MonthsTriple[] = {
72 QLatin1String("jan"), QLatin1String("feb"), QLatin1String("mar"), QLatin1String("apr"), QLatin1String("may"), QLatin1String("jun"), QLatin1String("jul"), QLatin1String("aug"), QLatin1String("sep"), QLatin1String("oct"), QLatin1String("nov"), QLatin1String("dec")
73 };
74
75 static const QRegExp fileListSeparatorRegExp(QStringLiteral("[ \\t]*[;\\n]+[ \\t]*"));
76 static const QRegExp fileRegExp(QStringLiteral("(\\bfile:)?[^{}\\t]+\\.\\w{2,4}\\b"), Qt::CaseInsensitive);
77 static const QRegExp urlRegExp(QStringLiteral("\\b(http|s?ftp|webdav|file)s?://[^ {}\"]+(\\b|[/])"), Qt::CaseInsensitive);
78 static const QRegExp doiRegExp(QStringLiteral("10([.][0-9]+)+/[/-a-z0-9.()<>_:;\\\\]+"), Qt::CaseInsensitive);
79 static const QRegExp mendeleyFileRegExp(QStringLiteral(":(.*):pdf"), Qt::CaseInsensitive);
80 static const QString doiUrlPrefix = QLatin1String("https://dx.doi.org/"); ///< use FileInfo::doiUrlPrefix() instead
81 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);
82 static const QRegExp htmlRegExp = QRegExp(QStringLiteral("</?(a|pre|p|br|span|i|b|italic)\\b[^>{}]{,32}>"), Qt::CaseInsensitive);
83
84 }
85
isLocalOrRelative(const QUrl & url)86 inline static bool isLocalOrRelative(const QUrl &url)
87 {
88 return url.isLocalFile() || url.isRelative() || url.scheme().isEmpty();
89 }
90
91 /**
92 * Poor man's variant of a text-squeezing function.
93 * Effect is similar as observed in KSqueezedTextLabel:
94 * If the text is longer as n characters, the middle part
95 * will be cut away and replaced by "..." to get a
96 * string of max n characters.
97 */
squeezeText(const QString & text,int n)98 inline static QString squeezeText(const QString &text, int n)
99 {
100 return text.length() <= n ? text : text.left(n / 2 - 1) + QLatin1String("...") + text.right(n / 2 - 2);
101 }
102
leftSqueezeText(const QString & text,int n)103 inline static QString leftSqueezeText(const QString &text, int n)
104 {
105 return text.length() <= n ? text : text.left(n) + QLatin1String("...");
106 }
107
108 #define squeeze_text(text, n) ((text).length()<=(n)?(text):(text).left((n)/2-1)+QLatin1String("...")+(text).right((n)/2-2))
109
110 #endif // KBIBTEX_NAMESPACE_H
111