X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fstl_binary_writer.cc;h=88e8ce59a4789bd1913c596e5e478ea88d801781;hb=5038e68ad9eb66e007211c8f1b707612a0c01e29;hp=d4fe9ed69c9185ee2101ff584d5c846c1ce88bde;hpb=a8b629085c404d7a947ed242fbf64d8e0e91edcd;p=libsub.git 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 +#include #include #include #include @@ -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