X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBiblioInfo.cpp;h=896d8fc4a8a1d895f1805c2641a47fdf3cb9fb1c;hb=105e0dfe2910e0bbd13857dabff84bfadda156c4;hp=4718d37ed27c1575edfded80a31d0727fa3f4213;hpb=5216137bdb1a894f1896bdedbfb28f7b192758e7;p=lyx.git diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp index 4718d37ed2..896d8fc4a8 100644 --- a/src/BiblioInfo.cpp +++ b/src/BiblioInfo.cpp @@ -16,7 +16,6 @@ #include "Buffer.h" #include "BufferParams.h" #include "buffer_funcs.h" -#include "gettext.h" #include "InsetIterator.h" #include "Paragraph.h" @@ -25,24 +24,18 @@ #include "insets/InsetBibtex.h" #include "insets/InsetInclude.h" -#include "support/lstrings.h" +#include "support/lassert.h" #include "support/docstream.h" +#include "support/gettext.h" +#include "support/lstrings.h" #include "boost/regex.hpp" -using std::string; -using std::vector; -using std::pair; -using std::endl; -using std::set; +using namespace std; +using namespace lyx::support; -namespace lyx { -using support::bformat; -using support::compare_no_case; -using support::getVectorFromString; -using support::ltrim; -using support::rtrim; +namespace lyx { ////////////////////////////////////////////////////////////////////// // @@ -50,11 +43,11 @@ using support::rtrim; // ////////////////////////////////////////////////////////////////////// -BibTeXInfo::BibTeXInfo() - : isBibTeX(true) +BibTeXInfo::BibTeXInfo(docstring const & key, docstring const & type) + : is_bibtex_(true), bib_key_(key), entry_type_(type) {} - + bool BibTeXInfo::hasField(docstring const & field) const { return count(field) == 1; @@ -77,7 +70,7 @@ docstring const & BibTeXInfo::getValueForField(string const & field) const } -static docstring familyName(docstring const & name) +docstring familyName(docstring const & name) { if (name.empty()) return docstring(); @@ -105,7 +98,7 @@ static docstring familyName(docstring const & name) docstring const BibTeXInfo::getAbbreviatedAuthor() const { - if (!isBibTeX) + if (!is_bibtex_) return docstring(); docstring author = getValueForField("author"); @@ -113,7 +106,7 @@ docstring const BibTeXInfo::getAbbreviatedAuthor() const if (author.empty()) { author = getValueForField("editor"); if (author.empty()) - return bibKey; + return bib_key_; } // OK, we've got some names. Let's format them. @@ -134,7 +127,7 @@ docstring const BibTeXInfo::getAbbreviatedAuthor() const docstring const BibTeXInfo::getYear() const { - if (!isBibTeX) + if (!is_bibtex_) return docstring(); docstring year = getValueForField("year"); @@ -146,7 +139,7 @@ docstring const BibTeXInfo::getYear() const docstring const BibTeXInfo::getInfo() const { - if (!isBibTeX) { + if (!is_bibtex_) { BibTeXInfo::const_iterator it = find(from_ascii("ref")); return it->second; } @@ -210,8 +203,8 @@ docstring const BibTeXInfo::getInfo() const ////////////////////////////////////////////////////////////////////// namespace { -// A functor for use with std::sort, leading to case insensitive sorting - class compareNoCase: public std::binary_function +// A functor for use with sort, leading to case insensitive sorting + class compareNoCase: public binary_function { public: bool operator()(docstring const & s1, docstring const & s2) const { @@ -227,7 +220,7 @@ vector const BiblioInfo::getKeys() const BiblioInfo::const_iterator it = begin(); for (; it != end(); ++it) bibkeys.push_back(it->first); - std::sort(bibkeys.begin(), bibkeys.end(), compareNoCase()); + sort(bibkeys.begin(), bibkeys.end(), compareNoCase()); return bibkeys; } @@ -235,11 +228,11 @@ vector const BiblioInfo::getKeys() const vector const BiblioInfo::getFields() const { vector bibfields; - set::const_iterator it = fieldNames.begin(); - set::const_iterator end = fieldNames.end(); + set::const_iterator it = field_names_.begin(); + set::const_iterator end = field_names_.end(); for (; it != end; ++it) bibfields.push_back(*it); - std::sort(bibfields.begin(), bibfields.end()); + sort(bibfields.begin(), bibfields.end()); return bibfields; } @@ -247,11 +240,11 @@ vector const BiblioInfo::getFields() const vector const BiblioInfo::getEntries() const { vector bibentries; - set::const_iterator it = entryTypes.begin(); - set::const_iterator end = entryTypes.end(); + set::const_iterator it = entry_types_.begin(); + set::const_iterator end = entry_types_.end(); for (; it != end; ++it) bibentries.push_back(*it); - std::sort(bibentries.begin(), bibentries.end()); + sort(bibentries.begin(), bibentries.end()); return bibentries; } @@ -289,8 +282,8 @@ docstring const BiblioInfo::getInfo(docstring const & key) const vector const BiblioInfo::getCiteStrings( docstring const & key, Buffer const & buf) const { - biblio::CiteEngine const engine = buf.params().getEngine(); - if (engine == biblio::ENGINE_NATBIB_NUMERICAL) + CiteEngine const engine = buf.params().citeEngine(); + if (engine == ENGINE_BASIC || engine == ENGINE_NATBIB_NUMERICAL) return getNumericalStrings(key, buf); else return getAuthorYearStrings(key, buf); @@ -308,40 +301,43 @@ vector const BiblioInfo::getNumericalStrings( if (author.empty() || year.empty()) return vector(); - vector const & styles = - biblio::getCiteStyles(buf.params().getEngine()); + vector const & styles = citeStyles(buf.params().citeEngine()); vector vec(styles.size()); for (size_t i = 0; i != vec.size(); ++i) { docstring str; switch (styles[i]) { - case biblio::CITE: - case biblio::CITEP: + case CITE: + case CITEP: str = from_ascii("[#ID]"); break; - case biblio::CITET: + case NOCITE: + str = _("Add to bibliography only."); + break; + + case CITET: str = author + " [#ID]"; break; - case biblio::CITEALT: + case CITEALT: str = author + " #ID"; break; - case biblio::CITEALP: + case CITEALP: str = from_ascii("#ID"); break; - case biblio::CITEAUTHOR: + case CITEAUTHOR: str = author; break; - case biblio::CITEYEAR: + case CITEYEAR: str = year; break; - case biblio::CITEYEARPAR: + case CITEYEARPAR: str = '(' + year + ')'; break; } @@ -364,45 +360,48 @@ vector const BiblioInfo::getAuthorYearStrings( if (author.empty() || year.empty()) return vector(); - vector const & styles = - getCiteStyles(buf.params().getEngine()); + vector const & styles = citeStyles(buf.params().citeEngine()); vector vec(styles.size()); - for (vector::size_type i = 0; i != vec.size(); ++i) { + for (size_t i = 0; i != vec.size(); ++i) { docstring str; switch (styles[i]) { - case biblio::CITE: + case CITE: // jurabib only: Author/Annotator // (i.e. the "before" field, 2nd opt arg) str = author + "/<" + _("before") + '>'; break; - case biblio::CITET: + case NOCITE: + str = _("Add to bibliography only."); + break; + + case CITET: str = author + " (" + year + ')'; break; - case biblio::CITEP: + case CITEP: str = '(' + author + ", " + year + ')'; break; - case biblio::CITEALT: + case CITEALT: str = author + ' ' + year ; break; - case biblio::CITEALP: + case CITEALP: str = author + ", " + year ; break; - case biblio::CITEAUTHOR: + case CITEAUTHOR: str = author; break; - case biblio::CITEYEAR: + case CITEYEAR: str = year; break; - case biblio::CITEYEARPAR: + case CITEYEARPAR: str = '(' + year + ')'; break; } @@ -412,27 +411,12 @@ vector const BiblioInfo::getAuthorYearStrings( } -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] - Buffer const * const tmp = buf->masterBuffer(); - BOOST_ASSERT(tmp); - if (tmp != buf) { - this->fillWithBibKeys(tmp); - return; - } - - // Pre-load all child documents. - buf->loadChildDocuments(); - - for (InsetIterator it = inset_iterator_begin(buf->inset()); it; ++it) - it->fillWithBibKeys(*buf, *this, it); +void BiblioInfo::mergeBiblioInfo(BiblioInfo const & info) +{ + bimap_.insert(info.begin(), info.end()); } -namespace biblio { - ////////////////////////////////////////////////////////////////////// // // CitationStyle @@ -443,18 +427,18 @@ namespace { char const * const citeCommands[] = { - "cite", "citet", "citep", "citealt", "citealp", "citeauthor", - "citeyear", "citeyearpar" }; + "cite", "nocite", "citet", "citep", "citealt", "citealp", + "citeauthor", "citeyear", "citeyearpar" }; unsigned int const nCiteCommands = sizeof(citeCommands) / sizeof(char *); -CiteStyle const citeStyles[] = { - CITE, CITET, CITEP, CITEALT, CITEALP, -CITEAUTHOR, CITEYEAR, CITEYEARPAR }; +CiteStyle const citeStylesArray[] = { + CITE, NOCITE, CITET, CITEP, CITEALT, + CITEALP, CITEAUTHOR, CITEYEAR, CITEYEARPAR }; unsigned int const nCiteStyles = - sizeof(citeStyles) / sizeof(CiteStyle); + sizeof(citeStylesArray) / sizeof(CiteStyle); CiteStyle const citeStylesFull[] = { CITET, CITEP, CITEALT, CITEALP, CITEAUTHOR }; @@ -471,61 +455,61 @@ unsigned int const nCiteStylesUCase = } // namespace anon -CitationStyle::CitationStyle(string const & command) - : style(CITE), full(false), forceUCase(false) +CitationStyle citationStyleFromString(string const & command) { + CitationStyle s; if (command.empty()) - return; + return s; string cmd = command; if (cmd[0] == 'C') { - forceUCase = true; + s.forceUpperCase = true; cmd[0] = 'c'; } - string::size_type const n = cmd.size() - 1; + size_t const n = cmd.size() - 1; if (cmd != "cite" && cmd[n] == '*') { - full = true; + s.full = true; cmd = cmd.substr(0,n); } char const * const * const last = citeCommands + nCiteCommands; - char const * const * const ptr = std::find(citeCommands, last, cmd); + char const * const * const ptr = find(citeCommands, last, cmd); if (ptr != last) { size_t idx = ptr - citeCommands; - style = citeStyles[idx]; + s.style = citeStylesArray[idx]; } + return s; } -string const CitationStyle::asLatexStr() const +string citationStyleToString(const CitationStyle & s) { - string cite = citeCommands[style]; - if (full) { + string cite = citeCommands[s.style]; + if (s.full) { CiteStyle const * last = citeStylesFull + nCiteStylesFull; - if (std::find(citeStylesFull, last, style) != last) + if (find(citeStylesFull, last, s.style) != last) cite += '*'; } - if (forceUCase) { + if (s.forceUpperCase) { CiteStyle const * last = citeStylesUCase + nCiteStylesUCase; - if (std::find(citeStylesUCase, last, style) != last) + if (find(citeStylesUCase, last, s.style) != last) cite[0] = 'C'; } return cite; } - -vector const getCiteStyles(CiteEngine const engine) +vector citeStyles(CiteEngine engine) { unsigned int nStyles = 0; unsigned int start = 0; switch (engine) { case ENGINE_BASIC: - nStyles = 1; + nStyles = 2; start = 0; break; case ENGINE_NATBIB_AUTHORYEAR: @@ -539,17 +523,14 @@ vector const getCiteStyles(CiteEngine const engine) break; } - typedef vector cite_vec; - - cite_vec styles(nStyles); + vector styles(nStyles); size_t i = 0; int j = start; for (; i != styles.size(); ++i, ++j) - styles[i] = citeStyles[j]; + styles[i] = citeStylesArray[j]; return styles; } -} // namespace biblio } // namespace lyx