#include "support/textutils.h"
#include <boost/tokenizer.hpp>
-#include "support/assert.h"
+#include "support/lassert.h"
#include <QString>
#include <QVector>
}
-
-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
bool suffixIs(string const & a, char c)
{
- if (a.empty()) return false;
+ if (a.empty())
+ return false;
return a[a.length() - 1] == c;
}
}
+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;
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);
}