/* This file is part of
- * ======================================================
- *
+ * ======================================================
+ *
* LyX, The Document Processor
- *
+ *
* Copyright 1995 Matthias Ettrich
* Copyright 1995-2001 The LyX Team.
*
#pragma implementation
#endif
+#include "LString.h"
+#include "lstrings.h"
+#include "LAssert.h"
+#include "debug.h"
+
+#include <boost/regex.hpp>
+
#include <algorithm>
#include <cctype>
#include <cstdlib>
-#include "LString.h"
-#include "lstrings.h"
-#include "LRegex.h"
-#include "LAssert.h"
-
using std::count;
using std::transform;
+using std::vector;
#ifndef CXX_GLOBAL_CSTD
+using std::atof;
+using std::isdigit;
+using std::strlen;
using std::tolower;
using std::toupper;
-using std::strlen;
#endif
bool isStrInt(string const & str)
{
if (str.empty()) return false;
-
+
// Remove leading and trailing white space chars.
string const tmpstr = frontStrip(strip(str, ' '), ' ');
if (tmpstr.empty()) return false;
-
+
string::const_iterator cit = tmpstr.begin();
if ((*cit) == '-') ++cit;
string::const_iterator end = tmpstr.end();
bool isStrUnsignedInt(string const & str)
{
if (str.empty()) return false;
-
+
// Remove leading and trailing white space chars.
string const tmpstr = frontStrip(strip(str, ' '), ' ');
if (tmpstr.empty()) return false;
-
+
string::const_iterator cit = tmpstr.begin();
string::const_iterator end = tmpstr.end();
for (; cit != end; ++cit) {
bool isStrDbl(string const & str)
{
if (str.empty()) return false;
-
+
// Remove leading and trailing white space chars.
string const tmpstr = frontStrip(strip(str, ' '), ' ');
if (tmpstr.empty()) return false;
}
-char lowercase(char c)
-{
- return char( tolower(c) );
+char lowercase(char c)
+{
+ return char(tolower(c));
}
-char uppercase(char c)
-{
- return char( toupper(c) );
+char uppercase(char c)
+{
+ return char(toupper(c));
}
return tolower(c);
}
};
-
+
struct local_uppercase {
char operator()(char c) const {
return toupper(c);
bool prefixIs(string const & a, char const * pre)
{
lyx::Assert(pre);
-
+
size_t const l = strlen(pre);
string::size_type const alen = a.length();
-
+
if (l > alen || a.empty())
return false;
else {
{
string::size_type const prelen = pre.length();
string::size_type const alen = a.length();
-
+
if (prelen > alen || a.empty())
return false;
else {
bool suffixIs(string const & a, char const * suf)
{
lyx::Assert(suf);
-
+
size_t const suflen = strlen(suf);
string::size_type const alen = a.length();
-
+
if (suflen > alen)
return false;
else {
{
string::size_type const suflen = suf.length();
string::size_type const alen = a.length();
-
+
if (suflen > alen) {
return false;
} else {
bool containsOnly(string const & s, char const * cset)
{
lyx::Assert(cset);
-
+
return s.find_first_not_of(cset) == string::npos;
}
bool containsOnly(char const * s, char const * cset)
{
lyx::Assert(s && cset);
-
+
return string(s).find_first_not_of(cset) == string::npos;
}
bool containsOnly(char const * s, string const & cset)
{
lyx::Assert(s);
-
+
return string(s).find_first_not_of(cset) == string::npos;
}
string const token(string const & a, char delim, int n)
{
if (a.empty()) return string();
-
+
string::size_type k = 0;
string::size_type i = 0;
string regex(pattern);
regex = subst(regex, ".", "\\.");
regex = subst(regex, "*", ".*");
- LRegex reg(regex);
- return reg.exact_match(a);
+ boost::regex reg(regex);
+ return boost::regex_match(a, reg);
}
char const * oldstr, string const & newstr)
{
lyx::Assert(oldstr);
-
+
string lstr(a);
string::size_type i = 0;
string::size_type olen = strlen(oldstr);
string tmp(a);
string::size_type i = tmp.find_last_not_of(c);
if (i == a.length() - 1) return tmp; // no c's at end of a
- if (i != string::npos)
+ if (i != string::npos)
tmp.erase(i + 1, string::npos);
#if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
/// Needed for broken string::find_last_not_of
string const frontStrip(string const & a, char const * p)
{
lyx::Assert(p);
-
+
if (a.empty() || !*p) return a;
string tmp(a);
string::size_type i = tmp.find_first_not_of(p);
}
return enc;
}
+
+
+/// gives a vector of stringparts which have the delimiter delim
+vector<string> const getVectorFromString(string const & str,
+ string const & delim)
+{
+ vector<string> vec;
+ if (str.empty())
+ return vec;
+ string keys(strip(str));
+ for(;;) {
+ string::size_type const idx = keys.find(delim);
+ if (idx == string::npos) {
+ vec.push_back(frontStrip(keys));
+ break;
+ }
+ string const key = strip(frontStrip(keys.substr(0, idx)));
+ if (!key.empty())
+ vec.push_back(key);
+ string::size_type const start = idx + delim.size();
+ keys = keys.substr(start);
+ }
+ return vec;
+}
+
+// the same vice versa
+string const getStringFromVector(vector<string> const & vec,
+ string const & delim)
+{
+ string str;
+ int i = 0;
+ for (vector<string>::const_iterator it = vec.begin();
+ it != vec.end(); ++it) {
+ string item = strip(frontStrip(*it));
+ if (item.empty()) continue;
+
+ if (i++ > 0) str += delim;
+ str += item;
+ }
+ return str;
+}