Code

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