2003-06-18 09:56:10 +00:00
|
|
|
|
/**
|
2007-11-10 13:44:50 +00:00
|
|
|
|
* \file convert.cpp
|
2003-06-18 09:56:10 +00:00
|
|
|
|
* 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
|
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/convert.h"
|
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>
|
2008-03-29 01:45:24 +00:00
|
|
|
|
#include <cstdlib>
|
2005-01-07 13:32:26 +00:00
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2004-09-04 12:13:50 +00:00
|
|
|
|
using boost::lexical_cast;
|
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)
|
|
|
|
|
{
|
2007-11-10 13:44:50 +00:00
|
|
|
|
return from_ascii(lexical_cast<string>(i));
|
2006-09-09 22:27:22 +00:00
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
2007-11-10 13:44:50 +00:00
|
|
|
|
return from_ascii(lexical_cast<string>(ui));
|
2006-09-13 11:18:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2007-11-10 13:44:50 +00:00
|
|
|
|
return from_ascii(lexical_cast<string>(ul));
|
2006-10-13 15:35:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2007-11-10 13:44:50 +00:00
|
|
|
|
return from_ascii(lexical_cast<string>(l));
|
2006-09-13 11:18:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2007-11-10 13:44:50 +00:00
|
|
|
|
return strtol(to_ascii(s).c_str(), 0, 10);
|
2006-10-20 16:12:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|