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>
27 void skipSpaces(sal_Int32
& io_rPos
,
31 while( io_rPos
< nLen
&&
32 ' ' == rStr
[io_rPos
] )
38 void skipSpacesAndCommas(sal_Int32
& io_rPos
,
43 && (' ' == rStr
[io_rPos
] || ',' == rStr
[io_rPos
]))
49 bool getDoubleChar(double& o_fRetval
,
53 sal_Unicode
aChar( rStr
[io_rPos
] );
54 OUStringBuffer sNumberString
;
57 if('+' == aChar
|| '-' == aChar
)
59 sNumberString
.append(rStr
[io_rPos
]);
60 aChar
= rStr
[++io_rPos
];
63 // numbers before point
64 while('0' <= aChar
&& '9' >= aChar
)
66 sNumberString
.append(rStr
[io_rPos
]);
68 aChar
= io_rPos
< rStr
.getLength() ? rStr
[io_rPos
] : 0;
74 sNumberString
.append(rStr
[io_rPos
]);
76 aChar
= io_rPos
< rStr
.getLength() ? rStr
[io_rPos
] : 0;
79 // numbers after point
80 while ('0' <= aChar
&& '9' >= aChar
)
82 sNumberString
.append(rStr
[io_rPos
]);
84 aChar
= io_rPos
< rStr
.getLength() ? rStr
[io_rPos
] : 0;
88 if('e' == aChar
|| 'E' == aChar
)
90 sNumberString
.append(rStr
[io_rPos
]);
92 aChar
= io_rPos
< rStr
.getLength() ? rStr
[io_rPos
] : 0;
95 if('+' == aChar
|| '-' == aChar
)
97 sNumberString
.append(rStr
[io_rPos
]);
99 aChar
= io_rPos
< rStr
.getLength() ? rStr
[io_rPos
] : 0;
103 while('0' <= aChar
&& '9' >= aChar
)
105 sNumberString
.append(rStr
[io_rPos
]);
107 aChar
= io_rPos
< rStr
.getLength() ? rStr
[io_rPos
] : 0;
111 if(sNumberString
.getLength())
113 rtl_math_ConversionStatus eStatus
;
114 o_fRetval
= ::rtl::math::stringToDouble( sNumberString
.makeStringAndClear(),
119 return ( eStatus
== rtl_math_ConversionStatus_Ok
);
125 bool importDoubleAndSpaces(double& o_fRetval
,
127 const OUString
& rStr
,
128 const sal_Int32 nLen
)
130 if( !getDoubleChar(o_fRetval
, io_rPos
, rStr
) )
133 skipSpacesAndCommas(io_rPos
, rStr
, nLen
);
138 bool importFlagAndSpaces(sal_Int32
& o_nRetval
,
140 const OUString
& rStr
,
141 const sal_Int32 nLen
)
143 sal_Unicode
aChar( rStr
[io_rPos
] );
150 else if ('1' == aChar
)
158 skipSpacesAndCommas(io_rPos
, rStr
, nLen
);
163 void putNumberCharWithSpace(OUStringBuffer
& rStr
,
166 bool bUseRelativeCoordinates
)
168 if( bUseRelativeCoordinates
)
171 const sal_Int32
aLen( rStr
.getLength() );
174 if( isOnNumberChar(rStr
[aLen
- 1], false, true) &&
183 } // namespace internal
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */