1 #include "svg/stringstream.h"
2 #include "svg/strip-trailing-zeros.h"
4 Inkscape::SVGOStringStream::SVGOStringStream()
5 {
6 /* These two are probably unnecessary now that we provide our own operator<< for float and
7 * double. */
8 ostr.imbue(std::locale::classic());
9 ostr.setf(std::ios::showpoint);
11 /* This one is (currently) needed though, as we currently use ostr.precision as a sort of
12 variable for storing the desired precision: see our two precision methods and our operator<<
13 methods for float and double. */
14 ostr.precision(8);
15 }
17 Inkscape::SVGOStringStream &
18 operator<<(Inkscape::SVGOStringStream &os, float d)
19 {
20 /* Try as integer first. */
21 {
22 long const n = long(d);
23 if (d == n) {
24 os << n;
25 return os;
26 }
27 }
29 std::ostringstream s;
30 s.imbue(std::locale::classic());
31 s.setf(std::ios::showpoint);
32 s.precision(os.precision());
33 s << d;
34 os << strip_trailing_zeros(s.str());
35 return os;
36 }
38 Inkscape::SVGOStringStream &
39 operator<<(Inkscape::SVGOStringStream &os, double d)
40 {
41 /* Try as integer first. */
42 {
43 long const n = long(d);
44 if (d == n) {
45 os << n;
46 return os;
47 }
48 }
50 std::ostringstream s;
51 s.imbue(std::locale::classic());
52 s.setf(std::ios::showpoint);
53 s.precision(os.precision());
54 s << d;
55 os << strip_trailing_zeros(s.str());
56 return os;
57 }
60 /*
61 Local Variables:
62 mode:c++
63 c-file-style:"stroustrup"
64 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
65 indent-tabs-mode:nil
66 fill-column:99
67 End:
68 */
69 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :