File indexing completed on 2024-05-19 05:05:21
0001 /*************************************************************************** 0002 * SPDX-License-Identifier: GPL-2.0-or-later 0003 * * 0004 * SPDX-FileCopyrightText: 2004-2023 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 #include "kbibtex.h" 0021 0022 #include <QString> 0023 #include <QRegularExpression> 0024 #include <QHash> 0025 #include <QDebug> 0026 0027 const QString KBibTeX::extensionTeX = QStringLiteral(".tex"); 0028 const QString KBibTeX::extensionAux = QStringLiteral(".aux"); 0029 const QString KBibTeX::extensionBBL = QStringLiteral(".bbl"); 0030 const QString KBibTeX::extensionBLG = QStringLiteral(".blg"); 0031 const QString KBibTeX::extensionBibTeX = QStringLiteral(".bib"); 0032 const QString KBibTeX::extensionPDF = QStringLiteral(".pdf"); 0033 const QString KBibTeX::extensionPostScript = QStringLiteral(".ps"); 0034 const QString KBibTeX::extensionRTF = QStringLiteral(".rtf"); 0035 0036 const QString KBibTeX::Months[] = { 0037 QStringLiteral("January"), QStringLiteral("February"), QStringLiteral("March"), QStringLiteral("April"), QStringLiteral("May"), QStringLiteral("June"), QStringLiteral("July"), QStringLiteral("August"), QStringLiteral("September"), QStringLiteral("October"), QStringLiteral("November"), QStringLiteral("December") 0038 }; 0039 0040 const QString KBibTeX::MonthsTriple[] = { 0041 QStringLiteral("jan"), QStringLiteral("feb"), QStringLiteral("mar"), QStringLiteral("apr"), QStringLiteral("may"), QStringLiteral("jun"), QStringLiteral("jul"), QStringLiteral("aug"), QStringLiteral("sep"), QStringLiteral("oct"), QStringLiteral("nov"), QStringLiteral("dec") 0042 }; 0043 0044 const QRegularExpression KBibTeX::fileListSeparatorRegExp(QStringLiteral("[ \\t]*[;\\n]+[ \\t]*")); 0045 const QRegularExpression KBibTeX::fileRegExp(QStringLiteral("(\\bfile:)?[^{}\\t]+\\.\\w{2,4}\\b"), QRegularExpression::CaseInsensitiveOption); 0046 const QRegularExpression KBibTeX::urlRegExp(QStringLiteral("\\b((http|s?ftp|(web)?dav|imap|ipp|ldap|rtsp|sip|stun|turn)s?|mailto|jabber|xmpp|info|file)://[^ {}\"]+(\\b|[/])"), QRegularExpression::CaseInsensitiveOption); 0047 const QRegularExpression KBibTeX::doiRegExp(QStringLiteral("(?<doi>10([.][0-9]+)+/[-/a-z0-9.()<>_:;\\\\]+)"), QRegularExpression::CaseInsensitiveOption); 0048 const QRegularExpression KBibTeX::arXivRegExp(QStringLiteral("\\b(?<arxiv>((astro-ph.CO|astro-ph.EP|astro-ph.GA|astro-ph.HE|astro-ph.IM|astro-ph|astro-ph.SR|cond-mat.dis-nn|cond-mat.mes-hall|cond-mat.mtrl-sci|cond-mat.other|cond-mat.quant-gas|cond-mat|cond-mat.soft|cond-mat.stat-mech|cond-mat.str-el|cond-mat.supr-con|cs.AI|cs.AR|cs.CC|cs.CE|cs.CG|cs.CL|cs.CR|cs.CV|cs.CY|cs.DB|cs.DC|cs.DL|cs.DM|cs.DS|cs.ET|cs.FL|cs.GL|cs.GR|cs.GT|cs.HC|cs.IR|cs.IT|cs.LG|cs.LO|cs.MA|cs.MM|cs.MS|cs.NA|cs.NE|cs.NI|cs.OH|cs.OS|cs.PF|cs.PL|cs|cs.RO|cs.SC|cs.SD|cs.SE|cs.SI|cs.SY|econ.EM|econ.GN|econ|econ.TH|eess.AS|eess.IV|eess|eess.SP|eess.SY|gr-qc|hep-ex|hep-lat|hep-ph|hep-th|math.AC|math.AG|math.AP|math.AT|math.CA|math.CO|math.CT|math.CV|math.DG|math.DS|math.FA|math.GM|math.GN|math.GR|math.GT|math.HO|math.IT|math.KT|math.LO|math.MG|math.MP|math.NA|math.NT|math.OA|math.OC|math-ph|math.PR|math.QA|math.RA|math|math.RT|math.SG|math.SP|math.ST|nlin.AO|nlin.CD|nlin.CG|nlin.PS|nlin|nlin.SI|nucl-ex|nucl-th|physics.acc-ph|physics.ao-ph|physics.app-ph|physics.atm-clus|physics.atom-ph|physics.bio-ph|physics.chem-ph|physics.class-ph|physics.comp-ph|physics.data-an|physics.ed-ph|physics.flu-dyn|physics.gen-ph|physics.geo-ph|physics.hist-ph|physics.ins-det|physics.med-ph|physics.optics|physics.plasm-ph|physics.pop-ph|physics|physics.soc-ph|physics.space-ph|q-bio.BM|q-bio.CB|q-bio.GN|q-bio.MN|q-bio.NC|q-bio.OT|q-bio.PE|q-bio.QM|q-bio|q-bio.SC|q-bio.TO|q-fin.CP|q-fin.EC|q-fin.GN|q-fin.MF|q-fin.PM|q-fin.PR|q-fin|q-fin.RM|q-fin.ST|q-fin.TR|quant-ph|stat.AP|stat.CO|stat.ME|stat.ML|stat.OT|stat|stat.TH|[0-9]{2}(0[1-9]|1[0-2]))/[0-9]{4,7})(v[1-9][0-9]*)?)")); 0049 const QRegularExpression KBibTeX::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"), QRegularExpression::CaseInsensitiveOption); 0050 const QRegularExpression KBibTeX::htmlRegExp(QStringLiteral("</?(a|pre|p|br|span|i|b|italic)\\b[^>{}]{,32}>"), QRegularExpression::CaseInsensitiveOption); 0051 const QString KBibTeX::doiUrlPrefix(QStringLiteral("https://doi.org/")); ///< for internal use in FileInfo::doiUrlPrefix, use FileInfo::doiUrlPrefix() instead 0052 0053 QDebug operator<<(QDebug dbg, const KBibTeX::TypeFlag &typeFlag) 0054 { 0055 static const auto pairs = QHash<int, const char *> { 0056 {static_cast<int>(KBibTeX::TypeFlag::Invalid), "Invalid"}, 0057 {static_cast<int>(KBibTeX::TypeFlag::PlainText), "PlainText"}, 0058 {static_cast<int>(KBibTeX::TypeFlag::Reference), "Reference"}, 0059 {static_cast<int>(KBibTeX::TypeFlag::Person), "Person"}, 0060 {static_cast<int>(KBibTeX::TypeFlag::Keyword), "Keyword"}, 0061 {static_cast<int>(KBibTeX::TypeFlag::Verbatim), "Verbatim"}, 0062 {static_cast<int>(KBibTeX::TypeFlag::Source), "Source"} 0063 }; 0064 dbg.nospace(); 0065 const int typeFlagInt = static_cast<int>(typeFlag); 0066 dbg << (pairs.contains(typeFlagInt) ? pairs[typeFlagInt] : "???"); 0067 return dbg; 0068 } 0069 0070 QDebug operator<<(QDebug dbg, const KBibTeX::TypeFlags &typeFlags) 0071 { 0072 static const auto pairs = QHash<const char *, KBibTeX::TypeFlag> { 0073 {"Invalid", KBibTeX::TypeFlag::Invalid}, 0074 {"PlainText", KBibTeX::TypeFlag::PlainText}, 0075 {"Reference", KBibTeX::TypeFlag::Reference}, 0076 {"Person", KBibTeX::TypeFlag::Person}, 0077 {"Keyword", KBibTeX::TypeFlag::Keyword}, 0078 {"Verbatim", KBibTeX::TypeFlag::Verbatim}, 0079 {"Source", KBibTeX::TypeFlag::Source} 0080 }; 0081 dbg.nospace(); 0082 bool first = true; 0083 for (QHash<const char *, KBibTeX::TypeFlag>::ConstIterator it = pairs.constBegin(); it != pairs.constEnd(); ++it) { 0084 if (typeFlags.testFlag(it.value())) { 0085 if (first) dbg << "|"; 0086 dbg << it.key(); 0087 first = false; 0088 } 0089 } 0090 return dbg; 0091 }