diff options
| author | MenTaLguY <mental@rydia.net> | 2006-01-16 02:36:01 +0000 |
|---|---|---|
| committer | mental <mental@users.sourceforge.net> | 2006-01-16 02:36:01 +0000 |
| commit | 179fa413b047bede6e32109e2ce82437c5fb8d34 (patch) | |
| tree | a5a6ac2c1708bd02288fbd8edb2ff500ff2e0916 /src/svg/strip-trailing-zeros.cpp | |
| download | inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.tar.gz inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.zip | |
moving trunk for module inkscape
(bzr r1)
Diffstat (limited to 'src/svg/strip-trailing-zeros.cpp')
| -rw-r--r-- | src/svg/strip-trailing-zeros.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/svg/strip-trailing-zeros.cpp b/src/svg/strip-trailing-zeros.cpp new file mode 100644 index 000000000..79b266b42 --- /dev/null +++ b/src/svg/strip-trailing-zeros.cpp @@ -0,0 +1,42 @@ +#include "svg/strip-trailing-zeros.h" +#include <glib/gmessages.h> +using std::string; + +string +strip_trailing_zeros(string str) +{ + string::size_type p_ix = str.find('.'); + if (p_ix != string::npos) { + string::size_type e_ix = str.find('e', p_ix); + /* N.B. In some contexts (e.g. CSS) it is an error for a number to contain `e'. fixme: + * Default to avoiding `e', e.g. using sprintf(str, "%17f", d). Add a new function that + * allows use of `e' and use that function only where the spec allows it. + */ + string::size_type nz_ix = str.find_last_not_of('0', (e_ix == string::npos + ? e_ix + : e_ix - 1)); + if (nz_ix == string::npos || nz_ix < p_ix || nz_ix >= e_ix) { + g_error("have `.' but couldn't find non-0"); + } else { + str.erase(str.begin() + (nz_ix == p_ix + ? p_ix + : nz_ix + 1), + (e_ix == string::npos + ? str.end() + : str.begin() + e_ix)); + } + } + return str; +} + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : |
