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>
25 using boost::lexical_cast;
28 string convert<string>(bool b)
30 return (b ? "true" : "false");
35 string convert<string>(char c)
42 string convert<string>(short unsigned int sui)
44 return lexical_cast<string>(sui);
49 string convert<string>(int i)
51 return lexical_cast<string>(i);
56 docstring convert<docstring>(int i)
58 return from_ascii(lexical_cast<string>(i));
63 string convert<string>(unsigned int ui)
65 return lexical_cast<string>(ui);
70 docstring convert<docstring>(unsigned int ui)
72 return from_ascii(lexical_cast<string>(ui));
77 string convert<string>(unsigned long ul)
79 return lexical_cast<string>(ul);
84 docstring convert<docstring>(unsigned long ul)
86 return from_ascii(lexical_cast<string>(ul));
91 string convert<string>(long l)
93 return lexical_cast<string>(l);
98 docstring convert<docstring>(long l)
100 return from_ascii(lexical_cast<string>(l));
105 string convert<string>(float f)
107 return lexical_cast<string>(f);
112 string convert<string>(double d)
114 return lexical_cast<string>(d);
119 int convert<int>(string const s)
121 return strtol(s.c_str(), 0, 10);
126 int convert<int>(docstring const s)
128 return strtol(to_ascii(s).c_str(), 0, 10);
133 unsigned int convert<unsigned int>(string const s)
135 return strtoul(s.c_str(), 0, 10);
140 unsigned long convert<unsigned long>(string const s)
142 return strtoul(s.c_str(), 0, 10);
147 double convert<double>(string const s)
149 return strtod(s.c_str(), 0);
154 int convert<int>(char const * cptr)
156 return strtol(cptr, 0, 10);
161 double convert<double>(char const * cptr)
163 return strtod(cptr, 0);