2003-06-18 09:56:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file tostr.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
2003-07-28 22:37:28 +00:00
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
2004-09-04 12:13:50 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2003-06-18 09:56:10 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-06-18 09:56:10 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2003-05-13 14:36:24 +00:00
|
|
|
|
#include <config.h>
|
2003-09-09 18:27:24 +00:00
|
|
|
|
|
2005-01-06 16:39:35 +00:00
|
|
|
|
#include "convert.h"
|
2004-09-04 12:13:50 +00:00
|
|
|
|
|
2006-09-09 22:27:22 +00:00
|
|
|
|
#include "support/docstring.h"
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
#include <boost/lexical_cast.hpp>
|
2004-09-04 12:13:50 +00:00
|
|
|
|
|
2005-01-07 13:32:26 +00:00
|
|
|
|
#include <string>
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2006-09-09 22:27:22 +00:00
|
|
|
|
using lyx::docstring;
|
|
|
|
|
|
2004-09-04 12:13:50 +00:00
|
|
|
|
using boost::lexical_cast;
|
2003-05-13 14:36:24 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
|
2003-05-13 14:36:24 +00:00
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
|
|
|
|
string convert<string>(bool b)
|
2003-05-13 14:36:24 +00:00
|
|
|
|
{
|
|
|
|
|
return (b ? "true" : "false");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
|
|
|
|
string convert<string>(char c)
|
2003-05-13 14:36:24 +00:00
|
|
|
|
{
|
2005-01-06 15:40:49 +00:00
|
|
|
|
return string(1, c);
|
2003-05-13 14:36:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
|
|
|
|
string convert<string>(short unsigned int sui)
|
2003-05-14 07:54:12 +00:00
|
|
|
|
{
|
2005-01-06 15:40:49 +00:00
|
|
|
|
return lexical_cast<string>(sui);
|
2003-05-14 07:54:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
|
|
|
|
string convert<string>(int i)
|
2003-05-13 14:36:24 +00:00
|
|
|
|
{
|
2005-01-06 15:40:49 +00:00
|
|
|
|
return lexical_cast<string>(i);
|
2003-05-13 14:36:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-13 11:18:13 +00:00
|
|
|
|
|
2006-09-09 22:27:22 +00:00
|
|
|
|
template<>
|
|
|
|
|
docstring convert<docstring>(int i)
|
|
|
|
|
{
|
|
|
|
|
return lyx::from_ascii(lexical_cast<string>(i));
|
|
|
|
|
}
|
2003-05-13 14:36:24 +00:00
|
|
|
|
|
2006-09-13 11:18:13 +00:00
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
|
|
|
|
string convert<string>(unsigned int ui)
|
2003-05-13 14:36:24 +00:00
|
|
|
|
{
|
2005-01-06 15:40:49 +00:00
|
|
|
|
return lexical_cast<string>(ui);
|
2003-05-13 14:36:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-13 11:18:13 +00:00
|
|
|
|
template<>
|
|
|
|
|
docstring convert<docstring>(unsigned int ui)
|
|
|
|
|
{
|
|
|
|
|
return lyx::from_ascii(lexical_cast<string>(ui));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-07 13:32:26 +00:00
|
|
|
|
template<>
|
|
|
|
|
string convert<string>(unsigned long ul)
|
|
|
|
|
{
|
|
|
|
|
return lexical_cast<string>(ul);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-13 15:35:18 +00:00
|
|
|
|
template<>
|
|
|
|
|
docstring convert<docstring>(unsigned long ul)
|
|
|
|
|
{
|
|
|
|
|
return lyx::from_ascii(lexical_cast<string>(ul));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-07 17:54:12 +00:00
|
|
|
|
template<>
|
|
|
|
|
string convert<string>(long l)
|
|
|
|
|
{
|
|
|
|
|
return lexical_cast<string>(l);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-13 11:18:13 +00:00
|
|
|
|
template<>
|
|
|
|
|
docstring convert<docstring>(long l)
|
|
|
|
|
{
|
|
|
|
|
return lyx::from_ascii(lexical_cast<string>(l));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
|
|
|
|
string convert<string>(float f)
|
2003-05-13 14:36:24 +00:00
|
|
|
|
{
|
2005-01-06 15:40:49 +00:00
|
|
|
|
return lexical_cast<string>(f);
|
2003-05-13 14:36:24 +00:00
|
|
|
|
}
|
2004-01-07 16:40:30 +00:00
|
|
|
|
|
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
template<>
|
|
|
|
|
string convert<string>(double d)
|
2004-01-07 16:40:30 +00:00
|
|
|
|
{
|
2005-01-06 15:40:49 +00:00
|
|
|
|
return lexical_cast<string>(d);
|
2004-01-07 16:40:30 +00:00
|
|
|
|
}
|
2005-01-27 21:05:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
int convert<int>(string const s)
|
|
|
|
|
{
|
|
|
|
|
return strtol(s.c_str(), 0, 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-20 16:12:49 +00:00
|
|
|
|
template<>
|
|
|
|
|
int convert<int>(docstring const s)
|
|
|
|
|
{
|
|
|
|
|
return strtol(lyx::to_ascii(s).c_str(), 0, 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-27 21:05:44 +00:00
|
|
|
|
template<>
|
|
|
|
|
unsigned int convert<unsigned int>(string const s)
|
|
|
|
|
{
|
|
|
|
|
return strtoul(s.c_str(), 0, 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-05-17 08:31:00 +00:00
|
|
|
|
template<>
|
|
|
|
|
unsigned long convert<unsigned long>(string const s)
|
|
|
|
|
{
|
|
|
|
|
return strtoul(s.c_str(), 0, 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-27 21:05:44 +00:00
|
|
|
|
template<>
|
|
|
|
|
double convert<double>(string const s)
|
|
|
|
|
{
|
|
|
|
|
return strtod(s.c_str(), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
int convert<int>(char const * cptr)
|
|
|
|
|
{
|
|
|
|
|
return strtol(cptr, 0, 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
double convert<double>(char const * cptr)
|
|
|
|
|
{
|
|
|
|
|
return strtod(cptr, 0);
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|