"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2b/arxivXml.cpp" (12 Feb 2021, 2354 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "arxivXml.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0.0_vs_2.0.1.

    1 /***************************************************************************
    2  *   Copyright (C) 2004-2021 by Pere Constans
    3  *   constans@molspaces.com
    4  *   cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
    5  *   See the LICENSE file that comes with this distribution.
    6  ***************************************************************************/
    7 #include "arxivXml.h"
    8 
    9 
   10 arxivXml::arxivXml(const QString& xml) : QXmlStreamReader()
   11 {
   12     _reference.clearReference();
   13     addData(xml);
   14     readReference();
   15 }
   16 
   17 
   18 void arxivXml::readReference()
   19 {
   20     if (hasError())
   21         return;
   22 
   23     QStringList authors;
   24 
   25     while (reading("entry"))
   26         if (name() == "author")
   27             appendAuthor(&authors);
   28         else if (name() == "journal_ref")
   29             readField("note");
   30         else if (name() == "title")
   31             readField("title");
   32         else if (name() == "summary")
   33             readField("abstract");
   34         else if (name() == "doi")
   35             readField("doi");
   36         else if (name() == "id")
   37             processId();
   38         else if (name() == "published")
   39             processDate();
   40 
   41     _reference["author"] = authors.join(", ");
   42 }
   43 
   44 void arxivXml::readField(const QString& field)
   45 {
   46     readNext();
   47     _reference[field] = text().toString();
   48 }
   49 
   50 void arxivXml::processId()
   51 {
   52     readNext();
   53     QRegExp rxarxiv("abs/(.+)$");
   54     if (text().toString().contains(rxarxiv))
   55     {
   56         QString aid(rxarxiv.cap(1));
   57         aid.remove(QRegExp("v\\d{1,2}$"));
   58         _reference["eprint"] = aid;
   59         _reference["journal"] = "arXiv:" + aid;
   60         _reference["url"] = c2bUtils::arxivUrl.arg(aid);
   61     }
   62 }
   63 
   64 void arxivXml::processDate()
   65 {
   66     readNext();
   67     _reference["year"] = text().toString().left(4);
   68 }
   69 
   70 void arxivXml::appendAuthor(QStringList* authors)
   71 {
   72     while (reading("name"))
   73         if (name() == "name")
   74         {
   75             readNext();
   76             authors->append(text().toString());
   77         }
   78 }
   79 
   80 bool arxivXml::reading(const QString& tag)
   81 {
   82     if (tokenType() == NoToken)
   83         while (!atEnd())
   84             if (readNext() == StartElement && name() == tag)
   85                 return true;
   86     while (!atEnd())
   87     {
   88         TokenType t = readNext();
   89         if (t == StartElement)
   90             return true;
   91         else if (t == EndElement && name() == tag)
   92             return false;
   93     }
   94     return false;
   95 }