]> git.lyx.org Git - lyx.git/blobdiff - src/BiblioInfo.cpp
Embedding: saving inzip name to .lyx file so that embedded files can always be found...
[lyx.git] / src / BiblioInfo.cpp
index 6f6f3ee68a3706b03cea50163f1b7b051104db9f..9f00a3753d53fbe3b9b5d80b7914dd69b1ce0737 100644 (file)
@@ -16,7 +16,6 @@
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "buffer_funcs.h"
-#include "gettext.h"
 #include "InsetIterator.h"
 #include "Paragraph.h"
 
 #include "insets/InsetBibtex.h"
 #include "insets/InsetInclude.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;
 
-////////////////////////////////////////
+
+//////////////////////////////////////////////////////////////////////
 //
 // BibTeXInfo
 //
-////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////
 
-BibTeXInfo::BibTeXInfo() : isBibTeX(true)
+BibTeXInfo::BibTeXInfo()
+       : isBibTeX(true)
 {}
 
        
@@ -74,33 +69,30 @@ docstring const & BibTeXInfo::getValueForField(string const & field) const
 }
 
 
-namespace {
-       docstring const familyName(docstring const & name)
-       {
-               if (name.empty())
-                       return docstring();
-
-               // 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);
-       }
-} // namespace anon
+static docstring familyName(docstring const & name)
+{
+       if (name.empty())
+               return docstring();
 
+       // 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);
+}
 
 
 docstring const BibTeXInfo::getAbbreviatedAuthor() const
@@ -116,20 +108,22 @@ docstring const BibTeXInfo::getAbbreviatedAuthor() const
                        return bibKey;
        }
 
-       //OK, we've got some names. Let's format them.
-       //Try to split the author list on " and "
+       // OK, we've got some names. Let's format them.
+       // Try to split the author list on " and "
        vector<docstring> const authors =
                getVectorFromString(author, from_ascii(" and "));
        
        if (authors.size() == 2)
                return bformat(_("%1$s and %2$s"),
                        familyName(authors[0]), familyName(authors[1]));
-       else if (authors.size() > 2)
+
+       if (authors.size() > 2)
                return bformat(_("%1$s et al."), familyName(authors[0]));
-       else  
-               return familyName(authors[0]);
+
+       return familyName(authors[0]);
 }
 
+
 docstring const BibTeXInfo::getYear() const
 {
        if (!isBibTeX) 
@@ -149,11 +143,11 @@ docstring const BibTeXInfo::getInfo() const
                return it->second;
        }
  
-       //FIXME
-       //This could be made alot better using the entryType
-       //field to customize the output based upon entry type.
+       // FIXME
+       // This could be made a lot better using the entryType
+       // field to customize the output based upon entry type.
        
-       //Search for all possible "required" fields
+       // Search for all possible "required" fields
        docstring author = getValueForField("author");
        if (author.empty())
                author = getValueForField("editor");
@@ -165,49 +159,51 @@ docstring const BibTeXInfo::getInfo() const
                docLoc = getValueForField("chapter");
                if (!docLoc.empty())
                        docLoc = from_ascii("Ch. ") + docLoc;
-       }       else 
+       }       else {
                docLoc = from_ascii("pp. ") + docLoc;
-               docstring media = getValueForField("journal");
+       }
+
+       docstring media = getValueForField("journal");
+       if (media.empty()) {
+               media = getValueForField("publisher");
                if (media.empty()) {
-                       media = getValueForField("publisher");
-                       if (media.empty()) {
-                               media = getValueForField("school");
-                               if (media.empty())
-                                       media = getValueForField("institution");
-                       }
+                       media = getValueForField("school");
+                       if (media.empty())
+                               media = getValueForField("institution");
                }
-               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();
+       }
+       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();
 }
 
 
-////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////
 //
 // BiblioInfo
 //
