2002-09-25 10:03:41 +00:00
|
|
|
|
/**
|
Rename files in src/support, step one.
src/support/package.h src/support/Package.h Package
src/support/package.C.in src/support/Package.C.in Package
src/support/path.h src/support/Path.h Path
src/support/fs_extras.h src/support/fs_extras.h NOCLASSES
src/support/RandomAccessList.h src/support/RandomAccessList.h RandomAccessList
src/support/lyxmanip.h src/support/lyxmanip.h NOCLASSES
src/support/rename.C src/support/rename.cpp NOCLASSES
src/support/abort.C src/support/abort.cpp NOCLASSES
src/support/lyxlib.h src/support/lyxlib.h NOCLASSES
src/support/ExceptionMessage.h src/support/ExceptionMessage.h ExceptionMessage
src/support/copy.C src/support/copy.cpp NOCLASSES
src/support/limited_stack.h src/support/limited_stack.h limited_stack
src/support/filefilterlist.C src/support/FileFilterList.cpp ['FileFilterList', 'Filter']
src/support/cow_ptr.h src/support/cow_ptr.h cow_ptr
src/support/os_unix.C src/support/os_unix.cpp NOCLASSES
src/support/socktools.h src/support/socktools.h NOCLASSES
src/support/forkedcontr.h src/support/ForkedcallsController.h ForkedcallsController
src/support/os.h src/support/os.h NOCLASSES
src/support/FileMonitor.h src/support/FileMonitor.h FileMonitor
src/support/copied_ptr.h src/support/copied_ptr.h copied_ptr
src/support/translator.h src/support/Translator.h Translator
src/support/filetools.C src/support/filetools.cpp NOCLASSES
src/support/unlink.C src/support/unlink.cpp NOCLASSES
src/support/os_win32.C src/support/os_win32.cpp GetFolderPath
src/support/lstrings.C src/support/lstrings.cpp NOCLASSES
src/support/qstring_helpers.C src/support/qstring_helpers.cpp NOCLASSES
src/support/getcwd.C src/support/getcwd.cpp NOCLASSES
src/support/systemcall.C src/support/Systemcall.cpp Systemcall
src/support/lyxalgo.h src/support/lyxalgo.h NOCLASSES
src/support/filefilterlist.h src/support/FileFilterList.h ['FileFilterList', 'Filter']
src/support/unicode.C src/support/unicode.cpp IconvProcessor
src/support/userinfo.C src/support/userinfo.cpp NOCLASSES
src/support/lyxtime.C src/support/lyxtime.cpp NOCLASSES
src/support/kill.C src/support/kill.cpp NOCLASSES
src/support/docstring.C src/support/docstring.cpp to_local8bit_failure
src/support/os_cygwin.C src/support/os_cygwin.cpp NOCLASSES
src/support/lyxsum.C src/support/lyxsum.cpp NOCLASSES
src/support/environment.C src/support/environment.cpp NOCLASSES
src/support/filetools.h src/support/filetools.h NOCLASSES
src/support/textutils.C src/support/textutils.cpp NOCLASSES
src/support/mkdir.C src/support/mkdir.cpp NOCLASSES
src/support/forkedcall.C src/support/Forkedcall.cpp ['ForkedProcess', 'Forkedcall']
src/support/tempname.C src/support/tempname.cpp NOCLASSES
src/support/os_win32.h src/support/os_win32.h GetFolderPath
src/support/types.h src/support/types.h NOCLASSES
src/support/lstrings.h src/support/lstrings.h NOCLASSES
src/support/forkedcallqueue.C src/support/ForkedCallQueue.cpp ForkedCallQueue
src/support/qstring_helpers.h src/support/qstring_helpers.h NOCLASSES
src/support/convert.C src/support/convert.cpp NOCLASSES
src/support/filename.C src/support/FileName.cpp ['FileName', 'DocFileName']
src/support/tests/convert.C src/support/tests/convert.cpp NOCLASSES
src/support/tests/filetools.C src/support/tests/filetools.cpp NOCLASSES
src/support/tests/lstrings.C src/support/tests/lstrings.cpp NOCLASSES
src/support/tests/boost.C src/support/tests/boost.cpp NOCLASSES
src/support/docstream.C src/support/docstream.cpp ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/std_istream.h src/support/std_istream.h NOCLASSES
src/support/systemcall.h src/support/Systemcall.h Systemcall
src/support/chdir.C src/support/chdir.cpp NOCLASSES
src/support/std_ostream.h src/support/std_ostream.h NOCLASSES
src/support/unicode.h src/support/unicode.h IconvProcessor
src/support/path.C src/support/Path.cpp Path
src/support/fs_extras.C src/support/fs_extras.cpp NOCLASSES
src/support/userinfo.h src/support/userinfo.h NOCLASSES
src/support/lyxtime.h src/support/lyxtime.h NOCLASSES
src/support/docstring.h src/support/docstring.h to_local8bit_failure
src/support/debugstream.h src/support/debugstream.h basic_debugstream
src/support/environment.h src/support/environment.h NOCLASSES
src/support/textutils.h src/support/textutils.h NOCLASSES
src/support/forkedcall.h src/support/Forkedcall.h ['ForkedProcess', 'Forkedcall']
src/support/socktools.C src/support/socktools.cpp NOCLASSES
src/support/forkedcallqueue.h src/support/ForkedCallQueue.h ForkedCallQueue
src/support/forkedcontr.C src/support/ForkedcallsController.cpp ForkedcallsController
src/support/os.C src/support/os.cpp NOCLASSES
src/support/convert.h src/support/convert.h NOCLASSES
src/support/filename.h src/support/FileName.h ['FileName', 'DocFileName']
src/support/docstream.h src/support/docstream.h ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/FileMonitor.C src/support/FileMonitor.cpp FileMonitor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18024 a592a061-630c-0410-9148-cb99ea01b6c8
2007-04-26 05:12:52 +00:00
|
|
|
|
* \file lstrings.cpp
|
2002-09-25 10:03:41 +00:00
|
|
|
|
* 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
|
2008-04-20 20:32:00 +00:00
|
|
|
|
* \author Dekel Tsur
|
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"
|
2007-11-08 00:09:58 +00:00
|
|
|
|
|
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"
|
2007-11-08 00:09:58 +00:00
|
|
|
|
#include "support/textutils.h"
|
2004-11-07 13:22:51 +00:00
|
|
|
|
|
2002-11-04 00:15:56 +00:00
|
|
|
|
#include <boost/tokenizer.hpp>
|
2008-04-10 21:49:34 +00:00
|
|
|
|
#include "support/assert.h"
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2008-04-20 20:32:00 +00:00
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QVector>
|
|
|
|
|
|
2004-11-07 13:22:51 +00:00
|
|
|
|
#include <algorithm>
|
2004-07-24 10:55:30 +00:00
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
namespace lyx {
|
2007-11-08 00:09:58 +00:00
|
|
|
|
|
2007-11-30 20:57:53 +00:00
|
|
|
|
// Using this allows us to have docstring default arguments in headers
|
|
|
|
|
// without #include "support/docstring" there.
|
|
|
|
|
docstring const & empty_docstring()
|
|
|
|
|
{
|
|
|
|
|
static docstring s;
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
// Using this allows us to have string default arguments in headers
|
2007-11-30 20:57:53 +00:00
|
|
|
|
// without #include <string>
|
2007-12-12 19:28:07 +00:00
|
|
|
|
string const & empty_string()
|
2007-11-30 20:57:53 +00:00
|
|
|
|
{
|
2007-12-12 19:28:07 +00:00
|
|
|
|
static string s;
|
2007-11-30 20:57:53 +00:00
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-08 00:09:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* Convert a QChar into a UCS4 character.
|
|
|
|
|
* This is a hack (it does only make sense for the common part of the UCS4
|
|
|
|
|
* and UTF16 encodings) and should not be used.
|
|
|
|
|
* This does only exist because of performance reasons (a real conversion
|
|
|
|
|
* using iconv is too slow on windows).
|
|
|
|
|
*/
|
|
|
|
|
static inline char_type qchar_to_ucs4(QChar const & qchar)
|
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(is_utf16(static_cast<char_type>(qchar.unicode())), /**/);
|
2007-11-08 00:09:58 +00:00
|
|
|
|
return static_cast<char_type>(qchar.unicode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert a UCS4 character into a QChar.
|
|
|
|
|
* This is a hack (it does only make sense for the common part of the UCS4
|
|
|
|
|
* and UTF16 encodings) and should not be used.
|
|
|
|
|
* This does only exist because of performance reasons (a real conversion
|
|
|
|
|
* using iconv is too slow on windows).
|
|
|
|
|
*/
|
|
|
|
|
static inline QChar const ucs4_to_qchar(char_type const ucs4)
|
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(is_utf16(ucs4), /**/);
|
2007-11-08 00:09:58 +00:00
|
|
|
|
return QChar(static_cast<unsigned short>(ucs4));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
/// Maximum valid UCS4 code point
|
|
|
|
|
char_type const ucs4_max = 0x10ffff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isLetterChar(char_type c)
|
|
|
|
|
{
|
|
|
|
|
if (!is_utf16(c)) {
|
|
|
|
|
if (c > ucs4_max)
|
|
|
|
|
// outside the UCS4 range
|
|
|
|
|
return false;
|
|
|
|
|
// assume that all non-utf16 characters are letters
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return ucs4_to_qchar(c).isLetter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isAlphaASCII(char_type c)
|
|
|
|
|
{
|
|
|
|
|
return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isPrintable(char_type c)
|
|
|
|
|
{
|
|
|
|
|
if (!is_utf16(c)) {
|
|
|
|
|
if (c > ucs4_max)
|
|
|
|
|
// outside the UCS4 range
|
|
|
|
|
return false;
|
|
|
|
|
// assume that all non-utf16 characters are printable
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return ucs4_to_qchar(c).isPrint();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isPrintableNonspace(char_type c)
|
|
|
|
|
{
|
|
|
|
|
if (!is_utf16(c)) {
|
|
|
|
|
if (c > ucs4_max)
|
|
|
|
|
// outside the UCS4 range
|
|
|
|
|
return false;
|
|
|
|
|
// assume that all non-utf16 characters are printable and
|
|
|
|
|
// no space
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
QChar const qc = ucs4_to_qchar(c);
|
|
|
|
|
return qc.isPrint() && !qc.isSpace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isSpace(char_type c)
|
|
|
|
|
{
|
|
|
|
|
if (!is_utf16(c)) {
|
|
|
|
|
// assume that no non-utf16 character is a space
|
|
|
|
|
// c outside the UCS4 range is catched as well
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QChar const qc = ucs4_to_qchar(c);
|
|
|
|
|
return qc.isSpace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isDigit(char_type c)
|
|
|
|
|
{
|
|
|
|
|
if (!is_utf16(c))
|
|
|
|
|
// assume that no non-utf16 character is a digit
|
|
|
|
|
// c outside the UCS4 range is catched as well
|
|
|
|
|
return false;
|
|
|
|
|
return ucs4_to_qchar(c).isDigit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isDigitASCII(char_type c)
|
|
|
|
|
{
|
|
|
|
|
return '0' <= c && c <= '9';
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2007-11-30 20:57:53 +00:00
|
|
|
|
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);
|
2007-11-30 20:57:53 +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();
|
2007-11-30 20:57:53 +00:00
|
|
|
|
if ((*cit) == '-')
|
|
|
|
|
++cit;
|
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
|
string::const_iterator end = tmpstr.end();
|
2007-11-30 20:57:53 +00:00
|
|
|
|
for (; cit != end; ++cit)
|
|
|
|
|
if (!isdigit((*cit)))
|
|
|
|
|
return false;
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-12-04 17:18:01 +00:00
|
|
|
|
bool isStrUnsignedInt(string const & str)
|
|
|
|
|
{
|
2007-11-30 20:57:53 +00:00
|
|
|
|
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);
|
2007-11-30 20:57:53 +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();
|
2007-11-30 20:57:53 +00:00
|
|
|
|
for (; cit != end; ++cit)
|
|
|
|
|
if (!isdigit((*cit)))
|
|
|
|
|
return false;
|
|
|
|
|
|
2000-12-04 17:18:01 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
bool isStrDbl(string const & str)
|
|
|
|
|
{
|
2007-11-30 20:57:53 +00:00
|
|
|
|
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);
|
2007-11-30 20:57:53 +00:00
|
|
|
|
if (tmpstr.empty())
|
|
|
|
|
return false;
|
|
|
|
|
// if (tmpstr.count('.') > 1) return false;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
|
|
string::const_iterator cit = tmpstr.begin();
|
2007-11-30 20:57:53 +00:00
|
|
|
|
bool found_dot = false;
|
|
|
|
|
if (*cit == '-')
|
|
|
|
|
++cit;
|
2000-08-03 21:17:52 +00:00
|
|
|
|
string::const_iterator end = tmpstr.end();
|
|
|
|
|
for (; cit != end; ++cit) {
|
2007-11-30 20:57:53 +00:00
|
|
|
|
if (!isdigit(*cit) && *cit != '.')
|
2000-06-12 11:27:15 +00:00
|
|
|
|
return false;
|
|
|
|
|
if ('.' == (*cit)) {
|
2007-11-30 20:57:53 +00:00
|
|
|
|
if (found_dot)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
return false;
|
2007-11-30 20:57:53 +00:00
|
|
|
|
found_dot = true;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-08-03 21:17:52 +00:00
|
|
|
|
|
2007-11-30 20:57:53 +00:00
|
|
|
|
static bool isHexChar(char_type c)
|
2006-10-22 18:47:19 +00:00
|
|
|
|
{
|
|
|
|
|
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';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
2007-07-06 15:50:39 +00:00
|
|
|
|
if (str[i] >= 0x80)
|
2007-07-06 14:43:18 +00:00
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isAscii(string const & str)
|
|
|
|
|
{
|
|
|
|
|
int const len = str.length();
|
|
|
|
|
for (int i = 0; i < len; ++i)
|
|
|
|
|
if (static_cast<unsigned char>(str[i]) >= 0x80)
|
2006-11-11 12:00:34 +00:00
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
char lowercase(char c)
|
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(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)
|
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(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 {
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
// since we cannot use tolower and toupper directly in the
|
|
|
|
|
// calls to transform yet, we use these helper clases. (Lgb)
|
2001-04-25 19:33:52 +00:00
|
|
|
|
|
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 {
|
2007-11-10 13:44:50 +00:00
|
|
|
|
Char operator()(Char c) const { return ascii_tolower(c); }
|
2002-07-16 21:17:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2007-11-10 13:44:50 +00:00
|
|
|
|
size_t const prelen = pre.length();
|
|
|
|
|
size_t const alen = a.length();
|
2008-02-01 17:04:59 +00:00
|
|
|
|
return prelen <= alen && !a.empty() && a.compare(0, prelen, pre) == 0;
|
2000-09-26 13:54:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-20 16:12:49 +00:00
|
|
|
|
bool prefixIs(docstring const & a, docstring const & pre)
|
|
|
|
|
{
|
2007-11-10 13:44:50 +00:00
|
|
|
|
size_t const prelen = pre.length();
|
|
|
|
|
size_t const alen = a.length();
|
2008-02-01 17:04:59 +00:00
|
|
|
|
return prelen <= alen && !a.empty() && a.compare(0, prelen, pre) == 0;
|
2006-10-20 16:12:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2007-11-10 13:44:50 +00:00
|
|
|
|
size_t const suflen = suf.length();
|
|
|
|
|
size_t const alen = a.length();
|
2008-02-01 17:04:59 +00:00
|
|
|
|
return suflen <= alen && a.compare(alen - suflen, suflen, suf) == 0;
|
2000-09-26 13:54:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2007-11-10 13:44:50 +00:00
|
|
|
|
if (a.empty())
|
|
|
|
|
return string();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2007-11-10 13:44:50 +00:00
|
|
|
|
size_t k = 0;
|
|
|
|
|
size_t i = 0;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
|
|
// Find delimiter or end of string
|
2007-11-10 13:44:50 +00:00
|
|
|
|
for (; n--;) {
|
1999-10-02 16:21:10 +00:00
|
|
|
|
if ((i = a.find(delim, i)) == string::npos)
|
|
|
|
|
break;
|
|
|
|
|
else
|
|
|
|
|
++i; // step delim
|
2007-11-10 13:44:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
// i is now the n'th delim (or string::npos)
|
2007-11-10 13:44:50 +00:00
|
|
|
|
if (i == string::npos)
|
|
|
|
|
return string();
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2007-11-30 20:57:53 +00:00
|
|
|
|
if (a.empty())
|
|
|
|
|
return docstring();
|
2006-09-09 22:27:22 +00:00
|
|
|
|
|
2007-11-10 13:44:50 +00:00
|
|
|
|
size_t k = 0;
|
|
|
|
|
size_t i = 0;
|
2006-09-09 22:27:22 +00:00
|
|
|
|
|
|
|
|
|
// Find delimiter or end of string
|
2007-11-10 13:44:50 +00:00
|
|
|
|
for (; n--;) {
|
2006-09-09 22:27:22 +00:00
|
|
|
|
if ((i = a.find(delim, i)) == docstring::npos)
|
|
|
|
|
break;
|
|
|
|
|
else
|
|
|
|
|
++i; // step delim
|
2007-11-10 13:44:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-09 22:27:22 +00:00
|
|
|
|
// i is now the n'th delim (or string::npos)
|
2007-11-10 13:44:50 +00:00
|
|
|
|
if (i == docstring::npos)
|
|
|
|
|
return docstring();
|
|
|
|
|
|
2006-09-09 22:27:22 +00:00
|
|
|
|
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;
|
2007-11-10 13:44:50 +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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-04-19 15:52:35 +00:00
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
2007-12-12 19:28:07 +00:00
|
|
|
|
basic_string<Ch> const subst_char(basic_string<Ch> const & a,
|
2006-09-03 14:09:24 +00:00
|
|
|
|
Ch oldchar, Ch newchar)
|
1999-10-02 16:21:10 +00:00
|
|
|
|
{
|
2007-12-12 19:28:07 +00:00
|
|
|
|
typedef basic_string<Ch> String;
|
2006-09-03 07:02:38 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-31 22:40:34 +00:00
|
|
|
|
/// Substitute all \a oldchar with \a newchar
|
|
|
|
|
docstring const subst_char(docstring const & a,
|
|
|
|
|
docstring::value_type oldchar, docstring::value_type newchar)
|
|
|
|
|
{
|
|
|
|
|
docstring tmp(a);
|
|
|
|
|
docstring::iterator lit = tmp.begin();
|
|
|
|
|
docstring::iterator end = tmp.end();
|
|
|
|
|
for (; lit != end; ++lit)
|
|
|
|
|
if ((*lit) == oldchar)
|
|
|
|
|
(*lit) = newchar;
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
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
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(!oldstr.empty(), /**/);
|
2006-09-03 07:02:38 +00:00
|
|
|
|
String lstr = a;
|
2007-11-10 13:44:50 +00:00
|
|
|
|
size_t i = 0;
|
|
|
|
|
size_t 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;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-31 22:40:34 +00:00
|
|
|
|
docstring const subst_string(docstring const & a,
|
|
|
|
|
docstring const & oldstr, docstring const & newstr)
|
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(!oldstr.empty(), /**/);
|
2007-10-31 22:40:34 +00:00
|
|
|
|
docstring lstr = a;
|
2007-11-10 13:44:50 +00:00
|
|
|
|
size_t i = 0;
|
|
|
|
|
size_t const olen = oldstr.length();
|
2007-10-31 22:40:34 +00:00
|
|
|
|
while ((i = lstr.find(oldstr, i)) != string::npos) {
|
|
|
|
|
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)
|
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(p, /**/);
|
2006-10-09 09:15:37 +00:00
|
|
|
|
|
|
|
|
|
if (a.empty() || !*p)
|
|
|
|
|
return a;
|
|
|
|
|
|
2007-11-10 13:44:50 +00:00
|
|
|
|
docstring s = from_ascii(p);
|
|
|
|
|
size_t r = a.find_last_not_of(s);
|
|
|
|
|
size_t l = a.find_first_not_of(s);
|
2006-10-09 09:15:37 +00:00
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(p, /**/);
|
2002-07-28 18:13:51 +00:00
|
|
|
|
|
2002-07-28 22:50:13 +00:00
|
|
|
|
if (a.empty() || !*p)
|
|
|
|
|
return a;
|
|
|
|
|
|
2007-11-10 13:44:50 +00:00
|
|
|
|
size_t r = a.find_last_not_of(p);
|
|
|
|
|
size_t l = a.find_first_not_of(p);
|
2002-07-28 22:50:13 +00:00
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(p, /**/);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2002-07-28 22:50:13 +00:00
|
|
|
|
if (a.empty() || !*p)
|
|
|
|
|
return a;
|
|
|
|
|
|
2007-11-10 13:44:50 +00:00
|
|
|
|
size_t r = a.find_last_not_of(p);
|
2002-07-28 22:50:13 +00:00
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(p, /**/);
|
2006-12-17 10:52:04 +00:00
|
|
|
|
|
|
|
|
|
if (a.empty() || !*p)
|
|
|
|
|
return a;
|
|
|
|
|
|
2007-11-10 13:44:50 +00:00
|
|
|
|
size_t r = a.find_last_not_of(from_ascii(p));
|
2006-12-17 10:52:04 +00:00
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(p, /**/);
|
2002-07-28 22:50:13 +00:00
|
|
|
|
if (a.empty() || !*p)
|
|
|
|
|
return a;
|
2007-11-10 13:44:50 +00:00
|
|
|
|
size_t l = a.find_first_not_of(p);
|
2002-07-28 22:50:13 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(p, /**/);
|
2006-10-22 10:15:23 +00:00
|
|
|
|
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;
|
2007-11-10 13:44:50 +00:00
|
|
|
|
size_t 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;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-31 22:40:34 +00:00
|
|
|
|
template<typename Char> inline
|
|
|
|
|
docstring const doSplit(docstring const & a, docstring & piece, Char delim)
|
|
|
|
|
{
|
|
|
|
|
docstring tmp;
|
2007-11-10 13:44:50 +00:00
|
|
|
|
size_t i = a.find(delim);
|
2007-10-31 22:40:34 +00:00
|
|
|
|
if (i == a.length() - 1) {
|
|
|
|
|
piece = a.substr(0, i);
|
|
|
|
|
} else if (i != docstring::npos) {
|
|
|
|
|
piece = a.substr(0, i);
|
|
|
|
|
tmp = a.substr(i + 1);
|
|
|
|
|
} else if (i == 0) {
|
|
|
|
|
piece.erase();
|
|
|
|
|
tmp = a.substr(i + 1);
|
|
|
|
|
} else {
|
|
|
|
|
piece = a;
|
|
|
|
|
}
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-08 00:09:58 +00:00
|
|
|
|
} // anon
|
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;
|
2007-11-10 13:44:50 +00:00
|
|
|
|
size_t i = a.find(delim);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
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;
|
2007-11-10 13:44:50 +00:00
|
|
|
|
size_t i = a.rfind(delim);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
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',
|
2007-05-28 22:27:45 +00:00
|
|
|
|
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
2006-10-19 16:51:30 +00:00
|
|
|
|
docstring enc;
|
2007-11-10 13:44:50 +00:00
|
|
|
|
for (size_t 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.
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(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);
|
2007-11-10 13:44:50 +00:00
|
|
|
|
while (true) {
|
|
|
|
|
size_t const idx = keys.find(delim);
|
2006-12-17 10:52:04 +00:00
|
|
|
|
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);
|
2007-11-10 13:44:50 +00:00
|
|
|
|
size_t 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
|
|
|
|
}
|
|
|
|
|
|
2007-11-10 13:44:50 +00:00
|
|
|
|
} // namespace anon
|
2006-12-17 10:52:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<string> const getVectorFromString(string const & str,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
string const & delim)
|
2006-12-17 10:52:04 +00:00
|
|
|
|
{
|
|
|
|
|
return getVectorFromStringT<string>(str, delim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<docstring> const getVectorFromString(docstring const & str,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
docstring const & delim)
|
2006-12-17 10:52:04 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
2007-11-10 13:44:50 +00:00
|
|
|
|
return subst(str, from_ascii("\n"), 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
|
|
|
|
{
|
2007-11-10 13:44:50 +00:00
|
|
|
|
docstring const s = subst(str, from_ascii("\r\n"), from_ascii("\n"));
|
2006-06-20 08:39:16 +00:00
|
|
|
|
return subst(s, '\r', '\n');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring bformat(docstring const & fmt, int arg1)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
|
2007-11-10 13:44:50 +00:00
|
|
|
|
docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
|
|
|
|
|
return subst(str, from_ascii("%%"), 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
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
|
2007-11-10 13:44:50 +00:00
|
|
|
|
docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
|
|
|
|
|
return subst(str, from_ascii("%%"), 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
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
|
2007-11-10 13:44:50 +00:00
|
|
|
|
docstring const str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
|
|
|
|
|
return subst(str, from_ascii("%%"), 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
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
|
2007-11-10 13:44:50 +00:00
|
|
|
|
docstring const str = subst(fmt, from_ascii("%1$s"), arg1);
|
|
|
|
|
return subst(str, from_ascii("%%"), 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
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
|
2007-11-10 13:44:50 +00:00
|
|
|
|
docstring const str = subst(fmt, from_ascii("%1$s"), from_ascii(arg1));
|
|
|
|
|
return subst(str, from_ascii("%%"), 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
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
|
|
|
|
|
LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
|
2007-11-10 13:44:50 +00:00
|
|
|
|
docstring str = subst(fmt, from_ascii("%1$s"), arg1);
|
|
|
|
|
str = subst(str, from_ascii("%2$s"), arg2);
|
|
|
|
|
return subst(str, from_ascii("%%"), 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
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
|
|
|
|
|
LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
|
2007-11-10 13:44:50 +00:00
|
|
|
|
docstring str = subst(fmt, from_ascii("%1$s"), from_ascii(arg1));
|
|
|
|
|
str = subst(fmt, from_ascii("%2$s"), arg2);
|
|
|
|
|
return subst(str, from_ascii("%%"), 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
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(contains(fmt, from_ascii("%1$d")), /**/);
|
|
|
|
|
LASSERT(contains(fmt, from_ascii("%2$d")), /**/);
|
2007-11-10 13:44:50 +00:00
|
|
|
|
docstring str = subst(fmt, from_ascii("%1$d"), convert<docstring>(arg1));
|
|
|
|
|
str = subst(str, from_ascii("%2$d"), convert<docstring>(arg2));
|
|
|
|
|
return subst(str, from_ascii("%%"), 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
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
|
|
|
|
|
LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
|
|
|
|
|
LASSERT(contains(fmt, from_ascii("%3$s")), /**/);
|
2007-11-10 13:44:50 +00:00
|
|
|
|
docstring str = subst(fmt, from_ascii("%1$s"), arg1);
|
|
|
|
|
str = subst(str, from_ascii("%2$s"), arg2);
|
|
|
|
|
str = subst(str, from_ascii("%3$s"), arg3);
|
|
|
|
|
return subst(str, from_ascii("%%"), 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)
|
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(contains(fmt, from_ascii("%1$s")), /**/);
|
|
|
|
|
LASSERT(contains(fmt, from_ascii("%2$s")), /**/);
|
|
|
|
|
LASSERT(contains(fmt, from_ascii("%3$s")), /**/);
|
|
|
|
|
LASSERT(contains(fmt, from_ascii("%4$s")), /**/);
|
2007-11-10 13:44:50 +00:00
|
|
|
|
docstring str = subst(fmt, from_ascii("%1$s"), arg1);
|
|
|
|
|
str = subst(str, from_ascii("%2$s"), arg2);
|
|
|
|
|
str = subst(str, from_ascii("%3$s"), arg3);
|
|
|
|
|
str = subst(str, from_ascii("%4$s"), arg4);
|
|
|
|
|
return subst(str, from_ascii("%%"), from_ascii("%"));
|
2003-06-30 15:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
} // namespace support
|
|
|
|
|
} // namespace lyx
|