Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sc / inc / stringutil.hxx
blobff2bc9cd74cd8070b748374161bc317c9a792244
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #ifndef INCLUDED_SC_INC_STRINGUTIL_HXX
21 #define INCLUDED_SC_INC_STRINGUTIL_HXX
23 #include <rtl/ustring.hxx>
24 #include "scdllapi.h"
25 #include <i18nlangtag/lang.h>
26 #include "types.hxx"
28 class SvNumberFormatter;
29 enum class SvNumFormatType : sal_Int16;
31 /**
32 * Store parameters used in the ScDocument::SetString() method. Various
33 * options for string-setting operation are specified herein.
35 struct SAL_WARN_UNUSED SC_DLLPUBLIC ScSetStringParam
37 /** Enum settings that take effect if mbDetectNumberFormat=false or if
38 true a number was not detected.
40 enum TextFormatPolicy
42 /**
43 * Set Text number format if the input string can be parsed as a number
44 * or formula text.
46 Always,
48 /**
49 * Set Text number format only when the input string is considered a
50 * special number but we only want to detect a simple number.
52 SpecialNumberOnly,
54 /**
55 * Keep an existing number format, do not set Text number format and do
56 * not set another number format.
58 Keep,
60 /**
61 * Never set Text number format.
63 Never
66 /**
67 * Stores the pointer to the number formatter instance to be used during
68 * number format detection. The caller must manage the life cycle of the
69 * instance.
71 SvNumberFormatter* mpNumFormatter;
73 /**
74 * When true, we try to detect special number format (dates etc) from the
75 * input string, when false, we only try to detect a basic decimal number
76 * format.
78 bool mbDetectNumberFormat;
80 /**
81 * Determine when to set the 'Text' number format to the cell where the
82 * input string is being set.
84 TextFormatPolicy meSetTextNumFormat;
86 /**
87 * When true, treat input with a leading apostrophe as an escape character
88 * for a numeric value content, to treat the numeric value as a text. When
89 * false, the whole string input including the leading apostrophe will be
90 * entered literally as string.
92 bool mbHandleApostrophe;
94 sc::StartListeningType meStartListening;
96 /** When true and the string results in a compiled formula, check the
97 formula tokens for presence of functions that could trigger access to
98 external resources. This is to be set to true in import filter code,
99 but not for user input.
101 bool mbCheckLinkFormula;
103 ScSetStringParam();
106 * Call this whenever you need to unconditionally set input as text, no
107 * matter what the input is.
109 void setTextInput();
112 * Call this whenever you need to maximize the chance of input being
113 * detected as a numeric value (numbers, dates, times etc).
115 void setNumericInput();
118 struct ScInputStringType
120 enum StringType { Unknown = 0, Text, Formula, Number };
122 StringType meType;
124 OUString maText;
125 double mfValue;
126 SvNumFormatType mnFormatType;
129 class ScStringUtil
131 public:
134 * Check if a given string is a simple decimal number (e.g. 12.345). We
135 * don't do any elaborate parsing here; we only check for the simplest
136 * case of decimal number format.
138 * Note that preceding and trailing spaces are ignored during parsing.
140 * @param rStr string to parse
141 * @param dsep decimal separator
142 * @param gsep group separator (aka thousands separator)
143 * @param dsepa decimal separator alternative, usually 0
144 * @param rVal value of successfully parsed number
146 * @return true if the string is a valid number, false otherwise.
148 static bool parseSimpleNumber(
149 const OUString& rStr, sal_Unicode dsep, sal_Unicode gsep, sal_Unicode dsepa, double& rVal);
151 static bool parseSimpleNumber(
152 const char* p, size_t n, char dsep, char gsep, double& rVal);
154 static sal_Int32 SC_DLLPUBLIC GetQuotedTokenCount(const OUString &rIn, const OUString& rQuotedPairs, sal_Unicode cTok );
155 static OUString SC_DLLPUBLIC GetQuotedToken(const OUString &rIn, sal_Int32 nToken, const OUString& rQuotedPairs,
156 sal_Unicode cTok, sal_Int32& rIndex );
158 static bool SC_DLLPUBLIC isMultiline( const OUString& rStr );
160 static ScInputStringType parseInputString(
161 SvNumberFormatter& rFormatter, const OUString& rStr, LanguageType eLang );
164 #endif
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */