diff options
| author | Carl Hetherington <cth@carlh.net> | 2019-03-12 16:24:46 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2019-03-12 16:24:46 +0000 |
| commit | 5038e68ad9eb66e007211c8f1b707612a0c01e29 (patch) | |
| tree | 70d5aa5d3f414defc3d3cd0b34de0725bf8760a9 /src/stl_binary_writer.cc | |
| parent | a8b629085c404d7a947ed242fbf64d8e0e91edcd (diff) | |
Remove sstream dependency.
Diffstat (limited to 'src/stl_binary_writer.cc')
| -rw-r--r-- | src/stl_binary_writer.cc | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/stl_binary_writer.cc b/src/stl_binary_writer.cc index d4fe9ed..88e8ce5 100644 --- a/src/stl_binary_writer.cc +++ b/src/stl_binary_writer.cc @@ -28,6 +28,7 @@ #include "compose.hpp" #include "sub_assert.h" #include <boost/locale.hpp> +#include <boost/algorithm/string.hpp> #include <list> #include <cmath> #include <fstream> @@ -70,16 +71,32 @@ put_string (char* p, unsigned int n, string s) memset (p + s.length(), ' ', n - s.length ()); } +/** @param v Value + * @param n Width to zero-pad v to. + */ static void put_int_as_string (char* p, int v, unsigned int n) { - locked_stringstream s; - /* Be careful to ensure we get no thousands separators */ - s.imbue (std::locale::classic ()); - s << setw (n) << setfill ('0'); - s << v; - SUB_ASSERT (s.str().length() == n); - put_string (p, s.str ()); + char buffer[64]; + + switch (n) { + case 2: + snprintf (buffer, sizeof(buffer), "%02d", v); + break; + case 5: + snprintf (buffer, sizeof(buffer), "%05d", v); + break; + default: + SUB_ASSERT (false); + } + + string s = buffer; + + struct lconv* lc = localeconv (); + boost::algorithm::replace_all (s, lc->thousands_sep, ""); + boost::algorithm::replace_all (s, lc->decimal_point, "."); + + put_string (p, s); } static void |
