]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetBibtex.cpp
Typo
[features.git] / src / insets / InsetBibtex.cpp
index 95c93a15b8d80f499764a3d718f98efec2d2fac9..a9c0ff966b51e3c33c8b7803f4757e7ca417da23 100644 (file)
@@ -4,7 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Alejandro Aguilar Sierra
- * \author Richard Heck (BibTeX parser improvements)
+ * \author Richard Kimberly Heck (BibTeX parser improvements)
  * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
@@ -28,7 +28,6 @@
 #include "LaTeXFeatures.h"
 #include "output_latex.h"
 #include "xml.h"
-#include "OutputParams.h"
 #include "PDFOptions.h"
 #include "texstream.h"
 #include "TextClass.h"
@@ -43,7 +42,6 @@
 #include "support/ExceptionMessage.h"
 #include "support/FileNameList.h"
 #include "support/filetools.h"
-#include "support/regex.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
 #include "support/os.h"
@@ -52,6 +50,7 @@
 
 #include <limits>
 #include <map>
+#include <regex>
 #include <utility>
 
 #include <iostream>
@@ -310,6 +309,7 @@ void InsetBibtex::latex(otexstream & os, OutputParams const & runparams) const
                vector<pair<docstring, string>> const dbs =
                        buffer().prepareBibFilePaths(runparams, getBibFiles(), false);
                vector<docstring> db_out;
+               db_out.reserve(dbs.size());
                for (pair<docstring, string> const & db : dbs)
                        db_out.push_back(db.first);
                // Style options
@@ -906,7 +906,7 @@ void InsetBibtex::validate(LaTeXFeatures & features) const
        // FIXME XHTML
        // It'd be better to be able to get this from an InsetLayout, but at present
        // InsetLayouts do not seem really to work for things that aren't InsetTexts.
-       if (features.runparams().flavor == OutputParams::HTML)
+       if (features.runparams().flavor == Flavor::Html)
                features.addCSSSnippet("div.bibtexentry { margin-left: 2em; text-indent: -2em; }\n"
                        "span.bibtexlabel:before{ content: \"[\"; }\n"
                        "span.bibtexlabel:after{ content: \"] \"; }");
@@ -983,7 +983,7 @@ int InsetBibtex::plaintext(odocstringstream & os,
        // We could output more information here, e.g., what databases are included
        // and information about options. But I don't necessarily see any reason to
        // do this right now.
-       if (op.for_tooltip || op.for_toc || op.for_search) {
+       if (op.for_tooltip || op.for_toc || op.find_effective()) {
                os << '[' << reflabel << ']' << '\n';
                return PLAINTEXT_NEWLINE;
        }
@@ -1088,6 +1088,13 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
 
        docstring const reflabel = buffer().B_("References");
 
+       // Check that the bibliography is not empty, to ensure that the document is valid.
+       if (cites.empty()) {
+               xs << XMLStream::ESCAPE_NONE << "<!-- The bibliography is empty! -->";
+               xs << xml::CR();
+               return;
+       }
+
        // Tell BiblioInfo our purpose (i.e. generate HTML rich text).
        CiteItem ci;
        ci.context = CiteItem::Export;
@@ -1099,7 +1106,8 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
        xs << xml::CR();
        xs << xml::StartTag("title");
        xs << reflabel;
-       xs << xml::EndTag("title") << xml::CR();
+       xs << xml::EndTag("title");
+       xs << xml::CR();
 
        // Translation between keys in each entry and DocBook tags.
        // IDs for publications; list: http://tdg.docbook.org/tdg/5.2/biblioid.html.
@@ -1155,12 +1163,8 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
        auto vit = cites.begin();
        auto ven = cites.end();
 
-       if (vit == ven) {
-               xs << XMLStream::ESCAPE_NONE << "<!-- No entry in the bibliography. -->";
-       }
-
        for (; vit != ven; ++vit) {
-               BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
+               auto const biit = bibinfo.find(*vit);
                if (biit == bibinfo.end())
                        continue;
 
@@ -1183,8 +1187,8 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
                string html = to_utf8(bibinfo.getInfo(entry.key(), buffer(), ci));
                regex tagRegex("<span class=\"bib-([^\"]*)\">([^<]*)</span>");
                smatch match;
-               auto tagIt = std::sregex_iterator(html.cbegin(), html.cend(), tagRegex, regex_constants::match_default);
-               auto tagEnd = std::sregex_iterator();
+               auto tagIt = sregex_iterator(html.cbegin(), html.cend(), tagRegex, regex_constants::match_default);
+               auto tagEnd = sregex_iterator();
                map<string, string> delayedTags;
 
                // Read all tags from HTML and convert those that have a 1:1 matching.
@@ -1199,6 +1203,7 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
                                        xs << xml::StartTag(toDocBookTag[match[1]]);
                                        xs << from_utf8(match[2].str());
                                        xs << xml::EndTag(toDocBookTag[match[1]]);
+                                       xs << xml::CR();
                                }
                        } else {
                                LYXERR0("The BibTeX field " << match[1].str() << " is unknown.");
@@ -1216,9 +1221,9 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
                if (! delayedTags.empty()) {
                        unsigned long remainingTags = delayedTags.size(); // Used as a workaround. With GCC 7, when erasing all
                        // elements one by one, some elements may still pop in later on (even though they were deleted previously).
-                       auto hasTag = [&delayedTags](string key) { return delayedTags.find(key) != delayedTags.end(); };
-                       auto getTag = [&delayedTags](string key) { return from_utf8(delayedTags[key]); };
-                       auto eraseTag = [&delayedTags, &remainingTags](string key) {
+                       auto hasTag = [&delayedTags](const string & key) { return delayedTags.find(key) != delayedTags.end(); };
+                       auto getTag = [&delayedTags](const string & key) { return from_utf8(delayedTags[key]); };
+                       auto eraseTag = [&delayedTags, &remainingTags](const string & key) {
                                remainingTags -= 1;
                                delayedTags.erase(key);
                        };
@@ -1274,7 +1279,7 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
                                xs << xml::StartTag("keywordset") << xml::CR();
                                for (auto & kw: keywords) {
                                        kw.erase(kw.begin(), std::find_if(kw.begin(), kw.end(),
-                                                                         [](int c) {return !std::isspace(c);}));
+                                                                         [](char_type c) {return !lyx::isSpace(c);}));
                                        xs << xml::StartTag("keyword");
                                        xs << kw;
                                        xs << xml::EndTag("keyword");
@@ -1410,6 +1415,7 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
 
        // Footer for bibliography.
        xs << xml::EndTag("bibliography");
+       xs << xml::CR();
 }