1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <stringconversiontools.hxx>
21 #include <rtl/math.hxx>
23 namespace basegfx::internal
25 void skipSpaces(sal_Int32
& io_rPos
,
26 std::u16string_view rStr
,
29 while( io_rPos
< nLen
&&
30 rStr
[io_rPos
] == ' ' )
36 static void skipSpacesAndCommas(sal_Int32
& io_rPos
,
37 std::u16string_view rStr
,
41 && (rStr
[io_rPos
] == ' ' || rStr
[io_rPos
] == ','))
47 static bool getDoubleChar(double& o_fRetval
,
49 std::u16string_view rStr
)
51 const sal_Int64 nStrSize
= rStr
.size();
52 sal_Unicode aChar
= io_rPos
< nStrSize
? rStr
[io_rPos
] : 0;
53 const sal_Int32 nStartPos
= io_rPos
;
56 if(aChar
== '+' || aChar
== '-')
58 aChar
= rStr
[++io_rPos
];
61 // numbers before point
62 while('0' <= aChar
&& '9' >= aChar
)
65 aChar
= io_rPos
< nStrSize
? rStr
[io_rPos
] : 0;
72 aChar
= io_rPos
< nStrSize
? rStr
[io_rPos
] : 0;
75 // numbers after point
76 while ('0' <= aChar
&& '9' >= aChar
)
79 aChar
= io_rPos
< nStrSize
? rStr
[io_rPos
] : 0;
83 if(aChar
== 'e' || aChar
== 'E')
86 aChar
= io_rPos
< nStrSize
? rStr
[io_rPos
] : 0;
89 if(aChar
== '+' || aChar
== '-')
92 aChar
= io_rPos
< nStrSize
? rStr
[io_rPos
] : 0;
96 while('0' <= aChar
&& '9' >= aChar
)
99 aChar
= io_rPos
< nStrSize
? rStr
[io_rPos
] : 0;
103 const sal_Int32 nLen
= io_rPos
- nStartPos
;
106 rStr
= rStr
.substr(nStartPos
, nLen
);
107 rtl_math_ConversionStatus eStatus
;
108 o_fRetval
= ::rtl::math::stringToDouble( rStr
,
112 return ( eStatus
== rtl_math_ConversionStatus_Ok
);
118 bool importDoubleAndSpaces(double& o_fRetval
,
120 std::u16string_view rStr
,
121 const sal_Int32 nLen
)
123 if( !getDoubleChar(o_fRetval
, io_rPos
, rStr
) )
126 skipSpacesAndCommas(io_rPos
, rStr
, nLen
);
131 bool importFlagAndSpaces(sal_Int32
& o_nRetval
,
133 std::u16string_view rStr
,
134 const sal_Int32 nLen
)
136 sal_Unicode
aChar( rStr
[io_rPos
] );
143 else if (aChar
== '1')
151 skipSpacesAndCommas(io_rPos
, rStr
, nLen
);
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */