diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index 94d2a961bc..11c3a26fd0 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -54,9 +54,9 @@ int InsetIndex::latex(odocstream & os, odocstringstream ods2; InsetText::plaintext(ods2, runparams); std::vector const levels = - getVectorFromString(ods.str(), from_ascii("!")); + getVectorFromString(ods.str(), from_ascii("!"), true); std::vector const levels_plain = - getVectorFromString(ods2.str(), from_ascii("!")); + getVectorFromString(ods2.str(), from_ascii("!"), true); vector::const_iterator it = levels.begin(); vector::const_iterator end = levels.end(); vector::const_iterator it2 = levels_plain.begin(); @@ -71,9 +71,13 @@ int InsetIndex::latex(odocstream & os, // e.g. \index{LyX@\LyX}, \index{text@\textbf{text}} // Don't do that if the user entered '@' himself, though. if (contains(*it, '\\') && !contains(*it, '@')) { + // Plaintext might return nothing (e.g. for ERTs) + docstring spart = + (it2 < levels_plain.end() + && !(*it2).empty()) ? *it2 : *it; // remove remaining \'s for the sorting part docstring const ppart = - subst(*it2, from_ascii("\\"), docstring()); + subst(spart, from_ascii("\\"), docstring()); os << ppart; os << '@'; i += ppart.size() + 1; diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp index 32629481b1..6792cf6bcd 100644 --- a/src/support/lstrings.cpp +++ b/src/support/lstrings.cpp @@ -913,7 +913,7 @@ docstring const escape(docstring const & lab) namespace { template vector const -getVectorFromStringT(String const & str, String const & delim) +getVectorFromStringT(String const & str, String const & delim, bool keepempty) { // Lars would like this code to go, but for now his replacement (below) // doesn't fullfil the same function. I have, therefore, reactivated the @@ -930,7 +930,7 @@ getVectorFromStringT(String const & str, String const & delim) break; } String const key = trim(keys.substr(0, idx)); - if (!key.empty()) + if (!key.empty() || keepempty) vec.push_back(key); size_t const start = idx + delim.size(); keys = keys.substr(start); @@ -949,16 +949,18 @@ getVectorFromStringT(String const & str, String const & delim) vector const getVectorFromString(string const & str, - string const & delim) + string const & delim, + bool keepempty) { - return getVectorFromStringT(str, delim); + return getVectorFromStringT(str, delim, keepempty); } vector const getVectorFromString(docstring const & str, - docstring const & delim) + docstring const & delim, + bool keepempty) { - return getVectorFromStringT(str, delim); + return getVectorFromStringT(str, delim, keepempty); } diff --git a/src/support/lstrings.h b/src/support/lstrings.h index c9bc75a9a7..01f72383ae 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -225,10 +225,12 @@ std::string const rsplit(std::string const & a, std::string & piece, char delim) docstring const escape(docstring const & lab); /// 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 std::vector const getVectorFromString(std::string const & str, - std::string const & delim = std::string(",")); + std::string const & delim = std::string(","), + bool keepempty = false); std::vector const getVectorFromString(docstring const & str, - docstring const & delim = from_ascii(",")); + docstring const & delim = from_ascii(","), bool keepempty = false); // the same vice versa std::string const getStringFromVector(std::vector const & vec,