From 9348c5c63521d5e2908e30b191afb1e703ff219a Mon Sep 17 00:00:00 2001 From: Yuriy Skalko Date: Thu, 10 Dec 2020 14:33:47 +0200 Subject: [PATCH 1/1] Use `to_string` instead of `boost::lexical_cast` --- src/support/convert.cpp | 51 +++++++++++++---------------------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/src/support/convert.cpp b/src/support/convert.cpp index 5912ac54e6..7053be3fa7 100644 --- a/src/support/convert.cpp +++ b/src/support/convert.cpp @@ -14,8 +14,6 @@ #include "support/convert.h" #include "support/docstring.h" -#include - #include #include //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 -To lexical_cast(From const & value, To const & defaultResult = To()) -{ - try { - return boost::lexical_cast(value); - } catch(...) { - // Ignore all exceptions and use default. - return defaultResult; - } -} - -} // namespace - - namespace lyx { template<> @@ -59,49 +40,49 @@ string convert(char c) template<> string convert(short unsigned int sui) { - return lexical_cast(sui); + return to_string(sui); } template<> string convert(int i) { - return lexical_cast(i); + return to_string(i); } template<> docstring convert(int i) { - return from_ascii(lexical_cast(i)); + return from_ascii(to_string(i)); } template<> string convert(unsigned int ui) { - return lexical_cast(ui); + return to_string(ui); } template<> docstring convert(unsigned int ui) { - return from_ascii(lexical_cast(ui)); + return from_ascii(to_string(ui)); } template<> string convert(unsigned long ul) { - return lexical_cast(ul); + return to_string(ul); } template<> docstring convert(unsigned long ul) { - return from_ascii(lexical_cast(ul)); + return from_ascii(to_string(ul)); } @@ -109,28 +90,28 @@ docstring convert(unsigned long ul) template<> string convert(unsigned long long ull) { - return lexical_cast(ull); + return to_string(ull); } template<> docstring convert(unsigned long long ull) { - return from_ascii(lexical_cast(ull)); + return from_ascii(to_string(ull)); } template<> string convert(long long ll) { - return lexical_cast(ll); + return to_string(ll); } template<> docstring convert(long long ll) { - return from_ascii(lexical_cast(ll)); + return from_ascii(to_string(ll)); } @@ -154,21 +135,21 @@ long long convert(string const s) template<> string convert(long l) { - return lexical_cast(l); + return to_string(l); } template<> docstring convert(long l) { - return from_ascii(lexical_cast(l)); + return from_ascii(to_string(l)); } template<> string convert(float f) { - std::ostringstream val; + ostringstream val; val << f; return val.str(); } @@ -177,7 +158,7 @@ string convert(float f) template<> string convert(double d) { - std::ostringstream val; + ostringstream val; val << d; return val.str(); } @@ -197,7 +178,7 @@ int convert(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)); } -- 2.39.2