[beast/devel: 25/35] BSE: bse_string_from_double(): use string_format() which is type-safe and locale-stable



commit 1d69e8d4a7b092c1acf9edde710ef700fb8908a2
Author: Tim Janik <timj gnu org>
Date:   Tue May 14 00:55:27 2013 +0200

    BSE: bse_string_from_double(): use string_format() which is type-safe and locale-stable

 bse/bsemath.cc |   13 ++++---------
 1 files changed, 4 insertions(+), 9 deletions(-)
---
diff --git a/bse/bsemath.cc b/bse/bsemath.cc
index e6fbe17..71dd869 100644
--- a/bse/bsemath.cc
+++ b/bse/bsemath.cc
@@ -11,16 +11,11 @@
 std::string
 bse_string_from_double (long double value)
 {
-  std::string str;
-  str.resize (FLOAT_STRING_SIZE, 0);
-  char *s = &str[0];
-  sprintf (s, "%." PRINTF_DIGITS "Lf", value);
-  while (*s)
-    s++;
-  while (s > &str[2] && s[-1] == '0' && s[-2] != '.')
+  std::string str = Rapicorn::string_format ("%.1270f", value);
+  const char *s = &str[str.size()];
+  while (s > &str[0] && s[-1] == '0' && s[-2] != '.')
     s--;
-  *s = 0;
-  return std::string (str.c_str());
+  return str.substr (0, s - &str[0]);
 }
 
 char*


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]