X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2Fconvert.cpp;h=b1c554e0832988e274b6003746bf80cc6d6bc019;hb=c1945d27dfd19ef698ae7506c1311ce94091207a;hp=6b985f50baf26042d972fa8d4ea8f70127763ea1;hpb=5bd14af8871b8f87c2c73ca8392b7c72217ad72d;p=lyx.git diff --git a/src/support/convert.cpp b/src/support/convert.cpp index 6b985f50ba..b1c554e083 100644 --- a/src/support/convert.cpp +++ b/src/support/convert.cpp @@ -23,9 +23,24 @@ using namespace std; -namespace lyx { +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; + } +} -using boost::lexical_cast; +} // namespace + + +namespace lyx { template<> string convert(bool b) @@ -90,6 +105,22 @@ docstring convert(unsigned long ul) } +#ifdef LYX_USE_LONG_LONG +template<> +string convert(unsigned long long ull) +{ + return lexical_cast(ull); +} + + +template<> +docstring convert(unsigned long long ull) +{ + return from_ascii(lexical_cast(ull)); +} +#endif + + template<> string convert(long l) { @@ -104,6 +135,22 @@ docstring convert(long l) } +#ifdef LYX_USE_LONG_LONG +template<> +string convert(long long ll) +{ + return lexical_cast(ll); +} + + +template<> +docstring convert(long long ll) +{ + return from_ascii(lexical_cast(ll)); +} +#endif + + template<> string convert(float f) { @@ -122,6 +169,13 @@ string convert(double d) } +template<> +docstring convert(double d) +{ + return from_ascii(convert(d)); +} + + template<> int convert(string const s) {