24#include <rtl/ustrbuf.hxx>
25#include <rtl/strbuf.hxx>
26#include <rtl/math.hxx>
29 mpNumFormatter(nullptr),
30 mbDetectNumberFormat(true),
31 meSetTextNumFormat(Never),
32 mbHandleApostrophe(true),
34 mbCheckLinkFormula(false)
68 sal_Int32
n = rStr.getLength();
71 sal_Int32 nPosDSep = -1, nPosGSep = -1;
72 sal_uInt32 nDigitCount = 0;
73 bool haveSeenDigit =
false;
74 sal_Int32 nPosExponent = -1;
77 for (
i = 0;
i <
n; ++
i, ++
p)
80 if (c != 0x0020 && c != 0x00A0)
92 for (;
p != pLast; --pLast, --
n)
95 if (c != 0x0020 && c != 0x00A0)
100 for (
i = 0;
i <
n; ++
i, ++
p)
103 if (c == 0x0020 && gsep == 0x00A0)
107 if (
'0' <= c && c <=
'9')
111 haveSeenDigit =
true;
114 else if (c == dsep || (dsepa && c == dsepa))
122 if (nPosGSep >= 0 &&
i - nPosGSep != 4)
144 if (nPosGSep >= 0 && nDigitCount != 3)
148 if (nPosExponent >= 0)
155 else if (c ==
'-' || c ==
'+')
159 if (
i == 0 || (nPosExponent >= 0 &&
i == nPosExponent + 1))
164 else if (c ==
'E' || c ==
'e')
168 if (nPosExponent >= 0)
172 if (nPosGSep >= 0 && nDigitCount != 3)
188 if (nPosGSep >= 0 && nDigitCount != 3)
192 rtl_math_ConversionStatus eStatus = rtl_math_ConversionStatus_Ok;
193 sal_Int32 nParseEnd = 0;
194 rVal = ::rtl::math::stringToDouble(
aBuf, dsep, gsep, &eStatus, &nParseEnd);
195 if (eStatus != rtl_math_ConversionStatus_Ok || nParseEnd <
aBuf.getLength())
203 const char* p,
size_t n,
char dsep,
char gsep,
double& rVal)
218 const char* pLast =
p + (
n-1);
219 sal_Int32 nPosDSep = -1, nPosGSep = -1;
220 sal_uInt32 nDigitCount = 0;
221 bool haveSeenDigit =
false;
222 sal_Int32 nPosExponent = -1;
225 for (
i = 0;
i <
n; ++
i, ++
p)
240 for (;
p != pLast; --pLast, --
n)
248 for (
i = 0;
i <
n; ++
i, ++
p)
252 if (
'0' <= c && c <=
'9')
256 haveSeenDigit =
true;
267 if (nPosGSep >= 0 &&
i - nPosGSep != 4)
289 if (nPosGSep >= 0 && nDigitCount != 3)
293 if (nPosExponent >= 0)
300 else if (c ==
'-' || c ==
'+')
304 if (
i == 0 || (nPosExponent >= 0 &&
i ==
static_cast<size_t>(nPosExponent+1)))
309 else if (c ==
'E' || c ==
'e')
313 if (nPosExponent >= 0)
317 if (nPosGSep >= 0 && nDigitCount != 3)
333 if (nPosGSep >= 0 && nDigitCount != 3)
337 rtl_math_ConversionStatus eStatus = rtl_math_ConversionStatus_Ok;
338 sal_Int32 nParseEnd = 0;
339 rVal = ::rtl::math::stringToDouble(
aBuf, dsep, gsep, &eStatus, &nParseEnd);
340 if (eStatus != rtl_math_ConversionStatus_Ok || nParseEnd <
aBuf.getLength())
350 assert( !(rQuotedPairs.getLength()%2) );
351 assert( rQuotedPairs.indexOf(cTok) == -1 );
354 const sal_Unicode* pQuotedStr = rQuotedPairs.getStr();
356 sal_Int32 nQuotedLen = rQuotedPairs.getLength();
357 sal_Int32 nLen = rIn.getLength();
359 sal_Int32 nFirstChar = rIndex;
360 sal_Int32
i = nFirstChar;
367 if ( cQuotedEndChar )
370 if ( c == cQuotedEndChar )
376 sal_Int32 nQuoteIndex = 0;
377 while ( nQuoteIndex < nQuotedLen )
379 if ( pQuotedStr[nQuoteIndex] == c )
381 cQuotedEndChar = pQuotedStr[nQuoteIndex+1];
413 return rIn.copy( nFirstChar,
i-nFirstChar );
424 return rStr.find_first_of(
u"\n\r") != std::u16string_view::npos;
436 if (rStr.getLength() > 1 && rStr[0] ==
'=')
440 else if (rStr.getLength() > 1 && rStr[0] ==
'\'')
444 aRet.
maText = rStr.copy(1);
456 else if (!rStr.isEmpty())
static bool parseSimpleNumber(const OUString &rStr, sal_Unicode dsep, sal_Unicode gsep, sal_Unicode dsepa, double &rVal)
Check if a given string is a simple decimal number (e.g.
static OUString SC_DLLPUBLIC GetQuotedToken(const OUString &rIn, sal_Int32 nToken, const OUString &rQuotedPairs, sal_Unicode cTok, sal_Int32 &rIndex)
static ScInputStringType parseInputString(SvNumberFormatter &rFormatter, const OUString &rStr, LanguageType eLang)
static bool SC_DLLPUBLIC isMultiline(std::u16string_view rStr)
CAUTION! The following defines must be in the same namespace as the respective type.
bool mbHandleApostrophe
When true, treat input with a leading apostrophe as an escape character for all content,...
void setTextInput()
Call this whenever you need to unconditionally set input as text, no matter what the input is.
void setNumericInput()
Call this whenever you need to maximize the chance of input being detected as a numeric value (number...
bool mbDetectNumberFormat
When true, we try to detect special number format (dates etc) from the input string,...
@ Always
Set Text number format if the input string can be parsed as a number or formula text.
@ Never
Never set Text number format.
TextFormatPolicy meSetTextNumFormat
Determine when to set the 'Text' number format to the cell where the input string is being set.