2007-08-14 16:50:51 +00:00
|
|
|
|
/**
|
2007-08-20 16:30:02 +00:00
|
|
|
|
* \file BiblioInfo.cpp
|
2007-08-14 16:50:51 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author Herbert Vo<EFBFBD>
|
2007-08-20 16:30:02 +00:00
|
|
|
|
* \author Richard Heck
|
2007-08-14 16:50:51 +00:00
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2007-08-14 22:18:27 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2007-08-20 17:04:36 +00:00
|
|
|
|
#include "BiblioInfo.h"
|
2007-08-20 16:30:02 +00:00
|
|
|
|
#include "Buffer.h"
|
|
|
|
|
#include "BufferParams.h"
|
2007-08-15 08:57:58 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
2007-08-14 16:50:51 +00:00
|
|
|
|
#include "InsetIterator.h"
|
|
|
|
|
#include "Paragraph.h"
|
|
|
|
|
|
|
|
|
|
#include "insets/Inset.h"
|
|
|
|
|
#include "insets/InsetBibitem.h"
|
|
|
|
|
#include "insets/InsetBibtex.h"
|
|
|
|
|
#include "insets/InsetInclude.h"
|
|
|
|
|
|
2007-11-01 22:17:22 +00:00
|
|
|
|
#include "support/docstream.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/gettext.h"
|
|
|
|
|
#include "support/lstrings.h"
|
2007-08-14 16:50:51 +00:00
|
|
|
|
|
2007-08-14 22:18:27 +00:00
|
|
|
|
#include "boost/regex.hpp"
|
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
|
using namespace lyx::support;
|
2007-08-14 16:50:51 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
2007-11-05 20:33:20 +00:00
|
|
|
|
|
2007-08-14 16:50:51 +00:00
|
|
|
|
|
2007-11-05 20:33:20 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2007-08-20 16:30:02 +00:00
|
|
|
|
//
|
|
|
|
|
// BibTeXInfo
|
|
|
|
|
//
|
2007-11-05 20:33:20 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2007-08-14 16:50:51 +00:00
|
|
|
|
|
2008-02-14 05:00:54 +00:00
|
|
|
|
BibTeXInfo::BibTeXInfo(bool ib)
|
2008-02-14 17:00:40 +00:00
|
|
|
|
: is_bibtex_(ib)
|
2008-02-14 05:00:54 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BibTeXInfo::BibTeXInfo(docstring const & key, docstring const & type)
|
2008-02-14 17:00:40 +00:00
|
|
|
|
: is_bibtex_(true), bib_key_(key), entry_type_(type)
|
2007-08-16 01:59:20 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
bool BibTeXInfo::hasField(docstring const & field) const
|
|
|
|
|
{
|
|
|
|
|
return count(field) == 1;
|
|
|
|
|
}
|
2007-08-16 01:59:20 +00:00
|
|
|
|
|
|
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
docstring const & BibTeXInfo::getValueForField(docstring const & field) const
|
2007-08-16 01:59:20 +00:00
|
|
|
|
{
|
2007-08-20 16:30:02 +00:00
|
|
|
|
BibTeXInfo::const_iterator it = find(field);
|
|
|
|
|
if (it != end())
|
|
|
|
|
return it->second;
|
|
|
|
|
static docstring const empty_value = docstring();
|
|
|
|
|
return empty_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring const & BibTeXInfo::getValueForField(string const & field) const
|
|
|
|
|
{
|
|
|
|
|
return getValueForField(from_ascii(field));
|
2007-08-16 01:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 20:33:20 +00:00
|
|
|
|
static docstring familyName(docstring const & name)
|
|
|
|
|
{
|
|
|
|
|
if (name.empty())
|
|
|
|
|
return docstring();
|
2007-08-14 16:50:51 +00:00
|
|
|
|
|
2007-11-05 20:33:20 +00:00
|
|
|
|
// Very simple parser
|
|
|
|
|
docstring fname = name;
|
|
|
|
|
|
|
|
|
|
// possible authorname combinations are:
|
|
|
|
|
// "Surname, FirstName"
|
|
|
|
|
// "Surname, F."
|
|
|
|
|
// "FirstName Surname"
|
|
|
|
|
// "F. Surname"
|
|
|
|
|
docstring::size_type idx = fname.find(',');
|
|
|
|
|
if (idx != docstring::npos)
|
|
|
|
|
return ltrim(fname.substr(0, idx));
|
|
|
|
|
idx = fname.rfind('.');
|
|
|
|
|
if (idx != docstring::npos && idx + 1 < fname.size())
|
|
|
|
|
fname = ltrim(fname.substr(idx + 1));
|
|
|
|
|
// test if we have a LaTeX Space in front
|
|
|
|
|
if (fname[0] == '\\')
|
|
|
|
|
return fname.substr(2);
|
|
|
|
|
return rtrim(fname);
|
|
|
|
|
}
|
2007-08-14 16:50:51 +00:00
|
|
|
|
|
|
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
docstring const BibTeXInfo::getAbbreviatedAuthor() const
|
2007-08-14 16:50:51 +00:00
|
|
|
|
{
|
2008-02-14 17:00:40 +00:00
|
|
|
|
if (!is_bibtex_)
|
2007-08-16 01:59:20 +00:00
|
|
|
|
return docstring();
|
|
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
docstring author = getValueForField("author");
|
2007-08-16 01:59:20 +00:00
|
|
|
|
|
2007-08-14 16:50:51 +00:00
|
|
|
|
if (author.empty()) {
|
2007-08-20 16:30:02 +00:00
|
|
|
|
author = getValueForField("editor");
|
|
|
|
|
if (author.empty())
|
2008-02-14 17:00:40 +00:00
|
|
|
|
return bib_key_;
|
2007-08-14 16:50:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-05 20:33:20 +00:00
|
|
|
|
// OK, we've got some names. Let's format them.
|
|
|
|
|
// Try to split the author list on " and "
|
2007-08-20 16:30:02 +00:00
|
|
|
|
vector<docstring> const authors =
|
|
|
|
|
getVectorFromString(author, from_ascii(" and "));
|
2007-08-16 01:59:20 +00:00
|
|
|
|
|
2007-08-14 16:50:51 +00:00
|
|
|
|
if (authors.size() == 2)
|
|
|
|
|
return bformat(_("%1$s and %2$s"),
|
2007-08-20 16:30:02 +00:00
|
|
|
|
familyName(authors[0]), familyName(authors[1]));
|
2007-11-05 20:33:20 +00:00
|
|
|
|
|
|
|
|
|
if (authors.size() > 2)
|
2007-08-14 16:50:51 +00:00
|
|
|
|
return bformat(_("%1$s et al."), familyName(authors[0]));
|
2007-11-05 20:33:20 +00:00
|
|
|
|
|
|
|
|
|
return familyName(authors[0]);
|
2007-08-14 16:50:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-05 20:33:20 +00:00
|
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
docstring const BibTeXInfo::getYear() const
|
2007-08-14 16:50:51 +00:00
|
|
|
|
{
|
2008-02-14 17:00:40 +00:00
|
|
|
|
if (!is_bibtex_)
|
2007-08-16 01:59:20 +00:00
|
|
|
|
return docstring();
|
|
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
docstring year = getValueForField("year");
|
2007-08-14 16:50:51 +00:00
|
|
|
|
if (year.empty())
|
|
|
|
|
year = _("No year");
|
|
|
|
|
return year;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
docstring const BibTeXInfo::getInfo() const
|
2007-08-14 16:50:51 +00:00
|
|
|
|
{
|
2008-02-14 17:00:40 +00:00
|
|
|
|
if (!is_bibtex_) {
|
2007-08-20 16:30:02 +00:00
|
|
|
|
BibTeXInfo::const_iterator it = find(from_ascii("ref"));
|
|
|
|
|
return it->second;
|
2007-08-14 16:50:51 +00:00
|
|
|
|
}
|
2007-08-16 01:59:20 +00:00
|
|
|
|
|
2007-11-05 20:33:20 +00:00
|
|
|
|
// FIXME
|
|
|
|
|
// This could be made a lot better using the entryType
|
|
|
|
|
// field to customize the output based upon entry type.
|
2007-08-16 01:59:20 +00:00
|
|
|
|
|
2007-11-05 20:33:20 +00:00
|
|
|
|
// Search for all possible "required" fields
|
2007-08-20 16:30:02 +00:00
|
|
|
|
docstring author = getValueForField("author");
|
2007-08-14 16:50:51 +00:00
|
|
|
|
if (author.empty())
|
2007-08-20 16:30:02 +00:00
|
|
|
|
author = getValueForField("editor");
|
2007-08-16 01:59:20 +00:00
|
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
docstring year = getValueForField("year");
|
|
|
|
|
docstring title = getValueForField("title");
|
|
|
|
|
docstring docLoc = getValueForField("pages");
|
2007-08-16 01:59:20 +00:00
|
|
|
|
if (docLoc.empty()) {
|
2007-08-20 16:30:02 +00:00
|
|
|
|
docLoc = getValueForField("chapter");
|
2007-08-16 01:59:20 +00:00
|
|
|
|
if (!docLoc.empty())
|
|
|
|
|
docLoc = from_ascii("Ch. ") + docLoc;
|
2007-11-05 20:33:20 +00:00
|
|
|
|
} else {
|
2007-08-16 01:59:20 +00:00
|
|
|
|
docLoc = from_ascii("pp. ") + docLoc;
|
2007-11-05 20:33:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
docstring media = getValueForField("journal");
|
|
|
|
|
if (media.empty()) {
|
|
|
|
|
media = getValueForField("publisher");
|
2007-08-16 01:59:20 +00:00
|
|
|
|
if (media.empty()) {
|
2007-11-05 20:33:20 +00:00
|
|
|
|
media = getValueForField("school");
|
|
|
|
|
if (media.empty())
|
|
|
|
|
media = getValueForField("institution");
|
2007-08-16 01:59:20 +00:00
|
|
|
|
}
|
2007-11-05 20:33:20 +00:00
|
|
|
|
}
|
|
|
|
|
docstring volume = getValueForField("volume");
|
|
|
|
|
|
|
|
|
|
odocstringstream result;
|
|
|
|
|
if (!author.empty())
|
|
|
|
|
result << author << ", ";
|
|
|
|
|
if (!title.empty())
|
|
|
|
|
result << title;
|
|
|
|
|
if (!media.empty())
|
|
|
|
|
result << ", " << media;
|
|
|
|
|
if (!year.empty())
|
|
|
|
|
result << ", " << year;
|
|
|
|
|
if (!docLoc.empty())
|
|
|
|
|
result << ", " << docLoc;
|
|
|
|
|
|
|
|
|
|
docstring const result_str = rtrim(result.str());
|
|
|
|
|
if (!result_str.empty())
|
|
|
|
|
return result_str;
|
|
|
|
|
|
|
|
|
|
// This should never happen (or at least be very unusual!)
|
|
|
|
|
return docstring();
|
2007-08-14 16:50:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 20:33:20 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2007-08-20 16:30:02 +00:00
|
|
|
|
//
|
|
|
|
|
// BiblioInfo
|
|
|
|
|
//
|
2007-11-05 20:33:20 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2007-08-20 16:30:02 +00:00
|
|
|
|
|
2007-08-14 16:50:51 +00:00
|
|
|
|
namespace {
|
2007-12-12 19:28:07 +00:00
|
|
|
|
// A functor for use with sort, leading to case insensitive sorting
|
|
|
|
|
class compareNoCase: public binary_function<docstring, docstring, bool>
|
2007-08-20 16:30:02 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
bool operator()(docstring const & s1, docstring const & s2) const {
|
|
|
|
|
return compare_no_case(s1, s2) < 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
2007-08-14 16:50:51 +00:00
|
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
vector<docstring> const BiblioInfo::getKeys() const
|
2007-08-14 16:50:51 +00:00
|
|
|
|
{
|
2007-08-20 16:30:02 +00:00
|
|
|
|
vector<docstring> bibkeys;
|
|
|
|
|
BiblioInfo::const_iterator it = begin();
|
|
|
|
|
for (; it != end(); ++it)
|
|
|
|
|
bibkeys.push_back(it->first);
|
2007-12-12 19:28:07 +00:00
|
|
|
|
sort(bibkeys.begin(), bibkeys.end(), compareNoCase());
|
2007-08-20 16:30:02 +00:00
|
|
|
|
return bibkeys;
|
2007-08-14 16:50:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
vector<docstring> const BiblioInfo::getFields() const
|
2007-08-14 16:50:51 +00:00
|
|
|
|
{
|
2007-08-20 16:30:02 +00:00
|
|
|
|
vector<docstring> bibfields;
|
2008-02-14 17:00:40 +00:00
|
|
|
|
set<docstring>::const_iterator it = field_names_.begin();
|
|
|
|
|
set<docstring>::const_iterator end = field_names_.end();
|
2007-08-20 16:30:02 +00:00
|
|
|
|
for (; it != end; ++it)
|
|
|
|
|
bibfields.push_back(*it);
|
2007-12-12 19:28:07 +00:00
|
|
|
|
sort(bibfields.begin(), bibfields.end());
|
2007-08-20 16:30:02 +00:00
|
|
|
|
return bibfields;
|
|
|
|
|
}
|
2007-08-14 16:50:51 +00:00
|
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
|
|
|
|
|
vector<docstring> const BiblioInfo::getEntries() const
|
|
|
|
|
{
|
|
|
|
|
vector<docstring> bibentries;
|
2008-02-14 17:00:40 +00:00
|
|
|
|
set<docstring>::const_iterator it = entry_types_.begin();
|
|
|
|
|
set<docstring>::const_iterator end = entry_types_.end();
|
2007-08-20 16:30:02 +00:00
|
|
|
|
for (; it != end; ++it)
|
|
|
|
|
bibentries.push_back(*it);
|
2007-12-12 19:28:07 +00:00
|
|
|
|
sort(bibentries.begin(), bibentries.end());
|
2007-08-20 16:30:02 +00:00
|
|
|
|
return bibentries;
|
|
|
|
|
}
|
2007-08-14 16:50:51 +00:00
|
|
|
|
|
|
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
docstring const BiblioInfo::getAbbreviatedAuthor(docstring const & key) const
|
2007-08-14 16:50:51 +00:00
|
|
|
|
{
|
2007-08-20 16:30:02 +00:00
|
|
|
|
BiblioInfo::const_iterator it = find(key);
|
|
|
|
|
if (it == end())
|
|
|
|
|
return docstring();
|
|
|
|
|
BibTeXInfo const & data = it->second;
|
|
|
|
|
return data.getAbbreviatedAuthor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring const BiblioInfo::getYear(docstring const & key) const
|
|
|
|
|
{
|
|
|
|
|
BiblioInfo::const_iterator it = find(key);
|
|
|
|
|
if (it == end())
|
|
|
|
|
return docstring();
|
|
|
|
|
BibTeXInfo const & data = it->second;
|
|
|
|
|
return data.getYear();
|
2007-08-14 16:50:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
docstring const BiblioInfo::getInfo(docstring const & key) const
|
2007-08-14 16:50:51 +00:00
|
|
|
|
{
|
2007-08-20 16:30:02 +00:00
|
|
|
|
BiblioInfo::const_iterator it = find(key);
|
|
|
|
|
if (it == end())
|
2007-08-14 16:50:51 +00:00
|
|
|
|
return docstring();
|
2007-08-20 16:30:02 +00:00
|
|
|
|
BibTeXInfo const & data = it->second;
|
|
|
|
|
return data.getInfo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<docstring> const BiblioInfo::getCiteStrings(
|
|
|
|
|
docstring const & key, Buffer const & buf) const
|
|
|
|
|
{
|
|
|
|
|
biblio::CiteEngine const engine = buf.params().getEngine();
|
2007-12-20 15:46:14 +00:00
|
|
|
|
if (engine == biblio::ENGINE_BASIC ||
|
|
|
|
|
engine == biblio::ENGINE_NATBIB_NUMERICAL)
|
2007-08-20 16:30:02 +00:00
|
|
|
|
return getNumericalStrings(key, buf);
|
|
|
|
|
else
|
|
|
|
|
return getAuthorYearStrings(key, buf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<docstring> const BiblioInfo::getNumericalStrings(
|
|
|
|
|
docstring const & key, Buffer const & buf) const
|
|
|
|
|
{
|
|
|
|
|
if (empty())
|
|
|
|
|
return vector<docstring>();
|
|
|
|
|
|
|
|
|
|
docstring const author = getAbbreviatedAuthor(key);
|
|
|
|
|
docstring const year = getYear(key);
|
|
|
|
|
if (author.empty() || year.empty())
|
|
|
|
|
return vector<docstring>();
|
|
|
|
|
|
|
|
|
|
vector<biblio::CiteStyle> const & styles =
|
|
|
|
|
biblio::getCiteStyles(buf.params().getEngine());
|
|
|
|
|
|
|
|
|
|
vector<docstring> vec(styles.size());
|
2007-12-20 15:46:14 +00:00
|
|
|
|
for (vector<docstring>::size_type i = 0; i != vec.size(); ++i) {
|
2007-08-20 16:30:02 +00:00
|
|
|
|
docstring str;
|
|
|
|
|
|
|
|
|
|
switch (styles[i]) {
|
|
|
|
|
case biblio::CITE:
|
|
|
|
|
case biblio::CITEP:
|
|
|
|
|
str = from_ascii("[#ID]");
|
|
|
|
|
break;
|
|
|
|
|
|
2007-12-20 15:46:14 +00:00
|
|
|
|
case biblio::NOCITE:
|
|
|
|
|
str = _("Add to bibliography only.");
|
|
|
|
|
break;
|
|
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
case biblio::CITET:
|
|
|
|
|
str = author + " [#ID]";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case biblio::CITEALT:
|
|
|
|
|
str = author + " #ID";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case biblio::CITEALP:
|
|
|
|
|
str = from_ascii("#ID");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case biblio::CITEAUTHOR:
|
|
|
|
|
str = author;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case biblio::CITEYEAR:
|
|
|
|
|
str = year;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case biblio::CITEYEARPAR:
|
|
|
|
|
str = '(' + year + ')';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vec[i] = str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return vec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<docstring> const BiblioInfo::getAuthorYearStrings(
|
|
|
|
|
docstring const & key, Buffer const & buf) const
|
|
|
|
|
{
|
|
|
|
|
if (empty())
|
|
|
|
|
return vector<docstring>();
|
|
|
|
|
|
|
|
|
|
docstring const author = getAbbreviatedAuthor(key);
|
|
|
|
|
docstring const year = getYear(key);
|
|
|
|
|
if (author.empty() || year.empty())
|
|
|
|
|
return vector<docstring>();
|
|
|
|
|
|
|
|
|
|
vector<biblio::CiteStyle> const & styles =
|
|
|
|
|
getCiteStyles(buf.params().getEngine());
|
|
|
|
|
|
|
|
|
|
vector<docstring> vec(styles.size());
|
|
|
|
|
for (vector<docstring>::size_type i = 0; i != vec.size(); ++i) {
|
|
|
|
|
docstring str;
|
|
|
|
|
|
|
|
|
|
switch (styles[i]) {
|
|
|
|
|
case biblio::CITE:
|
|
|
|
|
// jurabib only: Author/Annotator
|
|
|
|
|
// (i.e. the "before" field, 2nd opt arg)
|
|
|
|
|
str = author + "/<" + _("before") + '>';
|
|
|
|
|
break;
|
|
|
|
|
|
2007-12-20 15:46:14 +00:00
|
|
|
|
case biblio::NOCITE:
|
|
|
|
|
str = _("Add to bibliography only.");
|
|
|
|
|
break;
|
|
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
case biblio::CITET:
|
|
|
|
|
str = author + " (" + year + ')';
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case biblio::CITEP:
|
|
|
|
|
str = '(' + author + ", " + year + ')';
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case biblio::CITEALT:
|
|
|
|
|
str = author + ' ' + year ;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case biblio::CITEALP:
|
|
|
|
|
str = author + ", " + year ;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case biblio::CITEAUTHOR:
|
|
|
|
|
str = author;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case biblio::CITEYEAR:
|
|
|
|
|
str = year;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case biblio::CITEYEARPAR:
|
|
|
|
|
str = '(' + year + ')';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
vec[i] = str;
|
|
|
|
|
}
|
|
|
|
|
return vec;
|
2007-08-14 16:50:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
|
|
|
|
|
void BiblioInfo::fillWithBibKeys(Buffer const * const buf)
|
|
|
|
|
{
|
|
|
|
|
/// if this is a child document and the parent is already loaded
|
|
|
|
|
/// use the parent's list instead [ale990412]
|
2007-10-20 10:03:45 +00:00
|
|
|
|
Buffer const * const tmp = buf->masterBuffer();
|
2007-08-20 16:30:02 +00:00
|
|
|
|
BOOST_ASSERT(tmp);
|
|
|
|
|
if (tmp != buf) {
|
|
|
|
|
this->fillWithBibKeys(tmp);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (InsetIterator it = inset_iterator_begin(buf->inset()); it; ++it)
|
2008-02-27 20:43:16 +00:00
|
|
|
|
it->fillWithBibKeys(*this, it);
|
2007-08-20 16:30:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace biblio {
|
|
|
|
|
|
2007-11-05 20:33:20 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2007-08-20 16:30:02 +00:00
|
|
|
|
//
|
|
|
|
|
// CitationStyle
|
|
|
|
|
//
|
2007-11-05 20:33:20 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2007-08-20 16:30:02 +00:00
|
|
|
|
|
2007-08-14 16:50:51 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char const * const citeCommands[] = {
|
2007-12-20 15:46:14 +00:00
|
|
|
|
"cite", "nocite", "citet", "citep", "citealt", "citealp",
|
|
|
|
|
"citeauthor", "citeyear", "citeyearpar" };
|
2007-08-14 16:50:51 +00:00
|
|
|
|
|
|
|
|
|
unsigned int const nCiteCommands =
|
|
|
|
|
sizeof(citeCommands) / sizeof(char *);
|
|
|
|
|
|
|
|
|
|
CiteStyle const citeStyles[] = {
|
2007-12-20 15:46:14 +00:00
|
|
|
|
CITE, NOCITE, CITET, CITEP, CITEALT,
|
|
|
|
|
CITEALP, CITEAUTHOR, CITEYEAR, CITEYEARPAR };
|
2007-08-14 16:50:51 +00:00
|
|
|
|
|
|
|
|
|
unsigned int const nCiteStyles =
|
|
|
|
|
sizeof(citeStyles) / sizeof(CiteStyle);
|
|
|
|
|
|
|
|
|
|
CiteStyle const citeStylesFull[] = {
|
|
|
|
|
CITET, CITEP, CITEALT, CITEALP, CITEAUTHOR };
|
|
|
|
|
|
|
|
|
|
unsigned int const nCiteStylesFull =
|
|
|
|
|
sizeof(citeStylesFull) / sizeof(CiteStyle);
|
|
|
|
|
|
|
|
|
|
CiteStyle const citeStylesUCase[] = {
|
|
|
|
|
CITET, CITEP, CITEALT, CITEALP, CITEAUTHOR };
|
|
|
|
|
|
|
|
|
|
unsigned int const nCiteStylesUCase =
|
|
|
|
|
sizeof(citeStylesUCase) / sizeof(CiteStyle);
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CitationStyle::CitationStyle(string const & command)
|
|
|
|
|
: style(CITE), full(false), forceUCase(false)
|
|
|
|
|
{
|
|
|
|
|
if (command.empty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
string cmd = command;
|
|
|
|
|
if (cmd[0] == 'C') {
|
|
|
|
|
forceUCase = true;
|
|
|
|
|
cmd[0] = 'c';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string::size_type const n = cmd.size() - 1;
|
|
|
|
|
if (cmd != "cite" && cmd[n] == '*') {
|
|
|
|
|
full = true;
|
|
|
|
|
cmd = cmd.substr(0,n);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char const * const * const last = citeCommands + nCiteCommands;
|
2007-12-12 19:28:07 +00:00
|
|
|
|
char const * const * const ptr = find(citeCommands, last, cmd);
|
2007-08-14 16:50:51 +00:00
|
|
|
|
|
|
|
|
|
if (ptr != last) {
|
|
|
|
|
size_t idx = ptr - citeCommands;
|
|
|
|
|
style = citeStyles[idx];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const CitationStyle::asLatexStr() const
|
|
|
|
|
{
|
|
|
|
|
string cite = citeCommands[style];
|
|
|
|
|
if (full) {
|
|
|
|
|
CiteStyle const * last = citeStylesFull + nCiteStylesFull;
|
2007-12-12 19:28:07 +00:00
|
|
|
|
if (find(citeStylesFull, last, style) != last)
|
2007-08-14 16:50:51 +00:00
|
|
|
|
cite += '*';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (forceUCase) {
|
|
|
|
|
CiteStyle const * last = citeStylesUCase + nCiteStylesUCase;
|
2007-12-12 19:28:07 +00:00
|
|
|
|
if (find(citeStylesUCase, last, style) != last)
|
2007-08-14 16:50:51 +00:00
|
|
|
|
cite[0] = 'C';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cite;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<CiteStyle> const getCiteStyles(CiteEngine const engine)
|
|
|
|
|
{
|
|
|
|
|
unsigned int nStyles = 0;
|
|
|
|
|
unsigned int start = 0;
|
|
|
|
|
|
|
|
|
|
switch (engine) {
|
|
|
|
|
case ENGINE_BASIC:
|
2007-12-20 15:46:14 +00:00
|
|
|
|
nStyles = 2;
|
2007-08-14 16:50:51 +00:00
|
|
|
|
start = 0;
|
|
|
|
|
break;
|
|
|
|
|
case ENGINE_NATBIB_AUTHORYEAR:
|
|
|
|
|
case ENGINE_NATBIB_NUMERICAL:
|
|
|
|
|
nStyles = nCiteStyles - 1;
|
|
|
|
|
start = 1;
|
|
|
|
|
break;
|
|
|
|
|
case ENGINE_JURABIB:
|
|
|
|
|
nStyles = nCiteStyles;
|
|
|
|
|
start = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef vector<CiteStyle> cite_vec;
|
|
|
|
|
|
|
|
|
|
cite_vec styles(nStyles);
|
2007-11-05 20:33:20 +00:00
|
|
|
|
size_t i = 0;
|
2007-08-14 16:50:51 +00:00
|
|
|
|
int j = start;
|
|
|
|
|
for (; i != styles.size(); ++i, ++j)
|
|
|
|
|
styles[i] = citeStyles[j];
|
|
|
|
|
|
|
|
|
|
return styles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace biblio
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|