3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
14 #include "support/convert.h"
15 #include "support/docstring.h"
17 #include <boost/lexical_cast.hpp>
21 //needed for Mac OSX 10.5.2 Leopard
28 using boost::lexical_cast;
31 string convert<string>(bool b)
33 return (b ? "true" : "false");
38 string convert<string>(char c)
45 string convert<string>(short unsigned int sui)
47 return lexical_cast<string>(sui);
52 string convert<string>(int i)
54 return lexical_cast<string>(i);
59 docstring convert<docstring>(int i)
61 return from_ascii(lexical_cast<string>(i));
66 string convert<string>(unsigned int ui)
68 return lexical_cast<string>(ui);
73 docstring convert<docstring>(unsigned int ui)
75 return from_ascii(lexical_cast<string>(ui));
80 string convert<string>(unsigned long ul)
82 return lexical_cast<string>(ul);
87 docstring convert<docstring>(unsigned long ul)
89 return from_ascii(lexical_cast<string>(ul));
93 #ifdef LYX_USE_LONG_LONG
95 string convert<string>(unsigned long long ull)
97 return lexical_cast<string>(ull);
102 docstring convert<docstring>(unsigned long long ull)
104 return from_ascii(lexical_cast<string>(ull));
110 string convert<string>(long l)
112 return lexical_cast<string>(l);
117 docstring convert<docstring>(long l)
119 return from_ascii(lexical_cast<string>(l));
123 #ifdef LYX_USE_LONG_LONG
125 string convert<string>(long long ll)
127 return lexical_cast<string>(ll);
132 docstring convert<docstring>(long long ll)
134 return from_ascii(lexical_cast<string>(ll));
140 string convert<string>(float f)
142 std::ostringstream val;
149 string convert<string>(double d)
151 std::ostringstream val;
158 int convert<int>(string const s)
160 return strtol(s.c_str(), 0, 10);
165 int convert<int>(docstring const s)
167 return strtol(to_ascii(s).c_str(), 0, 10);
172 unsigned int convert<unsigned int>(string const s)
174 return strtoul(s.c_str(), 0, 10);
179 unsigned long convert<unsigned long>(string const s)
181 return strtoul(s.c_str(), 0, 10);
186 double convert<double>(string const s)
188 return strtod(s.c_str(), 0);
193 int convert<int>(char const * cptr)
195 return strtol(cptr, 0, 10);
200 double convert<double>(char const * cptr)
202 return strtod(cptr, 0);