]> git.lyx.org Git - lyx.git/blobdiff - src/support/lstrings.cpp
Fix layout bug. Pasting text into a cell tried to set Standard layout, because
[lyx.git] / src / support / lstrings.cpp
index c8fc921da3f224152b11349cb5a8446527d7120d..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>
@@ -60,45 +60,6 @@ static inline char_type qchar_to_ucs4(QChar const & qchar)
 }
 
 
-
-QString toqstr(char const * str)
-{
-       return QString::fromUtf8(str);
-}
-
-QString toqstr(std::string const & str)
-{
-       return toqstr(str.c_str());
-}
-
-
-QString toqstr(docstring const & ucs4)
-{
-       // If possible we let qt do the work, since this version does not
-       // need to be superfast.
-       return QString::fromUcs4((uint const *)ucs4.data(), ucs4.length());
-}
-
-QString toqstr(char_type ucs4)
-{
-       union { char_type c; uint i; } u = { ucs4 };
-       return QString::fromUcs4(&u.i, 1);
-}
-
-docstring qstring_to_ucs4(QString const & qstr)
-{
-       if (qstr.isEmpty())
-               return docstring();
-       QVector<uint> const ucs4 = qstr.toUcs4();
-       return docstring((char_type const *)(ucs4.constData()), ucs4.size());
-}
-
-std::string fromqstr(QString const & str)
-{
-       return str.isEmpty() ? std::string() : std::string(str.toUtf8());
-}
-
-
 /**
  * Convert a UCS4 character into a QChar.
  * This is a hack (it does only make sense for the common part of the UCS4
@@ -534,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;
 }
 
@@ -555,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;
@@ -952,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
@@ -969,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);
@@ -988,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);
 }