Use to_string instead of boost::lexical_cast

This commit is contained in:
Yuriy Skalko 2020-12-10 14:33:47 +02:00
parent 5999dd96e6
commit 9348c5c635

View File

@ -14,8 +14,6 @@
#include "support/convert.h" #include "support/convert.h"
#include "support/docstring.h" #include "support/docstring.h"
#include <boost/lexical_cast.hpp>
#include <string> #include <string>
#include <sstream> #include <sstream>
//needed for Mac OSX 10.5.2 Leopard //needed for Mac OSX 10.5.2 Leopard
@ -23,23 +21,6 @@
using namespace std; using namespace std;
namespace {
// A version of lexical cast that does not throw. Useful for when we convert to string
template<typename To, typename From>
To lexical_cast(From const & value, To const & defaultResult = To())
{
try {
return boost::lexical_cast<To>(value);
} catch(...) {
// Ignore all exceptions and use default.
return defaultResult;
}
}
} // namespace
namespace lyx { namespace lyx {
template<> template<>
@ -59,49 +40,49 @@ string convert<string>(char c)
template<> template<>
string convert<string>(short unsigned int sui) string convert<string>(short unsigned int sui)
{ {
return lexical_cast<string>(sui); return to_string(sui);
} }
template<> template<>
string convert<string>(int i) string convert<string>(int i)
{ {
return lexical_cast<string>(i); return to_string(i);
} }
template<> template<>
docstring convert<docstring>(int i) docstring convert<docstring>(int i)
{ {
return from_ascii(lexical_cast<string>(i)); return from_ascii(to_string(i));
} }
template<> template<>
string convert<string>(unsigned int ui) string convert<string>(unsigned int ui)
{ {
return lexical_cast<string>(ui); return to_string(ui);
} }
template<> template<>
docstring convert<docstring>(unsigned int ui) docstring convert<docstring>(unsigned int ui)
{ {
return from_ascii(lexical_cast<string>(ui)); return from_ascii(to_string(ui));
} }
template<> template<>
string convert<string>(unsigned long ul) string convert<string>(unsigned long ul)
{ {
return lexical_cast<string>(ul); return to_string(ul);
} }
template<> template<>
docstring convert<docstring>(unsigned long ul) docstring convert<docstring>(unsigned long ul)
{ {
return from_ascii(lexical_cast<string>(ul)); return from_ascii(to_string(ul));
} }
@ -109,28 +90,28 @@ docstring convert<docstring>(unsigned long ul)
template<> template<>
string convert<string>(unsigned long long ull) string convert<string>(unsigned long long ull)
{ {
return lexical_cast<string>(ull); return to_string(ull);
} }
template<> template<>
docstring convert<docstring>(unsigned long long ull) docstring convert<docstring>(unsigned long long ull)
{ {
return from_ascii(lexical_cast<string>(ull)); return from_ascii(to_string(ull));
} }
template<> template<>
string convert<string>(long long ll) string convert<string>(long long ll)
{ {
return lexical_cast<string>(ll); return to_string(ll);
} }
template<> template<>
docstring convert<docstring>(long long ll) docstring convert<docstring>(long long ll)
{ {
return from_ascii(lexical_cast<string>(ll)); return from_ascii(to_string(ll));
} }
@ -154,21 +135,21 @@ long long convert<long long>(string const s)
template<> template<>
string convert<string>(long l) string convert<string>(long l)
{ {
return lexical_cast<string>(l); return to_string(l);
} }
template<> template<>
docstring convert<docstring>(long l) docstring convert<docstring>(long l)
{ {
return from_ascii(lexical_cast<string>(l)); return from_ascii(to_string(l));
} }
template<> template<>
string convert<string>(float f) string convert<string>(float f)
{ {
std::ostringstream val; ostringstream val;
val << f; val << f;
return val.str(); return val.str();
} }
@ -177,7 +158,7 @@ string convert<string>(float f)
template<> template<>
string convert<string>(double d) string convert<string>(double d)
{ {
std::ostringstream val; ostringstream val;
val << d; val << d;
return val.str(); return val.str();
} }
@ -197,7 +178,7 @@ int convert<int>(string const s)
} }
int convert(std::string const & s, int base) int convert(string const & s, int base)
{ {
return int(strtol(s.c_str(), nullptr, base)); return int(strtol(s.c_str(), nullptr, base));
} }