2002-09-25 10:03:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file lstrings.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 10:03:41 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 10:03:41 +00:00
|
|
|
|
*/
|
2000-07-24 13:53:19 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2004-11-07 13:22:51 +00:00
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
#include "support/lyxlib.h"
|
2005-01-06 16:39:35 +00:00
|
|
|
|
#include "support/convert.h"
|
2007-02-26 09:03:21 +00:00
|
|
|
|
#include "support/qstring_helpers.h"
|
2004-11-07 13:22:51 +00:00
|
|
|
|
|
2002-03-01 17:42:43 +00:00
|
|
|
|
#include "debug.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
2002-11-04 00:15:56 +00:00
|
|
|
|
#include <boost/tokenizer.hpp>
|
2003-10-06 09:35:38 +00:00
|
|
|
|
#include <boost/assert.hpp>
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
|
|
|
|
#ifndef I_AM_NOT_AFRAID_OF_HEADER_LIBRARIES
|
|
|
|
|
#if USE_BOOST_FORMAT
|
2004-01-06 19:32:05 +00:00
|
|
|
|
#include <boost/format.hpp>
|
2005-01-06 15:40:49 +00:00
|
|
|
|
#endif
|
|
|
|
|
#endif
|
2002-05-25 00:19:56 +00:00
|
|
|
|
|
|
|
|
|
#include <cctype>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
2004-11-07 13:22:51 +00:00
|
|
|
|
#include <algorithm>
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
|
|
|
|
|
2006-09-11 08:54:10 +00:00
|
|
|
|
|
1999-12-15 06:12:28 +00:00
|
|
|
|
using std::transform;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2002-04-15 12:05:07 +00:00
|
|
|
|
using std::vector;
|
2001-04-25 19:33:52 +00:00
|
|
|
|
|
2000-11-10 12:33:01 +00:00
|
|
|
|
#ifndef CXX_GLOBAL_CSTD
|
2002-06-10 07:57:39 +00:00
|
|
|
|
using std::isdigit;
|
2000-01-06 02:44:26 +00:00
|
|
|
|
using std::tolower;
|
|
|
|
|
using std::toupper;
|
2000-03-16 04:29:22 +00:00
|
|
|
|
#endif
|
2000-09-26 13:54:57 +00:00
|
|
|
|
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace support {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
|
2006-09-09 22:27:22 +00:00
|
|
|
|
int compare_no_case(docstring const & s, docstring const & s2)
|
|
|
|
|
{
|
|
|
|
|
docstring::const_iterator p = s.begin();
|
|
|
|
|
docstring::const_iterator p2 = s2.begin();
|
|
|
|
|
|
|
|
|
|
while (p != s.end() && p2 != s2.end()) {
|
2006-11-13 09:53:25 +00:00
|
|
|
|
char_type const lc1 = lowercase(*p);
|
|
|
|
|
char_type const lc2 = lowercase(*p2);
|
2006-09-09 22:27:22 +00:00
|
|
|
|
if (lc1 != lc2)
|
|
|
|
|
return (lc1 < lc2) ? -1 : 1;
|
|
|
|
|
++p;
|
|
|
|
|
++p2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (s.size() == s2.size())
|
|
|
|
|
return 0;
|
|
|
|
|
if (s.size() < s2.size())
|
|
|
|
|
return -1;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
namespace {
|
2006-10-11 19:40:50 +00:00
|
|
|
|
|
2006-11-13 09:53:25 +00:00
|
|
|
|
template<typename Char>
|
|
|
|
|
Char ascii_tolower(Char c) {
|
2006-10-11 19:40:50 +00:00
|
|
|
|
if (c >= 'A' && c <= 'Z')
|
|
|
|
|
return c - 'A' + 'a';
|
|
|
|
|
return c;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-13 09:53:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
|
2006-11-13 09:53:25 +00:00
|
|
|
|
int compare_ascii_no_case(string const & s, string const & s2)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2006-11-13 09:53:25 +00:00
|
|
|
|
string::const_iterator p = s.begin();
|
|
|
|
|
string::const_iterator p2 = s2.begin();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
|
while (p != s.end() && p2 != s2.end()) {
|
|
|
|
|
int const lc1 = ascii_tolower(*p);
|
|
|
|
|
int const lc2 = ascii_tolower(*p2);
|
|
|
|
|
if (lc1 != lc2)
|
|
|
|
|
return (lc1 < lc2) ? -1 : 1;
|
|
|
|
|
++p;
|
|
|
|
|
++p2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (s.size() == s2.size())
|
1999-12-19 22:35:36 +00:00
|
|
|
|
return 0;
|
|
|
|
|
if (s.size() < s2.size())
|
|
|
|
|
return -1;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
|
2006-11-13 09:53:25 +00:00
|
|
|
|
int compare_ascii_no_case(docstring const & s, docstring const & s2)
|
2006-10-11 19:40:50 +00:00
|
|
|
|
{
|
2006-11-13 09:53:25 +00:00
|
|
|
|
docstring::const_iterator p = s.begin();
|
|
|
|
|
docstring::const_iterator p2 = s2.begin();
|
2006-10-11 19:40:50 +00:00
|
|
|
|
|
2006-11-13 09:53:25 +00:00
|
|
|
|
while (p != s.end() && p2 != s2.end()) {
|
|
|
|
|
char_type const lc1 = ascii_tolower(*p);
|
|
|
|
|
char_type const lc2 = ascii_tolower(*p2);
|
|
|
|
|
if (lc1 != lc2)
|
|
|
|
|
return (lc1 < lc2) ? -1 : 1;
|
|
|
|
|
++p;
|
|
|
|
|
++p2;
|
|
|
|
|
}
|
2006-10-11 19:40:50 +00:00
|
|
|
|
|
2006-11-13 09:53:25 +00:00
|
|
|
|
if (s.size() == s2.size())
|
|
|
|
|
return 0;
|
|
|
|
|
if (s.size() < s2.size())
|
|
|
|
|
return -1;
|
|
|
|
|
return 1;
|
2006-10-11 19:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-06 02:44:26 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
bool isStrInt(string const & str)
|
|
|
|
|
{
|
|
|
|
|
if (str.empty()) return false;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
// Remove leading and trailing white space chars.
|
2002-07-28 22:50:13 +00:00
|
|
|
|
string const tmpstr = trim(str);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
if (tmpstr.empty()) return false;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string::const_iterator cit = tmpstr.begin();
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if ((*cit) == '-') ++cit;
|
2000-08-03 21:17:52 +00:00
|
|
|
|
string::const_iterator end = tmpstr.end();
|
|
|
|
|
for (; cit != end; ++cit) {
|
1999-10-02 16:21:10 +00:00
|
|
|
|
if (!isdigit((*cit))) return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-12-04 17:18:01 +00:00
|
|
|
|
bool isStrUnsignedInt(string const & str)
|
|
|
|
|
{
|
|
|
|
|
if (str.empty()) return false;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-12-04 17:18:01 +00:00
|
|
|
|
// Remove leading and trailing white space chars.
|
2002-07-28 22:50:13 +00:00
|
|
|
|
string const tmpstr = trim(str);
|
2000-12-04 17:18:01 +00:00
|
|
|
|
if (tmpstr.empty()) return false;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-12-04 17:18:01 +00:00
|
|
|
|
string::const_iterator cit = tmpstr.begin();
|
|
|
|
|
string::const_iterator end = tmpstr.end();
|
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
|
if (!isdigit((*cit))) return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
bool isStrDbl(string const & str)
|
|
|
|
|
{
|
|
|
|
|
if (str.empty()) return false;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
// Remove leading and trailing white space chars.
|
2002-07-28 22:50:13 +00:00
|
|
|
|
string const tmpstr = trim(str);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (tmpstr.empty()) return false;
|
|
|
|
|
// if (1 < tmpstr.count('.')) return false;
|
|
|
|
|
|
|
|
|
|
string::const_iterator cit = tmpstr.begin();
|
|
|
|
|
bool found_dot(false);
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if ((*cit) == '-') ++cit;
|
2000-08-03 21:17:52 +00:00
|
|
|
|
string::const_iterator end = tmpstr.end();
|
|
|
|
|
for (; cit != end; ++cit) {
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (!isdigit((*cit))
|
|
|
|
|
&& '.' != (*cit)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if ('.' == (*cit)) {
|
|
|
|
|
if (found_dot) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
found_dot = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
|
|
2006-10-22 18:47:19 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
|
bool isHexChar(char_type c)
|
|
|
|
|
{
|
|
|
|
|
return c == '0' ||
|
|
|
|
|
c == '1' ||
|
|
|
|
|
c == '2' ||
|
|
|
|
|
c == '3' ||
|
|
|
|
|
c == '4' ||
|
|
|
|
|
c == '5' ||
|
|
|
|
|
c == '6' ||
|
|
|
|
|
c == '7' ||
|
|
|
|
|
c == '8' ||
|
|
|
|
|
c == '9' ||
|
|
|
|
|
c == 'a' || c == 'A' ||
|
|
|
|
|
c == 'b' || c == 'B' ||
|
|
|
|
|
c == 'c' || c == 'C' ||
|
|
|
|
|
c == 'd' || c == 'D' ||
|
|
|
|
|
c == 'e' || c == 'E' ||
|
|
|
|
|
c == 'f' || c == 'F';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isHex(docstring const & str)
|
|
|
|
|
{
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
2006-10-22 19:09:09 +00:00
|
|
|
|
if (str.length() > 2 && str[0] == '0' &&
|
2006-10-22 18:47:19 +00:00
|
|
|
|
(str[1] == 'x' || str[1] == 'X'))
|
|
|
|
|
index = 2;
|
|
|
|
|
|
|
|
|
|
int const len = str.length();
|
|
|
|
|
|
|
|
|
|
for (; index < len; ++index) {
|
|
|
|
|
if (!isHexChar(str[index]))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int hexToInt(docstring const & str)
|
|
|
|
|
{
|
|
|
|
|
string s = to_ascii(str);
|
|
|
|
|
int h;
|
|
|
|
|
sscanf(s.c_str(), "%x", &h);
|
|
|
|
|
return h;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-11 12:00:34 +00:00
|
|
|
|
bool isAscii(docstring const & str)
|
|
|
|
|
{
|
|
|
|
|
int const len = str.length();
|
|
|
|
|
for (int i = 0; i < len; ++i)
|
|
|
|
|
if (str[i] >= 0x80)
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
char lowercase(char c)
|
|
|
|
|
{
|
2007-03-02 16:52:49 +00:00
|
|
|
|
BOOST_ASSERT(static_cast<unsigned char>(c) < 0x80);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
return char(tolower(c));
|
2000-07-24 13:53:19 +00:00
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
char uppercase(char c)
|
|
|
|
|
{
|
2007-03-02 16:52:49 +00:00
|
|
|
|
BOOST_ASSERT(static_cast<unsigned char>(c) < 0x80);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
return char(toupper(c));
|
2000-07-24 13:53:19 +00:00
|
|
|
|
}
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
2006-11-13 09:53:25 +00:00
|
|
|
|
|
2006-09-03 14:09:24 +00:00
|
|
|
|
char_type lowercase(char_type c)
|
|
|
|
|
{
|
2007-02-26 09:03:21 +00:00
|
|
|
|
if (!is_utf16(c))
|
|
|
|
|
// We don't know how to lowercase a non-utf16 char
|
2006-09-03 14:09:24 +00:00
|
|
|
|
return c;
|
2007-02-26 09:03:21 +00:00
|
|
|
|
return qchar_to_ucs4(ucs4_to_qchar(c).toLower());
|
2006-09-03 14:09:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char_type uppercase(char_type c)
|
|
|
|
|
{
|
2007-02-26 09:03:21 +00:00
|
|
|
|
if (!is_utf16(c))
|
|
|
|
|
// We don't know how to uppercase a non-utf16 char
|
2006-09-03 14:09:24 +00:00
|
|
|
|
return c;
|
2007-02-26 09:03:21 +00:00
|
|
|
|
return qchar_to_ucs4(ucs4_to_qchar(c).toUpper());
|
2006-09-03 14:09:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
|
|
2001-04-25 19:33:52 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
// since we cannot use std::tolower and std::toupper directly in the
|
|
|
|
|
// calls to std::transform yet, we use these helper clases. (Lgb)
|
|
|
|
|
|
2007-02-26 09:03:21 +00:00
|
|
|
|
struct local_lowercase {
|
|
|
|
|
char_type operator()(char_type c) const {
|
|
|
|
|
if (!is_utf16(c))
|
|
|
|
|
// We don't know how to lowercase a non-utf16 char
|
|
|
|
|
return c;
|
|
|
|
|
return qchar_to_ucs4(ucs4_to_qchar(c).toLower());
|
|
|
|
|
}
|
2001-04-25 19:33:52 +00:00
|
|
|
|
};
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-04-25 19:33:52 +00:00
|
|
|
|
struct local_uppercase {
|
2007-02-26 18:54:03 +00:00
|
|
|
|
char_type operator()(char_type c) const {
|
|
|
|
|
if (!is_utf16(c))
|
|
|
|
|
// We don't know how to uppercase a non-utf16 char
|
|
|
|
|
return c;
|
|
|
|
|
return qchar_to_ucs4(ucs4_to_qchar(c).toUpper());
|
2001-04-25 19:33:52 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2006-12-15 16:09:05 +00:00
|
|
|
|
template<typename Char> struct local_ascii_lowercase {
|
|
|
|
|
Char operator()(Char c) const {
|
2002-07-16 21:17:10 +00:00
|
|
|
|
return ascii_tolower(c);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2001-04-25 19:33:52 +00:00
|
|
|
|
} // end of anon namespace
|
|
|
|
|
|
2006-12-10 11:52:46 +00:00
|
|
|
|
docstring const lowercase(docstring const & a)
|
|
|
|
|
{
|
|
|
|
|
docstring tmp(a);
|
2007-02-26 09:03:21 +00:00
|
|
|
|
transform(tmp.begin(), tmp.end(), tmp.begin(), local_lowercase());
|
2006-12-10 11:52:46 +00:00
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-02-26 18:54:03 +00:00
|
|
|
|
docstring const uppercase(docstring const & a)
|
1999-12-15 06:12:28 +00:00
|
|
|
|
{
|
2007-02-26 18:54:03 +00:00
|
|
|
|
docstring tmp(a);
|
2001-04-25 19:33:52 +00:00
|
|
|
|
transform(tmp.begin(), tmp.end(), tmp.begin(), local_uppercase());
|
1999-12-15 06:12:28 +00:00
|
|
|
|
return tmp;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-16 21:17:10 +00:00
|
|
|
|
string const ascii_lowercase(string const & a)
|
|
|
|
|
{
|
|
|
|
|
string tmp(a);
|
|
|
|
|
transform(tmp.begin(), tmp.end(), tmp.begin(),
|
2006-12-15 16:09:05 +00:00
|
|
|
|
local_ascii_lowercase<char>());
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring const ascii_lowercase(docstring const & a)
|
|
|
|
|
{
|
|
|
|
|
docstring tmp(a);
|
|
|
|
|
transform(tmp.begin(), tmp.end(), tmp.begin(),
|
|
|
|
|
local_ascii_lowercase<char_type>());
|
2002-07-16 21:17:10 +00:00
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-01-05 17:11:32 +00:00
|
|
|
|
bool prefixIs(docstring const & a, char_type c)
|
|
|
|
|
{
|
|
|
|
|
if (a.empty())
|
|
|
|
|
return false;
|
|
|
|
|
return a[0] == c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
|
bool prefixIs(string const & a, string const & pre)
|
|
|
|
|
{
|
|
|
|
|
string::size_type const prelen = pre.length();
|
|
|
|
|
string::size_type const alen = a.length();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-12-10 05:20:36 +00:00
|
|
|
|
if (prelen > alen || a.empty())
|
2000-09-26 13:54:57 +00:00
|
|
|
|
return false;
|
|
|
|
|
else {
|
2004-01-31 15:30:24 +00:00
|
|
|
|
#if defined(STD_STRING_IS_GOOD)
|
2000-09-26 13:54:57 +00:00
|
|
|
|
return a.compare(0, prelen, pre) == 0;
|
2004-01-31 15:30:24 +00:00
|
|
|
|
#else
|
|
|
|
|
return ::strncmp(a.c_str(), pre.c_str(), prelen) == 0;
|
2000-09-26 13:54:57 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-20 16:12:49 +00:00
|
|
|
|
bool prefixIs(docstring const & a, docstring const & pre)
|
|
|
|
|
{
|
|
|
|
|
docstring::size_type const prelen = pre.length();
|
|
|
|
|
docstring::size_type const alen = a.length();
|
|
|
|
|
|
|
|
|
|
if (prelen > alen || a.empty())
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
return a.compare(0, prelen, pre) == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
bool suffixIs(string const & a, char c)
|
|
|
|
|
{
|
|
|
|
|
if (a.empty()) return false;
|
1999-11-22 16:19:48 +00:00
|
|
|
|
return a[a.length() - 1] == c;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-01-05 17:11:32 +00:00
|
|
|
|
bool suffixIs(docstring const & a, char_type c)
|
|
|
|
|
{
|
|
|
|
|
if (a.empty())
|
|
|
|
|
return false;
|
|
|
|
|
return a[a.length() - 1] == c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
|
bool suffixIs(string const & a, string const & suf)
|
|
|
|
|
{
|
|
|
|
|
string::size_type const suflen = suf.length();
|
|
|
|
|
string::size_type const alen = a.length();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
|
if (suflen > alen) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
#if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
|
|
|
|
|
string tmp(a, alen - suflen);
|
|
|
|
|
return ::strncmp(tmp.c_str(), suf.c_str(), suflen) == 0;
|
|
|
|
|
#else
|
2000-10-02 00:55:02 +00:00
|
|
|
|
return a.compare(alen - suflen, suflen, suf) == 0;
|
2000-09-26 13:54:57 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
bool containsOnly(string const & s, string const & cset)
|
|
|
|
|
{
|
|
|
|
|
return s.find_first_not_of(cset) == string::npos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
// ale970405+lasgoutt-970425
|
|
|
|
|
// rewritten to use new string (Lgb)
|
2000-08-03 21:17:52 +00:00
|
|
|
|
string const token(string const & a, char delim, int n)
|
1999-10-02 16:21:10 +00:00
|
|
|
|
{
|
|
|
|
|
if (a.empty()) return string();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string::size_type k = 0;
|
|
|
|
|
string::size_type i = 0;
|
|
|
|
|
|
|
|
|
|
// Find delimiter or end of string
|
|
|
|
|
for (; n--;)
|
|
|
|
|
if ((i = a.find(delim, i)) == string::npos)
|
|
|
|
|
break;
|
|
|
|
|
else
|
|
|
|
|
++i; // step delim
|
|
|
|
|
// i is now the n'th delim (or string::npos)
|
|
|
|
|
if (i == string::npos) return string();
|
|
|
|
|
k = a.find(delim, i);
|
|
|
|
|
// k is now the n'th + 1 delim (or string::npos)
|
|
|
|
|
|
|
|
|
|
return a.substr(i, k - i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-09 22:27:22 +00:00
|
|
|
|
docstring const token(docstring const & a, char_type delim, int n)
|
|
|
|
|
{
|
|
|
|
|
if (a.empty()) return docstring();
|
|
|
|
|
|
|
|
|
|
string::size_type k = 0;
|
|
|
|
|
string::size_type i = 0;
|
|
|
|
|
|
|
|
|
|
// Find delimiter or end of string
|
|
|
|
|
for (; n--;)
|
|
|
|
|
if ((i = a.find(delim, i)) == docstring::npos)
|
|
|
|
|
break;
|
|
|
|
|
else
|
|
|
|
|
++i; // step delim
|
|
|
|
|
// i is now the n'th delim (or string::npos)
|
|
|
|
|
if (i == docstring::npos) return docstring();
|
|
|
|
|
k = a.find(delim, i);
|
|
|
|
|
// k is now the n'th + 1 delim (or string::npos)
|
|
|
|
|
|
|
|
|
|
return a.substr(i, k - i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
// this could probably be faster and/or cleaner, but it seems to work (JMarc)
|
|
|
|
|
// rewritten to use new string (Lgb)
|
|
|
|
|
int tokenPos(string const & a, char delim, string const & tok)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
2000-08-03 21:17:52 +00:00
|
|
|
|
string str(a);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string tmptok;
|
|
|
|
|
|
|
|
|
|
while (!str.empty()) {
|
|
|
|
|
str = split(str, tmptok, delim);
|
1999-11-15 10:54:16 +00:00
|
|
|
|
if (tok == tmptok)
|
1999-10-02 16:21:10 +00:00
|
|
|
|
return i;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-03 07:02:38 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
/// Substitute all \a oldchar with \a newchar
|
2006-09-03 07:02:38 +00:00
|
|
|
|
template<typename Ch> inline
|
2006-09-03 14:09:24 +00:00
|
|
|
|
std::basic_string<Ch> const subst_char(std::basic_string<Ch> const & a,
|
|
|
|
|
Ch oldchar, Ch newchar)
|
1999-10-02 16:21:10 +00:00
|
|
|
|
{
|
2006-09-03 07:02:38 +00:00
|
|
|
|
typedef std::basic_string<Ch> String;
|
|
|
|
|
String tmp(a);
|
|
|
|
|
typename String::iterator lit = tmp.begin();
|
|
|
|
|
typename String::iterator end = tmp.end();
|
2000-11-04 10:00:12 +00:00
|
|
|
|
for (; lit != end; ++lit)
|
1999-10-02 16:21:10 +00:00
|
|
|
|
if ((*lit) == oldchar)
|
|
|
|
|
(*lit) = newchar;
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
/// substitutes all instances of \a oldstr with \a newstr
|
2006-09-03 07:02:38 +00:00
|
|
|
|
template<typename String> inline
|
2006-09-03 14:09:24 +00:00
|
|
|
|
String const subst_string(String const & a,
|
|
|
|
|
String const & oldstr, String const & newstr)
|
2000-09-26 13:54:57 +00:00
|
|
|
|
{
|
2005-09-07 09:44:58 +00:00
|
|
|
|
BOOST_ASSERT(!oldstr.empty());
|
2006-09-03 07:02:38 +00:00
|
|
|
|
String lstr = a;
|
|
|
|
|
typename String::size_type i = 0;
|
|
|
|
|
typename String::size_type const olen = oldstr.length();
|
2001-12-05 08:04:20 +00:00
|
|
|
|
while ((i = lstr.find(oldstr, i)) != string::npos) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
lstr.replace(i, olen, newstr);
|
|
|
|
|
i += newstr.length(); // We need to be sure that we dont
|
|
|
|
|
// use the same i over and over again.
|
|
|
|
|
}
|
|
|
|
|
return lstr;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-03 07:02:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const subst(string const & a, char oldchar, char newchar)
|
|
|
|
|
{
|
2006-09-03 14:09:24 +00:00
|
|
|
|
return subst_char(a, oldchar, newchar);
|
2006-09-03 07:02:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring const subst(docstring const & a,
|
|
|
|
|
char_type oldchar, char_type newchar)
|
|
|
|
|
{
|
2006-09-03 14:09:24 +00:00
|
|
|
|
return subst_char(a, oldchar, newchar);
|
2006-09-03 07:02:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const subst(string const & a,
|
|
|
|
|
string const & oldstr, string const & newstr)
|
|
|
|
|
{
|
2006-09-03 14:09:24 +00:00
|
|
|
|
return subst_string(a, oldstr, newstr);
|
2006-09-03 07:02:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring const subst(docstring const & a,
|
|
|
|
|
docstring const & oldstr, docstring const & newstr)
|
|
|
|
|
{
|
2006-09-03 14:09:24 +00:00
|
|
|
|
return subst_string(a, oldstr, newstr);
|
2006-09-03 07:02:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
|
|
2006-10-09 09:15:37 +00:00
|
|
|
|
docstring const trim(docstring const & a, char const * p)
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(p);
|
|
|
|
|
|
|
|
|
|
if (a.empty() || !*p)
|
|
|
|
|
return a;
|
|
|
|
|
|
|
|
|
|
docstring s = lyx::from_ascii(p);
|
|
|
|
|
docstring::size_type r = a.find_last_not_of(s);
|
|
|
|
|
docstring::size_type l = a.find_first_not_of(s);
|
|
|
|
|
|
|
|
|
|
// Is this the minimal test? (lgb)
|
|
|
|
|
if (r == docstring::npos && l == docstring::npos)
|
|
|
|
|
return docstring();
|
|
|
|
|
|
|
|
|
|
return a.substr(l, r - l + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-28 22:50:13 +00:00
|
|
|
|
string const trim(string const & a, char const * p)
|
1999-10-02 16:21:10 +00:00
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(p);
|
2002-07-28 18:13:51 +00:00
|
|
|
|
|
2002-07-28 22:50:13 +00:00
|
|
|
|
if (a.empty() || !*p)
|
|
|
|
|
return a;
|
|
|
|
|
|
|
|
|
|
string::size_type r = a.find_last_not_of(p);
|
|
|
|
|
string::size_type l = a.find_first_not_of(p);
|
|
|
|
|
|
|
|
|
|
// Is this the minimal test? (lgb)
|
|
|
|
|
if (r == string::npos && l == string::npos)
|
|
|
|
|
return string();
|
|
|
|
|
|
|
|
|
|
return a.substr(l, r - l + 1);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-28 22:50:13 +00:00
|
|
|
|
string const rtrim(string const & a, char const * p)
|
1999-10-02 16:21:10 +00:00
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(p);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2002-07-28 22:50:13 +00:00
|
|
|
|
if (a.empty() || !*p)
|
|
|
|
|
return a;
|
|
|
|
|
|
|
|
|
|
string::size_type r = a.find_last_not_of(p);
|
|
|
|
|
|
|
|
|
|
// Is this test really needed? (Lgb)
|
|
|
|
|
if (r == string::npos)
|
|
|
|
|
return string();
|
|
|
|
|
|
|
|
|
|
return a.substr(0, r + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-17 10:52:04 +00:00
|
|
|
|
docstring const rtrim(docstring const & a, char const * p)
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(p);
|
|
|
|
|
|
|
|
|
|
if (a.empty() || !*p)
|
|
|
|
|
return a;
|
|
|
|
|
|
|
|
|
|
docstring::size_type r = a.find_last_not_of(from_ascii(p));
|
|
|
|
|
|
|
|
|
|
// Is this test really needed? (Lgb)
|
|
|
|
|
if (r == docstring::npos)
|
|
|
|
|
return docstring();
|
|
|
|
|
|
|
|
|
|
return a.substr(0, r + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-28 22:50:13 +00:00
|
|
|
|
string const ltrim(string const & a, char const * p)
|
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(p);
|
2002-07-28 22:50:13 +00:00
|
|
|
|
if (a.empty() || !*p)
|
|
|
|
|
return a;
|
|
|
|
|
string::size_type l = a.find_first_not_of(p);
|
|
|
|
|
if (l == string::npos)
|
|
|
|
|
return string();
|
|
|
|
|
return a.substr(l, string::npos);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const ltrim(docstring const & a, char const * p)
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(p);
|
|
|
|
|
if (a.empty() || !*p)
|
|
|
|
|
return a;
|
|
|
|
|
size_t l = a.find_first_not_of(from_ascii(p));
|
|
|
|
|
if (l == docstring::npos)
|
|
|
|
|
return docstring();
|
|
|
|
|
return a.substr(l, docstring::npos);
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2006-10-11 18:32:32 +00:00
|
|
|
|
template<typename String, typename Char> inline
|
|
|
|
|
String const doSplit(String const & a, String & piece, Char delim)
|
1999-10-02 16:21:10 +00:00
|
|
|
|
{
|
2006-10-11 18:32:32 +00:00
|
|
|
|
String tmp;
|
|
|
|
|
typename String::size_type i = a.find(delim);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
if (i == a.length() - 1) {
|
|
|
|
|
piece = a.substr(0, i);
|
2006-10-11 18:32:32 +00:00
|
|
|
|
} else if (i != String::npos) {
|
1999-10-02 16:21:10 +00:00
|
|
|
|
piece = a.substr(0, i);
|
|
|
|
|
tmp = a.substr(i + 1);
|
|
|
|
|
} else if (i == 0) {
|
2000-05-04 10:57:00 +00:00
|
|
|
|
piece.erase();
|
1999-10-02 16:21:10 +00:00
|
|
|
|
tmp = a.substr(i + 1);
|
|
|
|
|
} else {
|
|
|
|
|
piece = a;
|
|
|
|
|
}
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
2006-10-11 18:32:32 +00:00
|
|
|
|
string const split(string const & a, string & piece, char delim)
|
|
|
|
|
{
|
|
|
|
|
return doSplit(a, piece, delim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring const split(docstring const & a, docstring & piece, char_type delim)
|
|
|
|
|
{
|
|
|
|
|
return doSplit(a, piece, delim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
|
string const split(string const & a, char delim)
|
1999-10-02 16:21:10 +00:00
|
|
|
|
{
|
|
|
|
|
string tmp;
|
|
|
|
|
string::size_type i = a.find(delim);
|
|
|
|
|
if (i != string::npos) // found delim
|
|
|
|
|
tmp = a.substr(i + 1);
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ale970521
|
2000-08-03 21:17:52 +00:00
|
|
|
|
string const rsplit(string const & a, string & piece, char delim)
|
1999-10-02 16:21:10 +00:00
|
|
|
|
{
|
|
|
|
|
string tmp;
|
|
|
|
|
string::size_type i = a.rfind(delim);
|
|
|
|
|
if (i != string::npos) { // delimiter was found
|
|
|
|
|
piece = a.substr(0, i);
|
|
|
|
|
tmp = a.substr(i + 1);
|
2003-05-13 16:24:49 +00:00
|
|
|
|
} else { // delimiter was not found
|
2000-05-04 10:57:00 +00:00
|
|
|
|
piece.erase();
|
1999-10-02 16:21:10 +00:00
|
|
|
|
}
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
docstring const escape(docstring const & lab)
|
2001-06-27 14:10:35 +00:00
|
|
|
|
{
|
2006-11-12 13:42:20 +00:00
|
|
|
|
char_type hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
|
|
|
|
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
2006-10-19 16:51:30 +00:00
|
|
|
|
docstring enc;
|
|
|
|
|
for (docstring::size_type i = 0; i < lab.length(); ++i) {
|
2006-11-12 13:42:20 +00:00
|
|
|
|
char_type c = lab[i];
|
2001-06-27 14:10:35 +00:00
|
|
|
|
if (c >= 128 || c == '=' || c == '%') {
|
2006-11-12 13:42:20 +00:00
|
|
|
|
// Although char_type is a 32 bit type we know that
|
|
|
|
|
// UCS4 occupies only 21 bits, so we don't need to
|
|
|
|
|
// encode bigger values. Test for 2^24 because we
|
|
|
|
|
// can encode that with the 6 hex digits that are
|
|
|
|
|
// needed for 21 bits anyway.
|
|
|
|
|
BOOST_ASSERT(c < (1 << 24));
|
2001-06-27 14:10:35 +00:00
|
|
|
|
enc += '=';
|
2006-11-12 13:42:20 +00:00
|
|
|
|
enc += hexdigit[(c>>20) & 15];
|
|
|
|
|
enc += hexdigit[(c>>16) & 15];
|
|
|
|
|
enc += hexdigit[(c>>12) & 15];
|
|
|
|
|
enc += hexdigit[(c>> 8) & 15];
|
|
|
|
|
enc += hexdigit[(c>> 4) & 15];
|
|
|
|
|
enc += hexdigit[ c & 15];
|
2001-06-27 14:10:35 +00:00
|
|
|
|
} else {
|
|
|
|
|
enc += c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return enc;
|
|
|
|
|
}
|
2002-04-15 12:05:07 +00:00
|
|
|
|
|
|
|
|
|
|
2006-12-17 10:52:04 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
template<typename String> vector<String> const
|
|
|
|
|
getVectorFromStringT(String const & str, String const & delim)
|
2002-04-15 12:05:07 +00:00
|
|
|
|
{
|
2002-11-12 13:18:07 +00:00
|
|
|
|
// Lars would like this code to go, but for now his replacement (below)
|
|
|
|
|
// doesn't fullfil the same function. I have, therefore, reactivated the
|
|
|
|
|
// old code for now. Angus 11 Nov 2002.
|
|
|
|
|
#if 1
|
2006-12-17 10:52:04 +00:00
|
|
|
|
vector<String> vec;
|
2002-11-04 00:15:56 +00:00
|
|
|
|
if (str.empty())
|
|
|
|
|
return vec;
|
2006-12-17 10:52:04 +00:00
|
|
|
|
String keys = rtrim(str);
|
2002-11-04 00:15:56 +00:00
|
|
|
|
for(;;) {
|
2006-12-17 10:52:04 +00:00
|
|
|
|
typename String::size_type const idx = keys.find(delim);
|
|
|
|
|
if (idx == String::npos) {
|
2002-11-04 00:15:56 +00:00
|
|
|
|
vec.push_back(ltrim(keys));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-12-17 10:52:04 +00:00
|
|
|
|
String const key = trim(keys.substr(0, idx));
|
2002-11-04 00:15:56 +00:00
|
|
|
|
if (!key.empty())
|
|
|
|
|
vec.push_back(key);
|
2006-12-17 10:52:04 +00:00
|
|
|
|
typename String::size_type const start = idx + delim.size();
|
2002-11-04 00:15:56 +00:00
|
|
|
|
keys = keys.substr(start);
|
2002-04-15 12:05:07 +00:00
|
|
|
|
}
|
2002-11-04 00:15:56 +00:00
|
|
|
|
return vec;
|
|
|
|
|
#else
|
2006-12-17 10:52:04 +00:00
|
|
|
|
typedef boost::char_separator<typename String::value_type> Separator;
|
|
|
|
|
typedef boost::tokenizer<Separator, typename String::const_iterator, String> Tokenizer;
|
|
|
|
|
Separator sep(delim.c_str());
|
|
|
|
|
Tokenizer tokens(str, sep);
|
|
|
|
|
return vector<String>(tokens.begin(), tokens.end());
|
2002-11-04 00:15:56 +00:00
|
|
|
|
#endif
|
2002-04-15 12:05:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-12-17 10:52:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<string> const getVectorFromString(string const & str,
|
|
|
|
|
string const & delim)
|
|
|
|
|
{
|
|
|
|
|
return getVectorFromStringT<string>(str, delim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<docstring> const getVectorFromString(docstring const & str,
|
|
|
|
|
docstring const & delim)
|
|
|
|
|
{
|
|
|
|
|
return getVectorFromStringT<docstring>(str, delim);
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-04 00:15:56 +00:00
|
|
|
|
|
2002-04-15 12:05:07 +00:00
|
|
|
|
// 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) {
|
2002-07-28 22:50:13 +00:00
|
|
|
|
string item = trim(*it);
|
2003-05-19 14:10:32 +00:00
|
|
|
|
if (item.empty())
|
|
|
|
|
continue;
|
|
|
|
|
if (i++ > 0)
|
|
|
|
|
str += delim;
|
2002-04-15 12:05:07 +00:00
|
|
|
|
str += item;
|
|
|
|
|
}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
2003-05-13 09:48:57 +00:00
|
|
|
|
|
|
|
|
|
|
2006-04-20 09:55:45 +00:00
|
|
|
|
int findToken(char const * const str[], string const & search_token)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
while (str[i][0] && str[i] != search_token)
|
|
|
|
|
++i;
|
|
|
|
|
if (!str[i][0])
|
|
|
|
|
i = -1;
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-03 07:02:38 +00:00
|
|
|
|
docstring const externalLineEnding(docstring const & str)
|
2006-06-20 08:39:16 +00:00
|
|
|
|
{
|
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
|
// The MAC clipboard uses \r for lineendings, and we use \n
|
|
|
|
|
return subst(str, '\n', '\r');
|
|
|
|
|
#elif defined (_WIN32) || (defined (__CYGWIN__) && defined (X_DISPLAY_MISSING))
|
|
|
|
|
// Windows clipboard uses \r\n for lineendings, and we use \n
|
2006-09-03 07:02:38 +00:00
|
|
|
|
return subst(str, lyx::from_ascii("\n"), lyx::from_ascii("\r\n"));
|
2006-06-20 08:39:16 +00:00
|
|
|
|
#else
|
|
|
|
|
return str;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-03 07:02:38 +00:00
|
|
|
|
docstring const internalLineEnding(docstring const & str)
|
2006-06-20 08:39:16 +00:00
|
|
|
|
{
|
2006-09-03 07:02:38 +00:00
|
|
|
|
docstring const s = subst(str,
|
|
|
|
|
lyx::from_ascii("\r\n"), lyx::from_ascii("\n"));
|
2006-06-20 08:39:16 +00:00
|
|
|
|
return subst(s, '\r', '\n');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
#ifndef I_AM_NOT_AFRAID_OF_HEADER_LIBRARIES
|
2003-05-13 09:48:57 +00:00
|
|
|
|
#if USE_BOOST_FORMAT
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, int arg1)
|
2003-05-13 09:48:57 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
return (boost::basic_format<char_type>(fmt) % arg1).str();
|
2003-05-13 09:48:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, long arg1)
|
2003-05-13 09:48:57 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
return (boost::basic_format<char_type>(fmt) % arg1).str();
|
2005-01-06 15:40:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, unsigned int arg1)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
return (boost::basic_format<char_type>(fmt) % arg1).str();
|
2005-01-06 15:40:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat<docstring>(docstring const & fmt, docstring arg1)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
return (boost::basic_format<char_type>(fmt) % arg1).str();
|
2005-01-06 15:40:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-13 11:18:13 +00:00
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, char * arg1)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
return (boost::basic_format<char_type>(fmt) % arg1).str();
|
2003-05-13 09:48:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-05-19 14:10:32 +00:00
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, int arg1, int arg2)
|
2003-09-04 14:33:16 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
return (boost::basic_format<char_type>(fmt) % arg1 % arg2).str();
|
2003-09-04 14:33:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, docstring arg1, docstring arg2)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
return (boost::basic_format<char_type>(fmt) % arg1 % arg2).str();
|
2005-01-06 15:40:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, char const * arg1, docstring arg2)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
return (boost::basic_format<char_type>(fmt) % arg1 % arg2).str();
|
2005-01-06 15:40:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, docstring arg1, docstring arg2, docstring arg3)
|
2003-05-19 14:10:32 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
return (boost::basic_format<char_type>(fmt) % arg1 % arg2 % arg3).str();
|
2003-05-19 14:10:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt,
|
|
|
|
|
docstring arg1, docstring arg2, docstring arg3, docstring arg4)
|
2003-05-13 09:48:57 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
return (boost::basic_format<char_type>(fmt) % arg1 % arg2 % arg3 % arg4).str();
|
2003-06-30 15:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, int arg1)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$d")));
|
|
|
|
|
docstring const str = subst(fmt, lyx::from_ascii("%1$d"), convert<docstring>(arg1));
|
|
|
|
|
return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
|
2005-01-06 15:40:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-06-30 15:06:30 +00:00
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, long arg1)
|
2003-06-30 15:06:30 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$d")));
|
|
|
|
|
docstring const str = subst(fmt, lyx::from_ascii("%1$d"), convert<docstring>(arg1));
|
|
|
|
|
return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
|
2003-05-13 09:48:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, unsigned int arg1)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$d")));
|
|
|
|
|
docstring const str = subst(fmt, lyx::from_ascii("%1$d"), convert<docstring>(arg1));
|
|
|
|
|
return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
|
2005-01-06 15:40:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, docstring arg1)
|
2003-05-13 09:48:57 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$s")));
|
|
|
|
|
docstring const str = subst(fmt, lyx::from_ascii("%1$s"), arg1);
|
|
|
|
|
return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
|
2003-05-13 09:48:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, char * arg1)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$s")));
|
2006-09-13 11:18:13 +00:00
|
|
|
|
docstring const str = subst(fmt, lyx::from_ascii("%1$s"), lyx::from_ascii(arg1));
|
2006-09-11 08:54:10 +00:00
|
|
|
|
return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
|
2005-01-06 15:40:49 +00:00
|
|
|
|
}
|
2006-09-13 11:18:13 +00:00
|
|
|
|
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, docstring arg1, docstring arg2)
|
2003-05-13 09:48:57 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$s")));
|
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%2$s")));
|
|
|
|
|
docstring str = subst(fmt, lyx::from_ascii("%1$s"), arg1);
|
|
|
|
|
str = subst(str, lyx::from_ascii("%2$s"), arg2);
|
|
|
|
|
return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
|
2003-05-13 09:48:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, char const * arg1, docstring arg2)
|
2003-09-04 14:33:16 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$s")));
|
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%2$s")));
|
2006-09-13 11:18:13 +00:00
|
|
|
|
docstring str = subst(fmt, lyx::from_ascii("%1$s"), lyx::from_ascii(arg1));
|
2006-09-11 08:54:10 +00:00
|
|
|
|
str = subst(fmt, lyx::from_ascii("%2$s"), arg2);
|
|
|
|
|
return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
|
2003-09-04 14:33:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, int arg1, int arg2)
|
2003-05-19 14:10:32 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$d")));
|
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%2$d")));
|
|
|
|
|
docstring str = subst(fmt, lyx::from_ascii("%1$d"), convert<docstring>(arg1));
|
|
|
|
|
str = subst(str, lyx::from_ascii("%2$d"), convert<docstring>(arg2));
|
|
|
|
|
return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
|
2003-05-19 14:10:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, docstring arg1, docstring arg2, docstring arg3)
|
2003-05-13 09:48:57 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$s")));
|
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%2$s")));
|
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%3$s")));
|
|
|
|
|
docstring str = subst(fmt, lyx::from_ascii("%1$s"), arg1);
|
|
|
|
|
str = subst(str, lyx::from_ascii("%2$s"), arg2);
|
|
|
|
|
str = subst(str, lyx::from_ascii("%3$s"), arg3);
|
|
|
|
|
return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
|
2003-05-13 09:48:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-06-30 15:06:30 +00:00
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt,
|
|
|
|
|
docstring arg1, docstring arg2, docstring arg3, docstring arg4)
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%1$s")));
|
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%2$s")));
|
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%3$s")));
|
|
|
|
|
BOOST_ASSERT(contains(fmt, lyx::from_ascii("%4$s")));
|
|
|
|
|
docstring str = subst(fmt, lyx::from_ascii("%1$s"), arg1);
|
|
|
|
|
str = subst(str, lyx::from_ascii("%2$s"), arg2);
|
|
|
|
|
str = subst(str, lyx::from_ascii("%3$s"), arg3);
|
|
|
|
|
str = subst(str, lyx::from_ascii("%4$s"), arg4);
|
|
|
|
|
return subst(str, lyx::from_ascii("%%"), lyx::from_ascii("%"));
|
2003-06-30 15:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
#endif
|
2003-05-13 09:48:57 +00:00
|
|
|
|
#endif
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
|
|
|
|
} // namespace support
|
|
|
|
|
} // namespace lyx
|