Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/basegfx/source/tools/stringconversiontools.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <stringconversiontools.hxx>
21
#include <rtl/math.hxx>
22
23
namespace basegfx::internal
24
{
25
        void skipSpaces(sal_Int32&      io_rPos,
26
                        std::u16string_view rStr,
27
                        const sal_Int32 nLen)
28
138k
        {
29
138k
            while( io_rPos < nLen &&
30
120k
                    rStr[io_rPos] == ' ' )
31
187
            {
32
187
                ++io_rPos;
33
187
            }
34
138k
        }
35
36
        static void skipSpacesAndCommas(sal_Int32&      io_rPos,
37
                                 std::u16string_view rStr,
38
                                 const sal_Int32 nLen)
39
86.7k
        {
40
124k
            while(io_rPos < nLen
41
124k
                    && (rStr[io_rPos] == ' ' || rStr[io_rPos] == ','))
42
37.9k
            {
43
37.9k
                ++io_rPos;
44
37.9k
            }
45
86.7k
        }
46
47
        static bool getDoubleChar(double&         o_fRetval,
48
                           sal_Int32&      io_rPos,
49
                           std::u16string_view rStr)
50
87.6k
        {
51
87.6k
            const sal_Int64 nStrSize = rStr.size();
52
87.6k
            sal_Unicode aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0;
53
87.6k
            const sal_Int32 nStartPos = io_rPos;
54
55
            // sign
56
87.6k
            if(aChar == '+' || aChar == '-')
57
19.0k
            {
58
19.0k
                aChar = rStr[++io_rPos];
59
19.0k
            }
60
61
            // numbers before point
62
371k
            while('0' <= aChar && '9' >= aChar)
63
283k
            {
64
283k
                io_rPos++;
65
283k
                aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0;
66
283k
            }
67
68
            // point
69
87.6k
            if(aChar == '.')
70
139
            {
71
139
                io_rPos++;
72
139
                aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0;
73
139
            }
74
75
            // numbers after point
76
87.9k
            while ('0' <= aChar && '9' >= aChar)
77
350
            {
78
350
                io_rPos++;
79
350
                aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0;
80
350
            }
81
82
            // 'e'
83
87.6k
            if(aChar == 'e' || aChar == 'E')
84
18
            {
85
18
                io_rPos++;
86
18
                aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0;
87
88
                // sign for 'e'
89
18
                if(aChar == '+' || aChar == '-')
90
0
                {
91
0
                    io_rPos++;
92
0
                    aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0;
93
0
                }
94
95
                // number for 'e'
96
38
                while('0' <= aChar && '9' >= aChar)
97
20
                {
98
20
                    io_rPos++;
99
20
                    aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0;
100
20
                }
101
18
            }
102
103
87.6k
            const sal_Int32 nLen = io_rPos - nStartPos;
104
87.6k
            if(nLen)
105
86.7k
            {
106
86.7k
                rStr = rStr.substr(nStartPos, nLen);
107
86.7k
                rtl_math_ConversionStatus eStatus;
108
86.7k
                o_fRetval = ::rtl::math::stringToDouble( rStr,
109
86.7k
                                                            '.',
110
86.7k
                                                            ',',
111
86.7k
                                                            &eStatus );
112
86.7k
                return ( eStatus == rtl_math_ConversionStatus_Ok );
113
86.7k
            }
114
115
864
            return false;
116
87.6k
        }
117
118
        bool importDoubleAndSpaces(double&         o_fRetval,
119
                                   sal_Int32&      io_rPos,
120
                                   std::u16string_view rStr,
121
                                   const sal_Int32 nLen )
122
87.6k
        {
123
87.6k
            if( !getDoubleChar(o_fRetval, io_rPos, rStr) )
124
865
                return false;
125
126
86.7k
            skipSpacesAndCommas(io_rPos, rStr, nLen);
127
128
86.7k
            return true;
129
87.6k
        }
130
131
        bool importFlagAndSpaces(sal_Int32&      o_nRetval,
132
                                 sal_Int32&      io_rPos,
133
                                 std::u16string_view rStr,
134
                                 const sal_Int32 nLen)
135
1
        {
136
1
            sal_Unicode aChar( rStr[io_rPos] );
137
138
1
            if(aChar == '0')
139
0
            {
140
0
                o_nRetval = 0;
141
0
                ++io_rPos;
142
0
            }
143
1
            else if (aChar == '1')
144
0
            {
145
0
                o_nRetval = 1;
146
0
                ++io_rPos;
147
0
            }
148
1
            else
149
1
                return false;
150
151
0
            skipSpacesAndCommas(io_rPos, rStr, nLen);
152
153
0
            return true;
154
1
        }
155
156
}
157
158
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */