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 .
22 #include <rtl/ustring.hxx>
24 #include <i18nlangtag/lang.h>
27 class SvNumberFormatter
;
28 enum class SvNumFormatType
: sal_Int16
;
31 * Store parameters used in the ScDocument::SetString() method. Various
32 * options for string-setting operation are specified herein.
34 struct SAL_WARN_UNUSED SC_DLLPUBLIC ScSetStringParam
36 /** Enum settings that take effect if mbDetectNumberFormat=false or if
37 true a number was not detected.
42 * Set Text number format if the input string can be parsed as a number
48 * Set Text number format only when the input string is considered a
49 * special number but we only want to detect a simple number.
54 * Keep an existing number format, do not set Text number format and do
55 * not set another number format.
60 * Never set Text number format.
66 * Stores the pointer to the number formatter instance to be used during
67 * number format detection. The caller must manage the life cycle of the
70 SvNumberFormatter
* mpNumFormatter
;
73 * Specify which number formats are detected:
74 * mbDetectNumberFormat=true && mbDetectScientificNumberFormat=true : detect all special number formats : basic decimal number, date, scientific notation, etc
75 * mbDetectNumberFormat=false && mbDetectScientificNumberFormat=true : detect scientific notation and basic decimal number, but not other special number formats (date etc)
76 * mbDetectNumberFormat=false && mbDetectScientificNumberFormat=false : detect only basic decimal number, but not scientific notation or other special number formats (date etc)
77 * Note: mbDetectNumberFormat=true && mbDetectScientificNumberFormat=false not allowed
79 bool mbDetectNumberFormat
;
80 bool mbDetectScientificNumberFormat
;
83 * Determine when to set the 'Text' number format to the cell where the
84 * input string is being set.
86 TextFormatPolicy meSetTextNumFormat
;
89 * When true, treat input with a leading apostrophe as an escape character
90 * for all content, to treat also numeric value as a text. When
91 * false, the whole string input including the leading apostrophe will be
92 * entered literally as string.
94 bool mbHandleApostrophe
;
96 sc::StartListeningType meStartListening
;
98 /** When true and the string results in a compiled formula, check the
99 formula tokens for presence of functions that could trigger access to
100 external resources. This is to be set to true in import filter code,
101 but not for user input.
103 bool mbCheckLinkFormula
;
108 * Call this whenever you need to unconditionally set input as text, no
109 * matter what the input is.
114 * Call this whenever you need to maximize the chance of input being
115 * detected as a numeric value (numbers, dates, times etc).
117 void setNumericInput();
120 struct ScInputStringType
122 enum StringType
{ Unknown
= 0, Text
, Formula
, Number
};
128 SvNumFormatType mnFormatType
;
131 struct ScInterpreterContext
;
138 * Check if a given string is a simple decimal number (e.g. 12.345). We
139 * don't do any elaborate parsing here; we only check for the simplest
140 * case of decimal number format.
142 * Note that preceding and trailing spaces are ignored during parsing.
144 * @param rStr string to parse
145 * @param dsep decimal separator
146 * @param gsep group separator (aka thousands separator)
147 * @param dsepa decimal separator alternative, usually 0
148 * @param rVal value of successfully parsed number
150 * @return true if the string is a valid number, false otherwise.
152 static bool parseSimpleNumber(
153 const OUString
& rStr
, sal_Unicode dsep
, sal_Unicode gsep
, sal_Unicode dsepa
, double& rVal
, bool bDetectScientificNumber
= true);
155 static bool parseSimpleNumber(
156 const char* p
, size_t n
, char dsep
, char gsep
, double& rVal
);
158 static OUString SC_DLLPUBLIC
GetQuotedToken(const OUString
&rIn
, sal_Int32 nToken
, const OUString
& rQuotedPairs
,
159 sal_Unicode cTok
, sal_Int32
& rIndex
);
161 static bool SC_DLLPUBLIC
isMultiline( std::u16string_view rStr
);
163 static ScInputStringType
parseInputString(
164 ScInterpreterContext
& rContext
, const OUString
& rStr
, LanguageType eLang
);
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */