24#include <rtl/ustrbuf.hxx>
25#include <rtl/strbuf.hxx>
26#include <rtl/math.hxx>
29 mpNumFormatter(nullptr),
30 mbDetectNumberFormat(true),
31 mbDetectScientificNumberFormat(true),
32 meSetTextNumFormat(Never),
33 mbHandleApostrophe(true),
35 mbCheckLinkFormula(false)
71 sal_Int32
n = rStr.getLength();
74 sal_Int32 nPosDSep = -1, nPosGSep = -1;
75 sal_uInt32 nDigitCount = 0;
76 bool haveSeenDigit =
false;
77 sal_Int32 nPosExponent = -1;
80 for (
i = 0;
i <
n; ++
i, ++
p)
83 if (c != 0x0020 && c != 0x00A0)
95 for (;
p != pLast; --pLast, --
n)
98 if (c != 0x0020 && c != 0x00A0)
103 for (
i = 0;
i <
n; ++
i, ++
p)
106 if (c == 0x0020 && gsep == 0x00A0)
110 if (
'0' <= c && c <=
'9')
114 haveSeenDigit =
true;
117 else if (c == dsep || (dsepa && c == dsepa))
125 if (nPosGSep >= 0 &&
i - nPosGSep != 4)
147 if (nPosGSep >= 0 && nDigitCount != 3)
151 if (nPosExponent >= 0)
158 else if (c ==
'-' || c ==
'+')
162 if (
i == 0 || (nPosExponent >= 0 &&
i == nPosExponent + 1))
167 else if (c ==
'E' || c ==
'e')
171 if (nPosExponent >= 0 || !bDetectScientificNumber)
175 if (nPosGSep >= 0 && nDigitCount != 3)
191 if (nPosGSep >= 0 && nDigitCount != 3)
195 rtl_math_ConversionStatus eStatus = rtl_math_ConversionStatus_Ok;
196 sal_Int32 nParseEnd = 0;
197 rVal = ::rtl::math::stringToDouble(
aBuf, dsep, gsep, &eStatus, &nParseEnd);
198 if (eStatus != rtl_math_ConversionStatus_Ok || nParseEnd <
aBuf.getLength())
206 const char* p,
size_t n,
char dsep,
char gsep,
double& rVal)
221 const char* pLast =
p + (
n-1);
222 sal_Int32 nPosDSep = -1, nPosGSep = -1;
223 sal_uInt32 nDigitCount = 0;
224 bool haveSeenDigit =
false;
225 sal_Int32 nPosExponent = -1;
228 for (
i = 0;
i <
n; ++
i, ++
p)
243 for (;
p != pLast; --pLast, --
n)
251 for (
i = 0;
i <
n; ++
i, ++
p)
255 if (
'0' <= c && c <=
'9')
259 haveSeenDigit =
true;
270 if (nPosGSep >= 0 &&
i - nPosGSep != 4)
292 if (nPosGSep >= 0 && nDigitCount != 3)
296 if (nPosExponent >= 0)
303 else if (c ==
'-' || c ==
'+')
307 if (
i == 0 || (nPosExponent >= 0 &&
i ==
static_cast<size_t>(nPosExponent+1)))
312 else if (c ==
'E' || c ==
'e')
316 if (nPosExponent >= 0)
320 if (nPosGSep >= 0 && nDigitCount != 3)
336 if (nPosGSep >= 0 && nDigitCount != 3)
340 rtl_math_ConversionStatus eStatus = rtl_math_ConversionStatus_Ok;
341 sal_Int32 nParseEnd = 0;
342 rVal = ::rtl::math::stringToDouble(
aBuf, dsep, gsep, &eStatus, &nParseEnd);
343 if (eStatus != rtl_math_ConversionStatus_Ok || nParseEnd <
aBuf.getLength())
353 assert( !(rQuotedPairs.getLength()%2) );
354 assert( rQuotedPairs.indexOf(cTok) == -1 );
357 const sal_Unicode* pQuotedStr = rQuotedPairs.getStr();
359 sal_Int32 nQuotedLen = rQuotedPairs.getLength();
360 sal_Int32 nLen = rIn.getLength();
362 sal_Int32 nFirstChar = rIndex;
363 sal_Int32
i = nFirstChar;
370 if ( cQuotedEndChar )
373 if ( c == cQuotedEndChar )
379 sal_Int32 nQuoteIndex = 0;
380 while ( nQuoteIndex < nQuotedLen )
382 if ( pQuotedStr[nQuoteIndex] == c )
384 cQuotedEndChar = pQuotedStr[nQuoteIndex+1];
416 return rIn.copy( nFirstChar,
i-nFirstChar );
427 return rStr.find_first_of(
u"\n\r") != std::u16string_view::npos;
439 if (rStr.getLength() > 1 && rStr[0] ==
'=')
443 else if (rStr.getLength() > 1 && rStr[0] ==
'\'')
447 aRet.
maText = rStr.copy(1);
459 else if (!rStr.isEmpty())
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)
static bool parseSimpleNumber(const OUString &rStr, sal_Unicode dsep, sal_Unicode gsep, sal_Unicode dsepa, double &rVal, bool bDetectScientificNumber=true)
Check if a given string is a simple decimal number (e.g.
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.
bool mbDetectScientificNumberFormat
void setNumericInput()
Call this whenever you need to maximize the chance of input being detected as a numeric value (number...
bool mbDetectNumberFormat
Specify which number formats are detected: mbDetectNumberFormat=true && mbDetectScientificNumberForma...
@ 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.