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/docstring.h"
#include <boost/lexical_cast.hpp>
#include <string>
#include <sstream>
//needed for Mac OSX 10.5.2 Leopard
@ -23,23 +21,6 @@
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 {
template<>
@ -59,49 +40,49 @@ string convert<string>(char c)
template<>
string convert<string>(short unsigned int sui)
{
return lexical_cast<string>(sui);
return to_string(sui);
}
template<>
string convert<string>(int i)
{
return lexical_cast<string>(i);
return to_string(i);
}
template<>
docstring convert<docstring>(int i)
{
return from_ascii(lexical_cast<string>(i));
return from_ascii(to_string(i));
}
template<>
string convert<string>(unsigned int ui)
{
return lexical_cast<string>(ui);
return to_string(ui);
}
template<>
docstring convert<docstring>(unsigned int ui)
{
return from_ascii(lexical_cast<string>(ui));
return from_ascii(to_string(ui));
}
template<>
string convert<string>(unsigned long ul)
{
return lexical_cast<string>(ul);
return to_string(ul);
}
template<>
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<>
string convert<string>(unsigned long long ull)
{
return lexical_cast<string>(ull);
return to_string(ull);
}
template<>
docstring convert<docstring>(unsigned long long ull)
{
return from_ascii(lexical_cast<string>(ull));
return from_ascii(to_string(ull));
}
template<>
string convert<string>(long long ll)
{
return lexical_cast<string>(ll);
return to_string(ll);
}
template<>
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<>
string convert<string>(long l)
{
return lexical_cast<string>(l);
return to_string(l);
}
template<>
docstring convert<docstring>(long l)
{
return from_ascii(lexical_cast<string>(l));
return from_ascii(to_string(l));
}
template<>
string convert<string>(float f)
{
std::ostringstream val;
ostringstream val;
val << f;
return val.str();
}
@ -177,7 +158,7 @@ string convert<string>(float f)
template<>
string convert<string>(double d)
{
std::ostringstream val;
ostringstream val;
val << d;
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));
}