commit 9f56f97d8eb192d00a07fec6b1300c96f0efa022
Author: Richard Heck <[email protected]>
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.
---
src/insets/InsetCitation.cpp | 7 +++++--
src/support/lstrings.cpp | 20 ++++++++++----------
src/support/lstrings.h | 9 ++++++---
3 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp
index 8571a28..366cbc6 100644
--- a/src/insets/InsetCitation.cpp
+++ b/src/insets/InsetCitation.cpp
@@ -384,9 +384,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()
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,