]> git.lyx.org Git - lyx.git/blobdiff - src/support/convert.cpp
Use more informative descriptions fro Springer layouts
[lyx.git] / src / support / convert.cpp
index 58a56479a3abe377761d8a1afae8da3ace6ff322..b1c554e0832988e274b6003746bf80cc6d6bc019 100644 (file)
 
 using namespace std;
 
-namespace lyx {
+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
+
 
-using boost::lexical_cast;
+namespace lyx {
 
 template<>
 string convert<string>(bool b)
@@ -154,6 +169,13 @@ string convert<string>(double d)
 }
 
 
+template<>
+docstring convert<docstring>(double d)
+{
+       return from_ascii(convert<string>(d));
+}
+
+
 template<>
 int convert<int>(string const s)
 {