]> git.lyx.org Git - lyx.git/commitdiff
Fix bug 5040:
authorJürgen Spitzmüller <spitz@lyx.org>
Mon, 14 Jul 2008 16:09:59 +0000 (16:09 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Mon, 14 Jul 2008 16:09:59 +0000 (16:09 +0000)
* 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

src/insets/InsetIndex.cpp
src/support/lstrings.cpp
src/support/lstrings.h

index 94d2a961bc2f62adc4759d520c240b41aa698e54..11c3a26fd083cdc63beecc73c2ff47ad18cbb9bd 100644 (file)
@@ -54,9 +54,9 @@ int InsetIndex::latex(odocstream & os,
        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();
@@ -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;
index 32629481b135cc20b278f64a5fab233a0feb6e1e..6792cf6bcd33d8ec512814f8c380d25bee9a822a 100644 (file)
@@ -913,7 +913,7 @@ docstring const escape(docstring const & lab)
 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
@@ -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<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);
 }
 
 
index c9bc75a9a7779e62b0c2604e4ccb12f70175f59f..01f72383ae8a2c9eacdd0adb8ad89dded7f97770 100644 (file)
@@ -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<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,