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 lcl_skipSpaces(sal_Int32
& io_rPos
,
31 while( io_rPos
< nLen
&&
32 ' ' == rStr
[io_rPos
] )
38 void lcl_skipSpacesAndCommas(sal_Int32
& io_rPos
,
43 && (' ' == rStr
[io_rPos
] || ',' == rStr
[io_rPos
]))
49 bool lcl_getDoubleChar(double& o_fRetval
,
53 sal_Unicode
aChar( rStr
[io_rPos
] );
54 OUStringBuffer sNumberString
;
55 bool separator_seen
=false;
57 if('+' == aChar
|| '-' == aChar
)
59 sNumberString
.append(rStr
[io_rPos
]);
60 aChar
= rStr
[++io_rPos
];
63 while(('0' <= aChar
&& '9' >= aChar
)
64 || (!separator_seen
&& '.' == aChar
))
66 if ('.' == aChar
) separator_seen
= true;
67 sNumberString
.append(rStr
[io_rPos
]);
69 aChar
= io_rPos
< rStr
.getLength() ? rStr
[io_rPos
] : 0;
72 if('e' == aChar
|| 'E' == aChar
)
74 sNumberString
.append(rStr
[io_rPos
]);
76 aChar
= io_rPos
< rStr
.getLength() ? rStr
[io_rPos
] : 0;
78 if('+' == aChar
|| '-' == aChar
)
80 sNumberString
.append(rStr
[io_rPos
]);
82 aChar
= io_rPos
< rStr
.getLength() ? rStr
[io_rPos
] : 0;
85 while('0' <= aChar
&& '9' >= aChar
)
87 sNumberString
.append(rStr
[io_rPos
]);
89 aChar
= io_rPos
< rStr
.getLength() ? rStr
[io_rPos
] : 0;
93 if(sNumberString
.getLength())
95 rtl_math_ConversionStatus eStatus
;
96 o_fRetval
= ::rtl::math::stringToDouble( sNumberString
.makeStringAndClear(),
101 return ( eStatus
== rtl_math_ConversionStatus_Ok
);
107 bool lcl_importDoubleAndSpaces( double& o_fRetval
,
109 const OUString
& rStr
,
110 const sal_Int32 nLen
)
112 if( !lcl_getDoubleChar(o_fRetval
, io_rPos
, rStr
) )
115 lcl_skipSpacesAndCommas(io_rPos
, rStr
, nLen
);
120 bool lcl_importFlagAndSpaces(sal_Int32
& o_nRetval
,
122 const OUString
& rStr
,
123 const sal_Int32 nLen
)
125 sal_Unicode
aChar( rStr
[io_rPos
] );
132 else if ('1' == aChar
)
140 lcl_skipSpacesAndCommas(io_rPos
, rStr
, nLen
);
145 void lcl_putNumberCharWithSpace( OUStringBuffer
& rStr
,
148 bool bUseRelativeCoordinates
)
150 if( bUseRelativeCoordinates
)
153 const sal_Int32
aLen( rStr
.getLength() );
156 if( lcl_isOnNumberChar(rStr
[aLen
- 1], false) &&
163 lcl_putNumberChar(rStr
, fValue
);
166 } // namespace internal
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */