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"
19 //needed for Mac OSX 10.5.2 Leopard
27 string convert<string>(bool b)
29 return (b ? "true" : "false");
34 string convert<string>(char c)
41 string convert<string>(short unsigned int sui)
43 return to_string(sui);
48 string convert<string>(int i)
55 docstring convert<docstring>(int i)
57 return from_ascii(to_string(i));
62 string convert<string>(unsigned int ui)
69 docstring convert<docstring>(unsigned int ui)
71 return from_ascii(to_string(ui));
76 string convert<string>(unsigned long ul)
83 docstring convert<docstring>(unsigned long ul)
85 return from_ascii(to_string(ul));
89 #ifdef HAVE_LONG_LONG_INT
91 string convert<string>(unsigned long long ull)
93 return to_string(ull);
98 docstring convert<docstring>(unsigned long long ull)
100 return from_ascii(to_string(ull));
105 string convert<string>(long long ll)
107 return to_string(ll);
112 docstring convert<docstring>(long long ll)
114 return from_ascii(to_string(ll));
119 unsigned long long convert<unsigned long long>(string const s)
121 return strtoull(s.c_str(), nullptr, 10);
125 /* not presently needed
127 long long convert<long long>(string const s)
129 return strtoll(s.c_str(), nullptr, 10);
136 string convert<string>(long l)
143 docstring convert<docstring>(long l)
145 return from_ascii(to_string(l));
150 string convert<string>(float f)
159 string convert<string>(double d)
168 docstring convert<docstring>(double d)
170 return from_ascii(convert<string>(d));
175 int convert<int>(string const s)
177 return int(strtol(s.c_str(), nullptr, 10));
181 int convert(string const & s, int base)
183 return int(strtol(s.c_str(), nullptr, base));
188 int convert<int>(docstring const s)
190 return int(strtol(to_ascii(s).c_str(), nullptr, 10));
195 unsigned int convert<unsigned int>(string const s)
197 return static_cast<unsigned int>(strtoul(s.c_str(), nullptr, 10));
202 unsigned long convert<unsigned long>(string const s)
204 return strtoul(s.c_str(), nullptr, 10);
209 double convert<double>(string const s)
211 return strtod(s.c_str(), nullptr);
216 int convert<int>(char const * cptr)
218 return int(strtol(cptr, nullptr, 10));
223 double convert<double>(char const * cptr)
225 return strtod(cptr, nullptr);