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>
20 //needed for Mac OSX 10.5.2 Leopard
27 using boost::lexical_cast;
30 string convert<string>(bool b)
32 return (b ? "true" : "false");
37 string convert<string>(char c)
44 string convert<string>(short unsigned int sui)
46 return lexical_cast<string>(sui);
51 string convert<string>(int i)
53 return lexical_cast<string>(i);
58 docstring convert<docstring>(int i)
60 return from_ascii(lexical_cast<string>(i));
65 string convert<string>(unsigned int ui)
67 return lexical_cast<string>(ui);
72 docstring convert<docstring>(unsigned int ui)
74 return from_ascii(lexical_cast<string>(ui));
79 string convert<string>(unsigned long ul)
81 return lexical_cast<string>(ul);
86 docstring convert<docstring>(unsigned long ul)
88 return from_ascii(lexical_cast<string>(ul));
93 string convert<string>(long l)
95 return lexical_cast<string>(l);
100 docstring convert<docstring>(long l)
102 return from_ascii(lexical_cast<string>(l));
107 string convert<string>(float f)
109 return lexical_cast<string>(f);
114 string convert<string>(double d)
116 return lexical_cast<string>(d);
121 int convert<int>(string const s)
123 return strtol(s.c_str(), 0, 10);
128 int convert<int>(docstring const s)
130 return strtol(to_ascii(s).c_str(), 0, 10);
135 unsigned int convert<unsigned int>(string const s)
137 return strtoul(s.c_str(), 0, 10);
142 unsigned long convert<unsigned long>(string const s)
144 return strtoul(s.c_str(), 0, 10);
149 double convert<double>(string const s)
151 return strtod(s.c_str(), 0);
156 int convert<int>(char const * cptr)
158 return strtol(cptr, 0, 10);
163 double convert<double>(char const * cptr)
165 return strtod(cptr, 0);