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.
This commit is contained in:
Richard Heck 2017-10-18 12:26:35 -04:00 committed by Richard Heck
parent 03b5a0800a
commit 955199fe8c
4 changed files with 24 additions and 17 deletions

View 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);

View 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);
}

View 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,

View 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