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"
|
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
|
|
|
|
using lyx::docstring;
|
|
|
|
|
|
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
|
|
|
|
|
1999-12-19 22:35:36 +00:00
|
|
|
|
int compare_no_case(string const & s, string const & s2)
|
|
|
|
|
{
|
|
|
|
|
string::const_iterator p = s.begin();
|
|
|
|
|
string::const_iterator p2 = s2.begin();
|
|
|
|
|
|
|
|
|
|
while (p != s.end() && p2 != s2.end()) {
|
|
|
|
|
int const lc1 = tolower(*p);
|
|
|
|
|
int const lc2 = tolower(*p2);
|
|
|
|
|
if (lc1 != lc2)
|
|
|
|
|
return (lc1 < lc2) ? -1 : 1;
|
|
|
|
|
++p;
|
|
|
|
|
++p2;
|
|
|
|
|
}
|
2000-12-13 13:30:36 +00:00
|
|
|
|
|
1999-12-19 22:35:36 +00:00
|
|
|
|
if (s.size() == s2.size())
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return 0;
|
|
|
|
|
if (s.size() < s2.size())
|
|
|
|
|
return -1;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-27 14:10:35 +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()) {
|
|
|
|
|
int const lc1 = tolower(*p);
|
|
|
|
|
int const lc2 = tolower(*p2);
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
int ascii_tolower(int c) {
|
|
|
|
|
if (c >= 'A' && c <= 'Z')
|
|
|
|
|
return c - 'A' + 'a';
|
|
|
|
|
return c;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
template<typename String> inline
|
|
|
|
|
int do_compare_ascii_no_case(String const & s, String const & s2)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2006-10-11 19:40:50 +00:00
|
|
|
|
typename String::const_iterator p = s.begin();
|
|
|
|
|
typename 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int compare_ascii_no_case(string const & s, string const & s2)
|
|
|
|
|
{
|
|
|
|
|
return do_compare_ascii_no_case(s, s2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int compare_ascii_no_case(docstring const & s, docstring const & s2)
|
|
|
|
|
{
|
|
|
|
|
return do_compare_ascii_no_case(s, s2);
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-06 02:44:26 +00:00
|
|
|
|
|
1999-12-19 22:35:36 +00:00
|
|
|
|
int compare_no_case(string const & s, string const & s2, unsigned int len)
|
|
|
|
|
{
|
|
|
|
|
string::const_iterator p = s.begin();
|
|
|
|
|
string::const_iterator p2 = s2.begin();
|
|
|
|
|
unsigned int i = 0;
|
|
|
|
|
while (i < len && p != s.end() && p2 != s2.end()) {
|
|
|
|
|
int const lc1 = tolower(*p);
|
|
|
|
|
int const lc2 = tolower(*p2);
|
|
|
|
|
if (lc1 != lc2)
|
|
|
|
|
return (lc1 < lc2) ? -1 : 1;
|
|
|
|
|
++i;
|
|
|
|
|
++p;
|
|
|
|
|
++p2;
|
|
|
|
|
}
|
2000-12-13 13:30:36 +00:00
|
|
|
|
|
|
|
|
|
if (s.size() >= len && s2.size() >= len)
|
1999-12-19 22:35:36 +00:00
|
|
|
|
return 0;
|
|
|
|
|
if (s.size() < s2.size())
|
|
|
|
|
return -1;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
if (str.length() > 2 and str[0] == '0' &&
|
|
|
|
|
(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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
char lowercase(char c)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
return char(toupper(c));
|
2000-07-24 13:53:19 +00:00
|
|
|
|
}
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
2006-09-03 14:09:24 +00:00
|
|
|
|
// FIXME for lowercase() and uppercase() function below:
|
|
|
|
|
// 1) std::tolower() and std::toupper() are templates that
|
|
|
|
|
// compile fine with char_type. With the test (c >= 256) we
|
|
|
|
|
// do not trust these function to do the right thing with
|
|
|
|
|
// unicode char.
|
|
|
|
|
// 2) these functions use the current locale, which is wrong
|
|
|
|
|
// if it is not latin1 based (latin1 is a subset of UCS4).
|
|
|
|
|
|
|
|
|
|
char_type lowercase(char_type c)
|
|
|
|
|
{
|
|
|
|
|
if (c >= 256)
|
|
|
|
|
return c;
|
2006-09-09 22:27:22 +00:00
|
|
|
|
|
2006-09-03 14:09:24 +00:00
|
|
|
|
return tolower(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char_type uppercase(char_type c)
|
|
|
|
|
{
|
|
|
|
|
if (c >= 256)
|
|
|
|
|
return c;
|
|
|
|
|
|
|
|
|
|
return toupper(c);
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
struct local_lowercase {
|
|
|
|
|
char operator()(char c) const {
|
|
|
|
|
return tolower(c);
|
|
|
|
|
}
|
|
|
|
|
};
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-04-25 19:33:52 +00:00
|
|
|
|
struct local_uppercase {
|
|
|
|
|
char operator()(char c) const {
|
|
|
|
|
return toupper(c);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2002-07-16 21:17:10 +00:00
|
|
|
|
struct local_ascii_lowercase {
|
|
|
|
|
char operator()(char c) const {
|
|
|
|
|
return ascii_tolower(c);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2001-04-25 19:33:52 +00:00
|
|
|
|
} // end of anon namespace
|
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
|
string const lowercase(string const & a)
|
1999-10-02 16:21:10 +00:00
|
|
|
|
{
|
1999-12-15 06:12:28 +00:00
|
|
|
|
string tmp(a);
|
2001-04-25 19:33:52 +00:00
|
|
|
|
transform(tmp.begin(), tmp.end(), tmp.begin(), local_lowercase());
|
1999-12-15 06:12:28 +00:00
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
|
string const uppercase(string const & a)
|
1999-12-15 06:12:28 +00:00
|
|
|
|
{
|
|
|
|
|
string 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(),
|
|
|
|
|
local_ascii_lowercase());
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This function escapes 8-bit characters and other problematic
|
|
|
|
|
// characters that cause problems in latex labels.
|
2006-10-19 16:51:30 +00:00
|
|
|
|
docstring const escape(docstring const & lab)
|
2001-06-27 14:10:35 +00:00
|
|
|
|
{
|
2006-10-19 16:51:30 +00:00
|
|
|
|
lyx::char_type hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
2001-06-27 14:10:35 +00:00
|
|
|
|
'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-10-21 00:16:43 +00:00
|
|
|
|
lyx::char_type c = lab[i];
|
2006-10-19 16:51:30 +00:00
|
|
|
|
// FIXME We must change the following algorithm for UCS4
|
|
|
|
|
// chars, but that will be a file format change.
|
2001-06-27 14:10:35 +00:00
|
|
|
|
if (c >= 128 || c == '=' || c == '%') {
|
|
|
|
|
enc += '=';
|
|
|
|
|
enc += hexdigit[c>>4];
|
|
|
|
|
enc += hexdigit[c & 15];
|
|
|
|
|
} else {
|
|
|
|
|
enc += c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return enc;
|
|
|
|
|
}
|
2002-04-15 12:05:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// gives a vector of stringparts which have the delimiter delim
|
|
|
|
|
vector<string> const getVectorFromString(string const & str,
|
|
|
|
|
string const & delim)
|
|
|
|
|
{
|
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
|
2002-11-04 00:15:56 +00:00
|
|
|
|
vector<string> vec;
|
|
|
|
|
if (str.empty())
|
|
|
|
|
return vec;
|
2005-07-14 22:09:22 +00:00
|
|
|
|
string keys = rtrim(str);
|
2002-11-04 00:15:56 +00:00
|
|
|
|
for(;;) {
|
|
|
|
|
string::size_type const idx = keys.find(delim);
|
|
|
|
|
if (idx == string::npos) {
|
|
|
|
|
vec.push_back(ltrim(keys));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
string const key = trim(keys.substr(0, idx));
|
|
|
|
|
if (!key.empty())
|
|
|
|
|
vec.push_back(key);
|
|
|
|
|
string::size_type const start = idx + delim.size();
|
|
|
|
|
keys = keys.substr(start);
|
2002-04-15 12:05:07 +00:00
|
|
|
|
}
|
2002-11-04 00:15:56 +00:00
|
|
|
|
return vec;
|
|
|
|
|
#else
|
|
|
|
|
boost::char_separator<char> sep(delim.c_str());
|
|
|
|
|
boost::tokenizer<boost::char_separator<char> > tokens(str, sep);
|
|
|
|
|
return vector<string>(tokens.begin(), tokens.end());
|
|
|
|
|
#endif
|
2002-04-15 12:05:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|