LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sc / inc / stringutil.hxx
blob8cdb5821d0a92b4da9543e6b74e7388e04794185
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 #pragma once
22 #include <rtl/ustring.hxx>
23 #include "scdllapi.h"
24 #include <i18nlangtag/lang.h>
25 #include "types.hxx"
27 class SvNumberFormatter;
28 enum class SvNumFormatType : sal_Int16;
30 /**
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.
39 enum TextFormatPolicy
41 /**
42 * Set Text number format if the input string can be parsed as a number
43 * or formula text.
45 Always,
47 /**
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.
51 SpecialNumberOnly,
53 /**
54 * Keep an existing number format, do not set Text number format and do
55 * not set another number format.
57 Keep,
59 /**
60 * Never set Text number format.
62 Never
65 /**
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
68 * instance.
70 SvNumberFormatter* mpNumFormatter;
72 /**
73 * When true, we try to detect special number format (dates etc) from the
74 * input string, when false, we only try to detect a basic decimal number
75 * format.
77 bool mbDetectNumberFormat;
79 /**
80 * Determine when to set the 'Text' number format to the cell where the
81 * input string is being set.
83 TextFormatPolicy meSetTextNumFormat;
85 /**
86 * When true, treat input with a leading apostrophe as an escape character
87 * for a numeric value content, to treat the numeric value as a text. When
88 * false, the whole string input including the leading apostrophe will be
89 * entered literally as string.
91 bool mbHandleApostrophe;
93 sc::StartListeningType meStartListening;
95 /** When true and the string results in a compiled formula, check the
96 formula tokens for presence of functions that could trigger access to
97 external resources. This is to be set to true in import filter code,
98 but not for user input.
100 bool mbCheckLinkFormula;
102 ScSetStringParam();
105 * Call this whenever you need to unconditionally set input as text, no
106 * matter what the input is.
108 void setTextInput();
111 * Call this whenever you need to maximize the chance of input being
112 * detected as a numeric value (numbers, dates, times etc).
114 void setNumericInput();
117 struct ScInputStringType
119 enum StringType { Unknown = 0, Text, Formula, Number };
121 StringType meType;
123 OUString maText;
124 double mfValue;
125 SvNumFormatType mnFormatType;
128 class ScStringUtil
130 public:
133 * Check if a given string is a simple decimal number (e.g. 12.345). We
134 * don't do any elaborate parsing here; we only check for the simplest
135 * case of decimal number format.
137 * Note that preceding and trailing spaces are ignored during parsing.
139 * @param rStr string to parse
140 * @param dsep decimal separator
141 * @param gsep group separator (aka thousands separator)
142 * @param dsepa decimal separator alternative, usually 0
143 * @param rVal value of successfully parsed number
145 * @return true if the string is a valid number, false otherwise.
147 static bool parseSimpleNumber(
148 const OUString& rStr, sal_Unicode dsep, sal_Unicode gsep, sal_Unicode dsepa, double& rVal);
150 static bool parseSimpleNumber(
151 const char* p, size_t n, char dsep, char gsep, double& rVal);
153 static OUString SC_DLLPUBLIC GetQuotedToken(const OUString &rIn, sal_Int32 nToken, const OUString& rQuotedPairs,
154 sal_Unicode cTok, sal_Int32& rIndex );
156 static bool SC_DLLPUBLIC isMultiline( const OUString& rStr );
158 static ScInputStringType parseInputString(
159 SvNumberFormatter& rFormatter, const OUString& rStr, LanguageType eLang );
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */