commit 955199fe8ce9d9ddce6256be1a9749753de32555
Author: Richard Heck <rgh...@lyx.org>
Date:   Wed Oct 18 12:26:35 2017 -0400

    Fix bug #9847.
    
    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 |   10 ++++++----
 src/support/lstrings.cpp     |   20 ++++++++++----------
 src/support/lstrings.h       |    9 ++++++---
 status.23x                   |    2 ++
 4 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp
index 1d079c2..2444126 100644
--- a/src/insets/InsetCitation.cpp
+++ b/src/insets/InsetCitation.cpp
@@ -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);
diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp
index 02ecbe1..be326c0 100644
--- a/src/support/lstrings.cpp
+++ b/src/support/lstrings.cpp
@@ -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);
 }
 
 
diff --git a/src/support/lstrings.h b/src/support/lstrings.h
index 49f4da7..398bf8d 100644
--- a/src/support/lstrings.h
+++ b/src/support/lstrings.h
@@ -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,
diff --git a/status.23x b/status.23x
index 9e76c76..5b75dfb 100644
--- a/status.23x
+++ b/status.23x
@@ -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
 

Reply via email to