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>
26 using boost::lexical_cast;
29 string convert<string>(bool b)
31 return (b ? "true" : "false");
36 string convert<string>(char c)
43 string convert<string>(short unsigned int sui)
45 return lexical_cast<string>(sui);
50 string convert<string>(int i)
52 return lexical_cast<string>(i);
57 docstring convert<docstring>(int i)
59 return from_ascii(lexical_cast<string>(i));
64 string convert<string>(unsigned int ui)
66 return lexical_cast<string>(ui);
71 docstring convert<docstring>(unsigned int ui)
73 return from_ascii(lexical_cast<string>(ui));
78 string convert<string>(unsigned long ul)
80 return lexical_cast<string>(ul);
85 docstring convert<docstring>(unsigned long ul)
87 return from_ascii(lexical_cast<string>(ul));
92 string convert<string>(long l)
94 return lexical_cast<string>(l);
99 docstring convert<docstring>(long l)
101 return from_ascii(lexical_cast<string>(l));
106 string convert<string>(float f)
108 return lexical_cast<string>(f);
113 string convert<string>(double d)
115 return lexical_cast<string>(d);
120 int convert<int>(string const s)
122 return strtol(s.c_str(), 0, 10);
127 int convert<int>(docstring const s)
129 return strtol(to_ascii(s).c_str(), 0, 10);
134 unsigned int convert<unsigned int>(string const s)
136 return strtoul(s.c_str(), 0, 10);
141 unsigned long convert<unsigned long>(string const s)
143 return strtoul(s.c_str(), 0, 10);
148 double convert<double>(string const s)
150 return strtod(s.c_str(), 0);
155 int convert<int>(char const * cptr)
157 return strtol(cptr, 0, 10);
162 double convert<double>(char const * cptr)
164 return strtod(cptr, 0);