Coverage Report

Created: 2026-10-14 09:33

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
1.02k
        {
29
1.02k
            while( io_rPos < nLen &&
30
776
                    rStr[io_rPos] == ' ' )
31
0
            {
32
0
                ++io_rPos;
33
0
            }
34
1.02k
        }
35
36
        static void skipSpacesAndCommas(sal_Int32&      io_rPos,
37
                                 std::u16string_view rStr,
38
                                 const sal_Int32 nLen)
39
1.68k
        {
40
2.88k
            while(io_rPos < nLen
41
2.68k
                    && (rStr[io_rPos] == ' ' || rStr[io_rPos] == ','))
42
1.19k
            {
43
1.19k
                ++io_rPos;
44
1.19k
            }
45
1.68k
        }
46
47
        static bool getDoubleChar(double&         o_fRetval,
48
                           sal_Int32&      io_rPos,
49
                           std::u16string_view rStr)
50
1.69k
        {
51
1.69k
            const sal_Int64 nStrSize = rStr.size();
52
1.69k
            sal_Unicode aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0;
53
1.69k
            const sal_Int32 nStartPos = io_rPos;
54
55
            // sign
56
1.69k
            if(aChar == '+' || aChar == '-')
57
219
            {
58
219
                aChar = rStr[++io_rPos];
59
219
            }
60
61
            // numbers before point
62
6.41k
            while('0' <= aChar && '9' >= aChar)
63
4.72k
            {
64
4.72k
                io_rPos++;
65
4.72k
                aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0;
66
4.72k
            }
67
68
            // point
69
1.69k
            if(aChar == '.')
70
0
            {
71
0
                io_rPos++;
72
0
                aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0;
73
0
            }
74
75
            // numbers after point
76
1.69k
            while ('0' <= aChar && '9' >= aChar)
77
0
            {
78
0
                io_rPos++;
79
0
                aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0;
80
0
            }
81
82
            // 'e'
83
1.69k
            if(aChar == 'e' || aChar == 'E')
84
0
            {
85
0
                io_rPos++;
86
0
                aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0;
87
88
                // sign for 'e'
89
0
                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
0
                while('0' <= aChar && '9' >= aChar)
97
0
                {
98
0
                    io_rPos++;
99
0
                    aChar = io_rPos < nStrSize ? rStr[io_rPos] : 0;
100
0
                }
101
0
            }
102
103
1.69k
            const sal_Int32 nLen = io_rPos - nStartPos;
104
1.69k
            if(nLen)
105
1.68k
            {
106
1.68k
                rStr = rStr.substr(nStartPos, nLen);
107
1.68k
                rtl_math_ConversionStatus eStatus;
108
1.68k
                o_fRetval = ::rtl::math::stringToDouble( rStr,
109
1.68k
                                                            '.',
110
1.68k
                                                            ',',
111
1.68k
                                                            &eStatus );
112
1.68k
                return ( eStatus == rtl_math_ConversionStatus_Ok );
113
1.68k
            }
114
115
5
            return false;
116
1.69k
        }
117
118
        bool importDoubleAndSpaces(double&         o_fRetval,
119
                                   sal_Int32&      io_rPos,
120
                                   std::u16string_view rStr,
121
                                   const sal_Int32 nLen )
122
1.69k
        {
123
1.69k
            if( !getDoubleChar(o_fRetval, io_rPos, rStr) )
124
5
                return false;
125
126
1.68k
            skipSpacesAndCommas(io_rPos, rStr, nLen);
127
128
1.68k
            return true;
129
1.69k
        }
130
131
        bool importFlagAndSpaces(sal_Int32&      o_nRetval,
132
                                 sal_Int32&      io_rPos,
133
                                 std::u16string_view rStr,
134
                                 const sal_Int32 nLen)
135
0
        {
136
0
            sal_Unicode aChar( rStr[io_rPos] );
137
138
0
            if(aChar == '0')
139
0
            {
140
0
                o_nRetval = 0;
141
0
                ++io_rPos;
142
0
            }
143
0
            else if (aChar == '1')
144
0
            {
145
0
                o_nRetval = 1;
146
0
                ++io_rPos;
147
0
            }
148
0
            else
149
0
                return false;
150
151
0
            skipSpacesAndCommas(io_rPos, rStr, nLen);
152
153
0
            return true;
154
0
        }
155
156
}
157
158
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */