]> git.lyx.org Git - lyx.git/blobdiff - src/support/convert.cpp
Make tab movement visible (#10733)
[lyx.git] / src / support / convert.cpp
index 754a53622e88c3e1ac00caad07859db2ef82841c..b1c554e0832988e274b6003746bf80cc6d6bc019 100644 (file)
@@ -3,29 +3,44 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author André Pönitz
- * \author Lars Gullik Bjønnes
+ * \author André Pönitz
+ * \author Lars Gullik Bjønnes
  *
  * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#include "convert.h"
-
+#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
+#include <cstdlib>
 
+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;
+       }
+}
 
-using boost::lexical_cast;
+} // namespace
 
-using std::string;
 
+namespace lyx {
 
 template<>
 string convert<string>(bool b)
@@ -90,6 +105,22 @@ docstring convert<docstring>(unsigned long ul)
 }
 
 
+#ifdef LYX_USE_LONG_LONG
+template<>
+string convert<string>(unsigned long long ull)
+{
+       return lexical_cast<string>(ull);
+}
+
+
+template<>
+docstring convert<docstring>(unsigned long long ull)
+{
+       return from_ascii(lexical_cast<string>(ull));
+}
+#endif
+
+
 template<>
 string convert<string>(long l)
 {
@@ -104,17 +135,44 @@ docstring convert<docstring>(long l)
 }
 
 
+#ifdef LYX_USE_LONG_LONG
+template<>
+string convert<string>(long long ll)
+{
+       return lexical_cast<string>(ll);
+}
+
+
+template<>
+docstring convert<docstring>(long long ll)
+{
+       return from_ascii(lexical_cast<string>(ll));
+}
+#endif
+
+
 template<>
 string convert<string>(float f)
 {
-       return lexical_cast<string>(f);
+       std::ostringstream val;
+       val << f;
+       return val.str();
 }
 
 
 template<>
 string convert<string>(double d)
 {
-       return lexical_cast<string>(d);
+       std::ostringstream val;
+       val << d;
+       return val.str();
+}
+
+
+template<>
+docstring convert<docstring>(double d)
+{
+       return from_ascii(convert<string>(d));
 }