1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: table.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // System - Includes -----------------------------------------------------
36 #include "stringutil.hxx"
37 #include "rtl/ustrbuf.hxx"
38 #include "rtl/math.hxx"
40 using ::rtl::OUString
;
41 using ::rtl::OUStringBuffer
;
43 ScSetStringParam::ScSetStringParam() :
45 mbDetectNumberFormat(true),
46 mbSetTextCellFormat(false)
50 // ============================================================================-
52 bool ScStringUtil::parseSimpleNumber(
53 const OUString
& rStr
, sal_Unicode dsep
, sal_Unicode gsep
, double& rVal
)
56 // unicode space to ascii space
60 sal_Int32 n
= rStr
.getLength();
61 const sal_Unicode
* p
= rStr
.getStr();
62 sal_Int32 nPosDSep
= -1, nPosGSep
= -1;
63 sal_uInt32 nDigitCount
= 0;
65 for (sal_Int32 i
= 0; i
< n
; ++i
)
69 // unicode space to ascii space
72 if (sal_Unicode('0') <= c
&& c
<= sal_Unicode('9'))
80 // this is a decimal separator.
83 // a second decimal separator -> not a valid number.
86 if (nPosGSep
>= 0 && i
- nPosGSep
!= 4)
87 // the number has a group separator and the decimal sep is not
88 // positioned correctly.
98 // this is a group (thousand) separator.
101 // not allowed as the first character.
105 // not allowed after the decimal separator.
108 if (nPosGSep
>= 0 && nDigitCount
!= 3)
109 // must be exactly 3 digits since the last group separator.
115 else if (c
== sal_Unicode('-') || c
== sal_Unicode('+'))
117 // A sign must be the first character if it's given.
127 // finished parsing the number.
129 if (nPosGSep
>= 0 && nDigitCount
!= 3)
130 // must be exactly 3 digits since the last group separator.
133 rtl_math_ConversionStatus eStatus
= rtl_math_ConversionStatus_Ok
;
134 sal_Int32 nParseEnd
= 0;
135 rVal
= ::rtl::math::stringToDouble(aBuf
.makeStringAndClear(), dsep
, gsep
, &eStatus
, &nParseEnd
);
136 if (eStatus
!= rtl_math_ConversionStatus_Ok
)