-////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////
 
 namespace {
-// A functor for use with std::sort, leading to case insensitive sorting
-       class compareNoCase: public std::binary_function<docstring, docstring, bool>
+// A functor for use with sort, leading to case insensitive sorting
+       class compareNoCase: public binary_function<docstring, docstring, bool>
        {
                public:
                        bool operator()(docstring const & s1, docstring const & s2) const {
@@ -223,7 +219,7 @@ vector<docstring> 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,7 +231,7 @@ vector<docstring> const BiblioInfo::getFields() const
        set<docstring>::const_iterator end = fieldNames.end();
        for (; it != end; ++it)
                bibfields.push_back(*it);
-       std::sort(bibfields.begin(), bibfields.end());
+       sort(bibfields.begin(), bibfields.end());
        return bibfields;
 }
 
@@ -247,7 +243,7 @@ vector<docstring> const BiblioInfo::getEntries() const
        set<docstring>::const_iterator end = entryTypes.end();
        for (; it != end; ++it)
                bibentries.push_back(*it);
-       std::sort(bibentries.begin(), bibentries.end());
+       sort(bibentries.begin(), bibentries.end());
        return bibentries;
 }
 
@@ -286,7 +282,8 @@ vector<docstring> const BiblioInfo::getCiteStrings(
        docstring const & key, Buffer const & buf) const
 {
        biblio::CiteEngine const engine = buf.params().getEngine();
-       if (engine == biblio::ENGINE_NATBIB_NUMERICAL)
+       if (engine == biblio::ENGINE_BASIC || 
+           engine == biblio::ENGINE_NATBIB_NUMERICAL)
                return getNumericalStrings(key, buf);
        else
                return getAuthorYearStrings(key, buf);
@@ -317,6 +314,10 @@ vector<docstring> const BiblioInfo::getNumericalStrings(
                                str = from_ascii("[#ID]");
                                break;
 
+                       case biblio::NOCITE:
+                               str = _("Add to bibliography only.");
+                               break;
+
                        case biblio::CITET:
                                str = author + " [#ID]";
                                break;
@@ -374,6 +375,10 @@ vector<docstring> const BiblioInfo::getAuthorYearStrings(
                                str = author + "/<" + _("before") + '>';
                                break;
 
+                       case biblio::NOCITE:
+                               str = _("Add to bibliography only.");
+                               break;
+
                        case biblio::CITET:
                                str = author + " (" + year + ')';
                                break;
@@ -429,25 +434,25 @@ void BiblioInfo::fillWithBibKeys(Buffer const * const buf)
 
 namespace biblio {
 
-////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////
 //
 // CitationStyle
 //
-////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////
 
 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 };
+       CITE, NOCITE, CITET, CITEP, CITEALT,
+CITEALP, CITEAUTHOR, CITEYEAR, CITEYEARPAR };
 
 unsigned int const nCiteStyles =
                sizeof(citeStyles) / sizeof(CiteStyle);
@@ -486,7 +491,7 @@ CitationStyle::CitationStyle(string const & command)
        }
 
        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;
@@ -500,13 +505,13 @@ string const CitationStyle::asLatexStr() const
        string cite = citeCommands[style];
        if (full) {
                CiteStyle const * last = citeStylesFull + nCiteStylesFull;
-               if (std::find(citeStylesFull, last, style) != last)
+               if (find(citeStylesFull, last, style) != last)
                        cite += '*';
        }
 
        if (forceUCase) {
                CiteStyle const * last = citeStylesUCase + nCiteStylesUCase;
-               if (std::find(citeStylesUCase, last, style) != last)
+               if (find(citeStylesUCase, last, style) != last)
                        cite[0] = 'C';
        }
 
@@ -521,7 +526,7 @@ vector<CiteStyle> const getCiteStyles(CiteEngine const engine)
 
        switch (engine) {
                case ENGINE_BASIC:
-                       nStyles = 1;
+                       nStyles = 2;
                        start = 0;
                        break;
                case ENGINE_NATBIB_AUTHORYEAR:
@@ -538,7 +543,7 @@ vector<CiteStyle> const getCiteStyles(CiteEngine const engine)
        typedef vector<CiteStyle> cite_vec;
 
        cite_vec styles(nStyles);
-       cite_vec::size_type i = 0;
+       size_t i = 0;
        int j = start;
        for (; i != styles.size(); ++i, ++j)
                styles[i] = citeStyles[j];