]> git.lyx.org Git - features.git/blobdiff - src/support/lstrings.cpp
Fix for bug 5053. There are still some serious problems here, though, as (a) "unknown...
[features.git] / src / support / lstrings.cpp
index bab226f1bf572d9f7ccf35fca3cdd1ddf1744af8..2bd5f4ea95c606954ca82639b5a3be6726947906 100644 (file)
@@ -19,7 +19,7 @@
 #include "support/textutils.h"
 
 #include <boost/tokenizer.hpp>
-#include "support/assert.h"
+#include "support/lassert.h"
 
 #include <QString>
 #include <QVector>
@@ -495,7 +495,8 @@ bool prefixIs(docstring const & a, docstring const & pre)
 
 bool suffixIs(string const & a, char c)
 {
-       if (a.empty()) return false;
+       if (a.empty()) 
+               return false;
        return a[a.length() - 1] == c;
 }
 
@@ -516,6 +517,14 @@ bool suffixIs(string const & a, string const & suf)
 }
 
 
+bool suffixIs(docstring const & a, docstring const & suf)
+{
+       size_t const suflen = suf.length();
+       size_t const alen = a.length();
+       return suflen <= alen && a.compare(alen - suflen, suflen, suf) == 0;
+}
+
+
 bool containsOnly(string const & s, string const & cset)
 {
        return s.find_first_not_of(cset) == string::npos;
@@ -913,7 +922,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 +939,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 +958,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);
 }