mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-24 05:40:59 +00:00
Fix bug 5040:
* 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
This commit is contained in:
parent
6a30544088
commit
1d0bac1144
@ -54,9 +54,9 @@ int InsetIndex::latex(odocstream & os,
|
|||||||
odocstringstream ods2;
|
odocstringstream ods2;
|
||||||
InsetText::plaintext(ods2, runparams);
|
InsetText::plaintext(ods2, runparams);
|
||||||
std::vector<docstring> const levels =
|
std::vector<docstring> const levels =
|
||||||
getVectorFromString(ods.str(), from_ascii("!"));
|
getVectorFromString(ods.str(), from_ascii("!"), true);
|
||||||
std::vector<docstring> const levels_plain =
|
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 it = levels.begin();
|
||||||
vector<docstring>::const_iterator end = levels.end();
|
vector<docstring>::const_iterator end = levels.end();
|
||||||
vector<docstring>::const_iterator it2 = levels_plain.begin();
|
vector<docstring>::const_iterator it2 = levels_plain.begin();
|
||||||
@ -71,9 +71,13 @@ int InsetIndex::latex(odocstream & os,
|
|||||||
// e.g. \index{LyX@\LyX}, \index{text@\textbf{text}}
|
// e.g. \index{LyX@\LyX}, \index{text@\textbf{text}}
|
||||||
// Don't do that if the user entered '@' himself, though.
|
// Don't do that if the user entered '@' himself, though.
|
||||||
if (contains(*it, '\\') && !contains(*it, '@')) {
|
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
|
// remove remaining \'s for the sorting part
|
||||||
docstring const ppart =
|
docstring const ppart =
|
||||||
subst(*it2, from_ascii("\\"), docstring());
|
subst(spart, from_ascii("\\"), docstring());
|
||||||
os << ppart;
|
os << ppart;
|
||||||
os << '@';
|
os << '@';
|
||||||
i += ppart.size() + 1;
|
i += ppart.size() + 1;
|
||||||
|
@ -913,7 +913,7 @@ docstring const escape(docstring const & lab)
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
template<typename String> vector<String> const
|
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)
|
// Lars would like this code to go, but for now his replacement (below)
|
||||||
// doesn't fullfil the same function. I have, therefore, reactivated the
|
// doesn't fullfil the same function. I have, therefore, reactivated the
|
||||||
@ -930,7 +930,7 @@ getVectorFromStringT(String const & str, String const & delim)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
String const key = trim(keys.substr(0, idx));
|
String const key = trim(keys.substr(0, idx));
|
||||||
if (!key.empty())
|
if (!key.empty() || keepempty)
|
||||||
vec.push_back(key);
|
vec.push_back(key);
|
||||||
size_t const start = idx + delim.size();
|
size_t const start = idx + delim.size();
|
||||||
keys = keys.substr(start);
|
keys = keys.substr(start);
|
||||||
@ -949,16 +949,18 @@ getVectorFromStringT(String const & str, String const & delim)
|
|||||||
|
|
||||||
|
|
||||||
vector<string> const getVectorFromString(string const & str,
|
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,
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -225,10 +225,12 @@ std::string const rsplit(std::string const & a, std::string & piece, char delim)
|
|||||||
docstring const escape(docstring const & lab);
|
docstring const escape(docstring const & lab);
|
||||||
|
|
||||||
/// gives a vector of stringparts which have the delimiter delim
|
/// 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::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,
|
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
|
// the same vice versa
|
||||||
std::string const getStringFromVector(std::vector<std::string> const & vec,
|
std::string const getStringFromVector(std::vector<std::string> const & vec,
|
||||||
|
Loading…
Reference in New Issue
Block a user