"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/c2b/crJson.cpp" between
cb2bib-1.9.9.tar.gz and cb2bib-2.0.0.tar.gz

About: cb2Bib is a multiplatform application for rapidly extracting unformatted, or unstandardized bibliographic references from email alerts, journal Web pages, and PDF files.

crJson.cpp  (cb2bib-1.9.9):crJson.cpp  (cb2bib-2.0.0)
/*************************************************************************** /***************************************************************************
* Copyright (C) 2004-2018 by Pere Constans * Copyright (C) 2004-2019 by Pere Constans
* constans@molspaces.com * constans@molspaces.com
* cb2Bib version 1.9.9. Licensed under the GNU GPL version 3. * cb2Bib version 2.0.0. Licensed under the GNU GPL version 3.
* See the LICENSE file that comes with this distribution. * See the LICENSE file that comes with this distribution.
***************************************************************************/ ***************************************************************************/
#include "crJson.h" #include "crJson.h"
#include "cb2bib_utilities.h" #include "cb2bib_utilities.h"
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
skipping to change at line 32 skipping to change at line 32
void crJson::readReference(const QString& json) void crJson::readReference(const QString& json)
{ {
_has_error = true; _has_error = true;
_error_string.clear(); _error_string.clear();
QJsonParseError jerr; QJsonParseError jerr;
QJsonDocument jdoc(QJsonDocument::fromJson(json.toUtf8(), &jerr)); QJsonDocument jdoc(QJsonDocument::fromJson(json.toUtf8(), &jerr));
if (jdoc.isNull() || jdoc.isEmpty()) if (jdoc.isNull() || jdoc.isEmpty())
{ {
_error_string = QObject::tr("Invalid data%1").arg(jerr.errorString().isE _error_string =
mpty() ? QString() : ": " + jerr.errorString()); QObject::tr("Invalid data%1").arg(jerr.errorString().isEmpty() ? QSt
ring() : ": " + jerr.errorString());
return; return;
} }
QJsonObject jobj(jdoc.object().value("message").toObject()); QJsonObject jobj(jdoc.object().value("message").toObject());
if (jobj.isEmpty()) if (jobj.isEmpty())
{ {
_error_string = QObject::tr("Invalid reference data"); _error_string = QObject::tr("Invalid reference data");
return; return;
} }
#ifdef C2B_DEBUG #ifdef C2B_DEBUG
skipping to change at line 56 skipping to change at line 57
if (jobj.value("DOI").isUndefined()) if (jobj.value("DOI").isUndefined())
{ {
_error_string = QObject::tr("Invalid reference data: no DOI parsed"); _error_string = QObject::tr("Invalid reference data: no DOI parsed");
return; return;
} }
_reference["doi"] = jobj.value("DOI").toString(); _reference["doi"] = jobj.value("DOI").toString();
if (!jobj.value("published-print").isUndefined()) if (!jobj.value("published-print").isUndefined())
{ {
const QJsonValue jyear(jobj.value("published-print").toObject().value("d const QJsonValue jyear(
ate-parts").toArray().first().toArray().first()); jobj.value("published-print").toObject().value("date-parts").toArray
().first().toArray().first());
if (!jyear.isUndefined()) if (!jyear.isUndefined())
_reference["year"] = QString::number(jyear.toDouble()); _reference["year"] = QString::number(jyear.toDouble());
} }
else if (!jobj.value("published-online").isUndefined()) else if (!jobj.value("published-online").isUndefined())
{ {
// For articles no longer published in print // For articles no longer published in print
const QJsonValue jyear(jobj.value("published-online").toObject().value(" const QJsonValue jyear(
date-parts").toArray().first().toArray().first()); jobj.value("published-online").toObject().value("date-parts").toArra
y().first().toArray().first());
if (!jyear.isUndefined()) if (!jyear.isUndefined())
_reference["year"] = QString::number(jyear.toDouble()); _reference["year"] = QString::number(jyear.toDouble());
} }
_reference["volume"] = jobj.value("volume").toString(); _reference["volume"] = jobj.value("volume").toString();
_reference["number"] = jobj.value("issue").toString(); _reference["number"] = jobj.value("issue").toString();
_reference["pages"] = jobj.value("page").toString(); _reference["pages"] = jobj.value("page").toString();
QStringList authors; QStringList authors;
const QJsonArray jauthors(jobj.value("author").toArray()); const QJsonArray jauthors(jobj.value("author").toArray());
skipping to change at line 213 skipping to change at line 216
return na.simplified(); return na.simplified();
} }
QString crJson::_bibtex_title(const QStringList& titles, const QStringList& subt itles) QString crJson::_bibtex_title(const QStringList& titles, const QStringList& subt itles)
{ {
if (titles.count() > 0 && subtitles.count() > 0 && !titles.first().contains( ": ")) if (titles.count() > 0 && subtitles.count() > 0 && !titles.first().contains( ": "))
{ {
const int wt(_words(titles.first())); const int wt(_words(titles.first()));
const int ws(_words(subtitles.first())); const int ws(_words(subtitles.first()));
const int wu(_words(titles.first() + ' ' + subtitles.first())); const int wu(_words(titles.first() + ' ' + subtitles.first()));
const int s(100 *(wt + ws - wu) / sqrt(double(wt * ws))); const int s(100 * (wt + ws - wu) / sqrt(double(wt * ws)));
if (s < 30) if (s < 30)
return titles.first() + ": " + subtitles.first(); return titles.first() + ": " + subtitles.first();
} }
return titles.count() > 0 ? titles.first() : QString(); return titles.count() > 0 ? titles.first() : QString();
} }
QString crJson::_bibtex_booktitle(const QStringList& titles) QString crJson::_bibtex_booktitle(const QStringList& titles)
{ {
if (titles.count() == 0) if (titles.count() == 0)
return QString(); return QString();
if (titles.count() == 2) if (titles.count() == 2)
return (!titles.at(1).contains(QRegExp("(advances|series|lecture notes|s return (!titles.at(1).contains(
tudies in|topics in)", Qt::CaseInsensitive))) ? QRegExp("(advances|series|lecture notes|studies in|topics in
titles.at(1) : titles.at(0); )", Qt::CaseInsensitive)))
? titles.at(1)
: titles.at(0);
return titles.first(); return titles.first();
} }
QString crJson::_bibtex_series(const QStringList& titles) QString crJson::_bibtex_series(const QStringList& titles)
{ {
if (titles.count() == 2) if (titles.count() == 2)
return (titles.at(1).contains(QRegExp("(advances|series|lecture notes|st return (titles.at(1).contains(
udies in|topics in)", Qt::CaseInsensitive))) ? QRegExp("(advances|series|lecture notes|studies in|topics in
titles.at(1) : titles.at(0); )", Qt::CaseInsensitive)))
? titles.at(1)
: titles.at(0);
return QString(); return QString();
} }
int crJson::_words(const QString& s) int crJson::_words(const QString& s)
{ {
QStringList wl(s.split(QRegExp("\\W"), QString::SkipEmptyParts)); QStringList wl(s.split(QRegExp("\\W"), QString::SkipEmptyParts));
wl.removeDuplicates(); wl.removeDuplicates();
return wl.count(); return wl.count();
} }
 End of changes. 8 change blocks. 
15 lines changed or deleted 22 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)