* src/support/lstrings.{cpp,h}:
- new optional param "bool keepemtpy" in getVectorFromString.
By default, empty content between two delimiters was/is not added to the vector.
This can be changed with this bool.
* src/insets/InsetIndex.cpp:
- care for the case when plaintext returns nothing (e.g when ERT is used)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25616
a592a061-630c-0410-9148-
cb99ea01b6c8
odocstringstream ods2;
InsetText::plaintext(ods2, runparams);
std::vector<docstring> const levels =
- getVectorFromString(ods.str(), from_ascii("!"));
+ getVectorFromString(ods.str(), from_ascii("!"), true);
std::vector<docstring> const levels_plain =
- getVectorFromString(ods2.str(), from_ascii("!"));
+ getVectorFromString(ods2.str(), from_ascii("!"), true);
vector<docstring>::const_iterator it = levels.begin();
vector<docstring>::const_iterator end = levels.end();
vector<docstring>::const_iterator it2 = levels_plain.begin();
// 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;
namespace {
template<typename String> vector<String> 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
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);
vector<string> const getVectorFromString(string const & str,
- string const & delim)
+ string const & delim,
+ bool keepempty)
{
- return getVectorFromStringT<string>(str, delim);
+ return getVectorFromStringT<string>(str, delim, keepempty);
}
vector<docstring> const getVectorFromString(docstring const & str,
- docstring const & delim)
+ docstring const & delim,
+ bool keepempty)
{
- return getVectorFromStringT<docstring>(str, delim);
+ return getVectorFromStringT<docstring>(str, delim, keepempty);
}
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<std::string> const getVectorFromString(std::string const & str,
- std::string const & delim = std::string(","));
+ std::string const & delim = std::string(","),
+ bool keepempty = false);
std::vector<docstring> 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<std::string> const & vec,