Logo Search packages:      
Sourcecode: cb2bib version File versions

citeIDMaker.cpp

/***************************************************************************
 *   Copyright (C) 2004-2009 by Pere Constans
 *   constans@molspaces.com
 *   cb2Bib version 1.3.0. Licensed under the GNU GPL version 3.
 *   See the LICENSE file that comes with this distribution.
 ***************************************************************************/
#include "citeIDMaker.h"

#include "cb2bib_utilities.h"
#include "settings.h"


citeIDMaker::citeIDMaker(QObject* parento) : QObject(parento)
{
    loadSettings();
    connect(settings::instance(), SIGNAL(newSettings()), this, SLOT(loadSettings()));
}

citeIDMaker::~citeIDMaker()
{}


/** \page citeid_placeholders Predefined cite ID placeholders

    - <tt><<author_all_initials>></tt> Takes capitalized initials of all authors in cite.

    - <tt><<author_first>></tt> Takes first author last name/s.

    - <tt><<journal_initials>></tt> Takes capitalized initials of journal name.

    - <tt><<pages_first>></tt> First page.

    - <tt><<ppages_first>></tt> First page, written as, e. g., 'p125'.

    - <tt><<volume>></tt> Volume number.

    - <tt><<year_abbreviated>></tt> Last two digits from year.

    - <tt><<year_full>></tt> All digits from year.


    <b>Note:</b> If <tt>author</tt> is empty, <tt>editor</tt> will be
    considered instead. On conference proceedings or monographs this situation
    is usual.

*/
QString citeIDMaker::makeCiteID(const bibReference& reference)
{
    m_author = reference.value("author");
    m_editor = reference.value("editor");
    m_journal = reference.value("journal");
    m_pages = reference.value("pages");
    m_volume = reference.value("volume");
    m_year = reference.value("year");
    if (m_citeidpattern.contains("<<author_first>>"))
        makeCiteID_author_first(m_author);
    else if (m_citeidpattern.contains("<<author_all_initials>>"))
        makeCiteID_author_all_initials(m_author);
    if (m_citeidpattern.contains("<<journal_initials>>"))
        makeCiteID_journal_initials(m_journal);
    if (m_citeidpattern.contains("<<pages_first>>"))
        makeCiteID_pages_first(m_pages);
    else if (m_citeidpattern.contains("<<ppages_first>>"))
        makeCiteID_ppages_first(m_pages);
    if (m_citeidpattern.contains("<<volume>>"))
        makeCiteID_volume(m_volume);
    if (m_citeidpattern.contains("<<year_abbreviated>>"))
        makeCiteID_year_abbreviated(m_year);
    else if (m_citeidpattern.contains("<<year_full>>"))
        makeCiteID_year_full(m_year);
    QString cid = m_citeidpattern;
    cid.replace("<<author_first>>", m_author);
    cid.replace("<<author_all_initials>>", m_author);
    cid.replace("<<journal_initials>>", m_journal);
    cid.replace("<<pages_first>>", m_pages);
    cid.replace("<<ppages_first>>", m_pages);
    cid.replace("<<volume>>", m_volume);
    cid.replace("<<year_abbreviated>>", m_year);
    cid.replace("<<year_full>>", m_year);
    cid.remove(" ");
    return cid;
}

void citeIDMaker::makeCiteID_author_first(const QString& author)
{
    m_author = author;
    if (m_author.isEmpty())
        m_author = m_editor;
    QRegExp rx("([-'\\s\\w]+)(\\sand|$)");
    rx.setMinimal(true);
    rx.indexIn(m_author);
    m_author = rx.cap(1);
    if (m_author.contains(c2bUtils::nonAsciiLetter))
        m_author = c2bUtils::toAscii(m_author, c2bUtils::Cleanup);
}

void citeIDMaker::makeCiteID_author_all_initials(const QString& author)
{
    m_author = author;
    if (m_author.isEmpty())
        m_author = m_editor;
    m_author.remove(QRegExp("\\b\\w\\b"));
    m_author.remove(" and ");
    m_author.remove(QRegExp("[a-z]"));
    if (m_author.contains(QRegExp("[^A-Z]")))
        m_author = c2bUtils::toAscii(m_author, c2bUtils::Cleanup);
}

void citeIDMaker::makeCiteID_journal_initials(const QString& journal)
{
    m_journal = journal;
    m_journal.remove(QRegExp("[^A-Z]"));
}

void citeIDMaker::makeCiteID_pages_first(const QString& pages)
{
    m_pages = c2bUtils::firstPage(pages);
}

void citeIDMaker::makeCiteID_ppages_first(const QString& pages)
{
    m_pages = c2bUtils::firstPage(pages);
    if (!m_pages.isEmpty())
        m_pages = 'p' + m_pages;
}

void citeIDMaker::makeCiteID_volume(const QString& volume)
{
    m_volume = volume;
}

void citeIDMaker::makeCiteID_year_abbreviated(const QString& year)
{
    m_year = year.right(2);
}

void citeIDMaker::makeCiteID_year_full(const QString& year)
{
    m_year = year;
}

void citeIDMaker::loadSettings()
{
    m_citeidpattern = settings::instance()->value("cb2Bib/CiteIdPattern").toString();
}

Generated by  Doxygen 1.6.0   Back to index