]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/biblio.C
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / biblio.C
index 7e92ed61c909e825a618288796fbff6f8271dc58..32d4f8af3610f172bc9b250fe5d6afe14d716add 100644 (file)
 #include "gettext.h"
 
 #include "support/lstrings.h"
-#include "support/std_sstream.h"
 
 #include <boost/regex.hpp>
 
 #include <algorithm>
-
-using lyx::support::ascii_lowercase;
-using lyx::support::bformat;
-using lyx::support::compare_ascii_no_case;
-using lyx::support::contains;
-using lyx::support::getVectorFromString;
-using lyx::support::ltrim;
-using lyx::support::prefixIs;
-using lyx::support::rtrim;
-using lyx::support::split;
-using lyx::support::subst;
-using lyx::support::token;
-using lyx::support::trim;
+#include <sstream>
 
 using std::string;
 using std::ostringstream;
 using std::vector;
 
 
+namespace lyx {
+
+using support::ascii_lowercase;
+using support::bformat;
+using support::compare_ascii_no_case;
+using support::contains;
+using support::getVectorFromString;
+using support::ltrim;
+using support::prefixIs;
+using support::rtrim;
+using support::split;
+using support::subst;
+using support::token;
+using support::trim;
+
 namespace biblio {
 
 namespace {
@@ -139,9 +141,9 @@ string const asValidLatexCommand(string const & input,
                        output = input;
 
                // Jurabib does not support the 'full' natbib style.
-                string::size_type const n = output.size() - 1;
-                if (output != "cite*" && output[n] == '*')
-                        output = output.substr(0, n);
+               string::size_type const n = output.size() - 1;
+               if (output != "cite*" && output[n] == '*')
+                       output = output.substr(0, n);
 
                break;
        }
@@ -267,8 +269,9 @@ string const getYear(InfoMap const & map, string const & key)
 namespace {
 
 // A functor for use with std::sort, leading to case insensitive sorting
-struct compareNoCase: public std::binary_function<string, string, bool>
+class compareNoCase: public std::binary_function<string, string, bool>
 {
+public:
        bool operator()(string const & s1, string const & s2) const {
                return compare_ascii_no_case(s1, s2) < 0;
        }
@@ -321,6 +324,7 @@ string const getInfo(InfoMap const & map, string const & key)
        string number     = parseBibTeX(data, "number");
        string volume     = parseBibTeX(data, "volume");
        string pages      = parseBibTeX(data, "pages");
+       string annote     = parseBibTeX(data, "annote");
 
        string media      = parseBibTeX(data, "journal");
        if (media.empty())
@@ -349,6 +353,8 @@ string const getInfo(InfoMap const & map, string const & key)
                result << ", pp. " << pages;
        if (!year.empty())
                result << ", " << year;
+       if (!annote.empty())
+               result << "\n\n" << annote;
 
        string const result_str = rtrim(result.str());
        if (!result_str.empty())
@@ -382,8 +388,9 @@ string const escape_special_chars(string const & expr)
 
 // A functor for use with std::find_if, used to ascertain whether a
 // data entry matches the required regex_
-struct RegexMatch : public std::unary_function<string, bool>
+class RegexMatch : public std::unary_function<string, bool>
 {
+public:
        // re and icase are used to construct an instance of boost::RegEx.
        // if icase is true, then matching is insensitive to case
        RegexMatch(InfoMap const & m, string const & re, bool icase)
@@ -476,7 +483,11 @@ string const parseBibTeX(string data, string const & findkey)
                string::size_type const idx =
                        dummy.empty() ? string::npos : dummy.find('%');
                if (idx != string::npos)
-                       dummy.erase(idx, string::npos);
+                       // Check if this is really a comment or just "\%"
+                       if (idx == 0 || dummy[idx - 1] != '\\')
+                               dummy.erase(idx, string::npos);
+                       else  //  This is "\%", so just erase the '\'
+                               dummy.erase(idx - 1, 1);
                // do we have a new token or a new line of
                // the same one? In the first case we ignore
                // the \n and in the second we replace it
@@ -822,3 +833,4 @@ getAuthorYearStrings(string const & key,
 }
 
 } // namespace biblio
+} // namespace lyx