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));
94 string convert<string>(long l)
96 return lexical_cast<string>(l);
101 docstring convert<docstring>(long l)
103 return from_ascii(lexical_cast<string>(l));
108 string convert<string>(float f)
110 std::ostringstream val;
117 string convert<string>(double d)
119 std::ostringstream val;
126 int convert<int>(string const s)
128 return strtol(s.c_str(), 0, 10);
133 int convert<int>(docstring const s)
135 return strtol(to_ascii(s).c_str(), 0, 10);
140 unsigned int convert<unsigned int>(string const s)
142 return strtoul(s.c_str(), 0, 10);
147 unsigned long convert<unsigned long>(string const s)
149 return strtoul(s.c_str(), 0, 10);
154 double convert<double>(string const s)
156 return strtod(s.c_str(), 0);
161 int convert<int>(char const * cptr)
163 return strtol(cptr, 0, 10);
168 double convert<double>(char const * cptr)
170 return strtod(cptr, 0);