]> git.lyx.org Git - features.git/commitdiff
Fix bug #9847.
authorRichard Heck <rgheck@lyx.org>
Wed, 18 Oct 2017 16:26:35 +0000 (12:26 -0400)
committerRichard Heck <rikiheck@lyx.org>
Tue, 17 Apr 2018 03:19:21 +0000 (23:19 -0400)
Spaces are, amazingly, allowed at the end of bibliography keys. So we
introduce a new parameter allowing getVectorFromString not to trim
whitespace, and then use it.

For some reason, this seems not actually to have been backported
to 2.3.x.

src/insets/InsetCitation.cpp
src/support/lstrings.cpp
src/support/lstrings.h
status.23x

index 1d079c26cd1487bddcadeefa718e46584776fbae..24441268984d2525395e8a913f08ab108faad25c 100644 (file)
@@ -389,9 +389,12 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
        buffer().params().documentClass().addCiteMacro("!textafter", to_utf8(after));
        */
        docstring label;
-       vector<docstring> keys = getVectorFromString(key);
+       // we only really want the last 'false', to suppress trimming, but
+       // we need to give the other defaults, too, to set it.
+       vector<docstring> keys =
+               getVectorFromString(key, from_ascii(","), false, false);
        CitationStyle cs = getCitationStyle(buffer().masterParams(),
-                                           cite_type, buffer().masterParams().citeStyles());
+                       cite_type, buffer().masterParams().citeStyles());
        bool const qualified = cs.hasQualifiedList
                && (keys.size() > 1
                    || !getParam("pretextlist").empty()
@@ -427,8 +430,7 @@ docstring InsetCitation::basicLabel(bool for_xhtml) const
        do {
                // if there is no comma, then everything goes into key
                // and keys will be empty.
-               keys = trim(split(keys, key, ','));
-               key = trim(key);
+               keys = split(keys, key, ',');
                if (!label.empty())
                        label += ", ";
                label += wrapCitation(key, key, for_xhtml);
index 02ecbe1d9e9d93eb5ce36b7891195c0d27a7cc79..be326c0fd46dea68b7b229130b488fe9f3518fd3 100644 (file)
@@ -1317,7 +1317,8 @@ docstring wrapParas(docstring const & str, int const indent,
 namespace {
 
 template<typename String> vector<String> const
-getVectorFromStringT(String const & str, String const & delim, bool keepempty)
+getVectorFromStringT(String const & str, String const & delim,
+                     bool keepempty, bool trimit)
 {
 // Lars would like this code to go, but for now his replacement (below)
 // doesn't fullfil the same function. I have, therefore, reactivated the
@@ -1326,14 +1327,15 @@ getVectorFromStringT(String const & str, String const & delim, bool keepempty)
        vector<String> vec;
        if (str.empty())
                return vec;
-       String keys = rtrim(str);
+       String keys = trimit ? rtrim(str) : str;
        while (true) {
                size_t const idx = keys.find(delim);
                if (idx == String::npos) {
-                       vec.push_back(ltrim(keys));
+                       vec.push_back(trimit ? ltrim(keys) : keys);
                        break;
                }
-               String const key = trim(keys.substr(0, idx));
+               String const key = trimit ?
+                       trim(keys.substr(0, idx)) : keys.substr(0, idx);
                if (!key.empty() || keepempty)
                        vec.push_back(key);
                size_t const start = idx + delim.size();
@@ -1371,18 +1373,16 @@ template<typename String> const String
 
 
 vector<string> const getVectorFromString(string const & str,
-                                        string const & delim,
-                                        bool keepempty)
+        string const & delim, bool keepempty, bool trimit)
 {
-       return getVectorFromStringT<string>(str, delim, keepempty);
+       return getVectorFromStringT<string>(str, delim, keepempty, trimit);
 }
 
 
 vector<docstring> const getVectorFromString(docstring const & str,
-                                           docstring const & delim,
-                                           bool keepempty)
+        docstring const & delim, bool keepempty, bool trimit)
 {
-       return getVectorFromStringT<docstring>(str, delim, keepempty);
+       return getVectorFromStringT<docstring>(str, delim, keepempty, trimit);
 }
 
 
index 49f4da7b8086cdc97bccd5914cf69f0a58e7873b..398bf8dd337ae1a1ff0adced2343b4a04114a81c 100644 (file)
@@ -324,11 +324,14 @@ docstring wrapParas(docstring const & str, int const indent = 0,
 
 /// gives a vector of stringparts which have the delimiter delim
 /// If \p keepempty is true, empty strings will be pushed to the vector as well
+/// If \p trimit is true, leading and trailing whitespace will be trimmed from
+/// all values. Note that this can affect what counts as "empty".
 std::vector<std::string> const getVectorFromString(std::string const & str,
-                                             std::string const & delim = std::string(","),
-                                             bool keepempty = false);
+        std::string const & delim = std::string(","),
+        bool keepempty = false, bool trimit = true);
 std::vector<docstring> const getVectorFromString(docstring const & str,
-               docstring const & delim = from_ascii(","), bool keepempty = false);
+        docstring const & delim = from_ascii(","),
+        bool keepempty = false, bool trimit = true);
 
 /// the same vice versa
 std::string const getStringFromVector(std::vector<std::string> const & vec,
index 9e76c76cba8953e319de5a14ca3f877bb45e57fe..5b75dfb9ab1a0c3013c836564b50fa50e9d35996 100644 (file)
@@ -201,6 +201,8 @@ What's new
 - Recalculate citation insets when bibliography info changes as a result
   of undo or redo (bug 11005).
 
+- Allow for spaces in bibliography keys (bug 9847).
+
 
 * INTERNALS