File tree Expand file tree Collapse file tree 3 files changed +1
-113
lines changed Expand file tree Collapse file tree 3 files changed +1
-113
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 10
10
namespace osrm ::util
11
11
{
12
12
13
- // precision: position after decimal point
14
- // length: maximum number of digits including comma and decimals
15
- // work with negative values to prevent overflowing when taking -value
16
- template <int length, int precision> char *printInt (char *buffer, int value)
17
- {
18
- static_assert (length > 0 , " length must be positive" );
19
- static_assert (precision > 0 , " precision must be positive" );
20
-
21
- const bool minus = [&value]
22
- {
23
- if (value >= 0 )
24
- {
25
- value = -value;
26
- return false ;
27
- }
28
- return true ;
29
- }();
30
-
31
- buffer += length - 1 ;
32
- for (int i = 0 ; i < precision; ++i)
33
- {
34
- *buffer = ' 0' - (value % 10 );
35
- value /= 10 ;
36
- --buffer;
37
- }
38
- *buffer = ' .' ;
39
- --buffer;
40
-
41
- for (int i = precision + 1 ; i < length; ++i)
42
- {
43
- *buffer = ' 0' - (value % 10 );
44
- value /= 10 ;
45
- if (value == 0 )
46
- {
47
- break ;
48
- }
49
- --buffer;
50
- }
51
-
52
- if (minus)
53
- {
54
- --buffer;
55
- *buffer = ' -' ;
56
- }
57
- return buffer;
58
- }
59
-
60
13
inline bool RequiresJSONStringEscaping (const std::string &string)
61
14
{
62
15
for (const char letter : string)
Original file line number Diff line number Diff line change 2
2
3
3
#include < boost/test/unit_test.hpp>
4
4
5
- #include < iostream >
5
+ #include < string >
6
6
7
7
BOOST_AUTO_TEST_SUITE (string_util)
8
8
@@ -27,20 +27,4 @@ BOOST_AUTO_TEST_CASE(json_escaping)
27
27
BOOST_CHECK (!RequiresJSONStringEscaping (" Aleja Solidarnosci" ));
28
28
}
29
29
30
- BOOST_AUTO_TEST_CASE (print_int)
31
- {
32
- const std::string input{" \b\\ " };
33
- char buffer[12 ];
34
- buffer[11 ] = 0 ; // zero termination
35
- std::string output = printInt<11 , 8 >(buffer, 314158976 );
36
- BOOST_CHECK_EQUAL (output, " 3.14158976" );
37
-
38
- buffer[11 ] = 0 ;
39
- output = printInt<11 , 8 >(buffer, 0 );
40
- BOOST_CHECK_EQUAL (output, " 0.00000000" );
41
-
42
- output = printInt<11 , 8 >(buffer, -314158976 );
43
- BOOST_CHECK_EQUAL (output, " -3.14158976" );
44
- }
45
-
46
30
BOOST_AUTO_TEST_SUITE_END ()
You can’t perform that action at this time.
0 commit comments