GCC Code Coverage Report


Directory: ./
File: src/2geom/coord.cpp
Date: 2024-03-18 17:01:34
Exec Total Coverage
Lines: 20 20 100.0%
Functions: 3 3 100.0%
Branches: 22 38 57.9%

Line Branch Exec Source
1 /** @file
2 * @brief Conversion between Coord and strings
3 *//*
4 * Authors:
5 * Krzysztof KosiƄski <tweenk.pl@gmail.com>
6 *
7 * Copyright 2014 Authors
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it either under the terms of the GNU Lesser General Public
11 * License version 2.1 as published by the Free Software Foundation
12 * (the "LGPL") or, at your option, under the terms of the Mozilla
13 * Public License Version 1.1 (the "MPL"). If you do not alter this
14 * notice, a recipient may use your version of this file under either
15 * the MPL or the LGPL.
16 *
17 * You should have received a copy of the LGPL along with this library
18 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * You should have received a copy of the MPL along with this library
21 * in the file COPYING-MPL-1.1
22 *
23 * The contents of this file are subject to the Mozilla Public License
24 * Version 1.1 (the "License"); you may not use this file except in
25 * compliance with the License. You may obtain a copy of the License at
26 * http://www.mozilla.org/MPL/
27 *
28 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
29 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
30 * the specific language governing rights and limitations.
31 */
32
33 // Most of the code in this file is derived from:
34 // https://code.google.com/p/double-conversion/
35 // The copyright notice for that code is attached below.
36 //
37 // Copyright 2010 the V8 project authors. All rights reserved.
38 // Redistribution and use in source and binary forms, with or without
39 // modification, are permitted provided that the following conditions are
40 // met:
41 //
42 // * Redistributions of source code must retain the above copyright
43 // notice, this list of conditions and the following disclaimer.
44 // * Redistributions in binary form must reproduce the above
45 // copyright notice, this list of conditions and the following
46 // disclaimer in the documentation and/or other materials provided
47 // with the distribution.
48 // * Neither the name of Google Inc. nor the names of its
49 // contributors may be used to endorse or promote products derived
50 // from this software without specific prior written permission.
51 //
52 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63
64 #include <2geom/coord.h>
65 #include <cstdint>
66 #include <cstdlib>
67 #include <cassert>
68 #include <cstring>
69 #include <climits>
70 #include <cstdarg>
71 #include <cmath>
72
73 #include <double-conversion/double-conversion.h>
74
75 namespace Geom {
76
77 100524 std::string format_coord_shortest(Coord x)
78 {
79 static const double_conversion::DoubleToStringConverter conv(
80 double_conversion::DoubleToStringConverter::UNIQUE_ZERO,
81
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 100522 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
100524 "inf", "NaN", 'e', -3, 6, 0, 0);
82
1/2
✓ Branch 2 taken 100524 times.
✗ Branch 3 not taken.
301572 std::string ret(' ', 32);
83
2/4
✓ Branch 2 taken 100524 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 100524 times.
✗ Branch 6 not taken.
100524 double_conversion::StringBuilder builder(&ret[0], 32);
84
1/2
✓ Branch 1 taken 100524 times.
✗ Branch 2 not taken.
100524 conv.ToShortest(x, &builder);
85
2/4
✓ Branch 1 taken 100524 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 100524 times.
✗ Branch 5 not taken.
100524 ret.resize(builder.position());
86 201048 return ret;
87 100524 }
88
89 100172 std::string format_coord_nice(Coord x)
90 {
91 static const double_conversion::DoubleToStringConverter conv(
92 double_conversion::DoubleToStringConverter::UNIQUE_ZERO,
93
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 100166 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
100172 "inf", "NaN", 'e', -6, 21, 0, 0);
94
1/2
✓ Branch 2 taken 100172 times.
✗ Branch 3 not taken.
300516 std::string ret(' ', 32);
95
2/4
✓ Branch 2 taken 100172 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 100172 times.
✗ Branch 6 not taken.
100172 double_conversion::StringBuilder builder(&ret[0], 32);
96
1/2
✓ Branch 1 taken 100172 times.
✗ Branch 2 not taken.
100172 conv.ToShortest(x, &builder);
97
2/4
✓ Branch 1 taken 100172 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 100172 times.
✗ Branch 5 not taken.
100172 ret.resize(builder.position());
98 200344 return ret;
99 100172 }
100
101 199895 Coord parse_coord(std::string const &s)
102 {
103 static const double_conversion::StringToDoubleConverter conv(
104 double_conversion::StringToDoubleConverter::ALLOW_LEADING_SPACES |
105 double_conversion::StringToDoubleConverter::ALLOW_TRAILING_SPACES |
106 double_conversion::StringToDoubleConverter::ALLOW_SPACES_AFTER_SIGN,
107
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 199894 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
199895 0.0, nan(""), "inf", "NaN");
108 199895 int dummy;
109
1/2
✓ Branch 3 taken 199895 times.
✗ Branch 4 not taken.
399790 return conv.StringToDouble(s.c_str(), s.length(), &dummy);
110 }
111
112 } // namespace Geom
113
114 /*
115 Local Variables:
116 mode:c++
117 c-file-style:"stroustrup"
118 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
119 indent-tabs-mode:nil
120 fill-column:99
121 End:
122 */
123 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
124