*
* \author Lars Gullik Bjønnes
* \author Jean-Marc Lasgouttes
+ * \author Dekel Tsur
*
* Full author contact details are available in file CREDITS.
*/
#include "support/textutils.h"
#include <boost/tokenizer.hpp>
-#include "support/assert.h"
+#include "support/lassert.h"
+
+#include <QString>
+#include <QVector>
#include <algorithm>
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;
}
+// this could probably be faster and/or cleaner, but it seems to work (JMarc)
+// rewritten to use new string (Lgb)
+int tokenPos(docstring const & a, char_type delim, docstring const & tok)
+{
+ int i = 0;
+ docstring str = a;
+ docstring tmptok;
+
+ while (!str.empty()) {
+ str = split(str, tmptok, delim);
+ if (tok == tmptok)
+ return i;
+ ++i;
+ }
+ return -1;
+}
+
+
namespace {
/// Substitute all \a oldchar with \a newchar
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);
}