24#include <rtl/ustrbuf.hxx>
26#include <rtl/character.hxx>
51#define MAX_NO_OF_DIGITS DBL_DIG
52#define MAX_DOUBLE_BUFFER_LENGTH MAX_NO_OF_DIGITS + 9
60#define CREATE_1000SEP_CHAR '@'
62#define FORMAT_SEPARATOR ';'
93 return floor( log10( fabs( dNumber ) ) );
103 OUString _sFalseStrg,
104 OUString _sCurrencyStrg,
105 OUString _sCurrencyFormatStrg )
106 : cDecPoint(_cDecPoint)
107 , cThousandSep(_cThousandSep)
108 , sOnStrg(
std::move(_sOnStrg))
109 , sOffStrg(
std::move(_sOffStrg))
110 , sYesStrg(
std::move(_sYesStrg))
111 , sNoStrg(
std::move(_sNoStrg))
112 , sTrueStrg(
std::move(_sTrueStrg))
113 , sFalseStrg(
std::move(_sFalseStrg))
114 , sCurrencyStrg(
std::move(_sCurrencyStrg))
115 , sCurrencyFormatStrg(
std::move(_sCurrencyFormatStrg))
129 sStrg.remove(nStartPos,1);
134 if( nDigit>=0 && nDigit<=9 )
136 sStrg.append(
static_cast<sal_Unicode>(nDigit+
'0'));
144 for(sal_Int32
i = 0;
i < sStrg.getLength();
i++)
180 while(
nPos >= 0 && ! rtl::isAsciiDigit(sStrg[
nPos]))
193 if( rtl::isAsciiDigit(c2) )
202 sStrg[
nPos] = c2 + 1;
208 sStrg[
nPos + 1] =
'1';
224 for( sal_Int32
i = nFormatPos;
225 i>0 && sFormatStrg[
i ] ==
'#' && sStrg[sStrg.getLength() - 1] ==
'0';
228 sStrg.setLength(sStrg.getLength() - 1 );
240 sSciNumStrg = OUString::createFromAscii( sBuffer );
246 nNumExp =
static_cast<short>(_dNewExp);
272 bFoundFirstDigit =
true;
273 return static_cast<short>(
sSciNumStrg[ no ] -
'0');
285 bFoundFirstDigit =
true;
286 return static_cast<short>(
sNumExpStrg[ no ] -
'0');
292 bool& bFoundFirstDigit )
306 if(
nPos != std::u16string_view::npos )
311 return OUString(sFormatStrg.substr( 0,
nPos ));
323 if(
nPos != std::u16string_view::npos)
327 std::u16string_view sTempStrg = sFormatStrg.substr(
nPos+1 );
330 if(
nPos == std::u16string_view::npos )
332 return OUString(sTempStrg);
336 return OUString(sTempStrg.substr( 0,
nPos ));
348 if(
nPos != std::u16string_view::npos )
352 std::u16string_view sTempStrg = sFormatStrg.substr(
nPos+1 );
354 if(
nPos != std::u16string_view::npos )
357 sTempStrg = sTempStrg.substr(
nPos+1 );
359 if(
nPos == std::u16string_view::npos )
361 return OUString(sTempStrg);
365 return OUString(sTempStrg.substr( 0,
nPos ));
379 if(
nPos != std::u16string_view::npos )
383 std::u16string_view sTempStrg = sFormatStrg.substr(
nPos+1 );
385 if(
nPos != std::u16string_view::npos )
387 sTempStrg = sTempStrg.substr(
nPos+1 );
389 if(
nPos != std::u16string_view::npos )
392 return OUString(sTempStrg.substr(
nPos+1 ));
402 short& nNoOfDigitsLeft,
short& nNoOfDigitsRight,
403 short& nNoOfOptionalDigitsLeft,
404 short& nNoOfExponentDigits,
short& nNoOfOptionalExponentDigits,
405 bool& bPercent,
bool& bCurrency,
bool& bScientific,
406 bool& bGenerateThousandSeparator,
407 short& nMultipleThousandSeparators )
412 nLen = sFormatStrg.size();
414 nNoOfDigitsRight = 0;
415 nNoOfOptionalDigitsLeft = 0;
416 nNoOfExponentDigits = 0;
417 nNoOfOptionalExponentDigits = 0;
423 bGenerateThousandSeparator = sFormatStrg.find(
',' ) != std::u16string_view::npos;
424 nMultipleThousandSeparators = 0;
426 for( sal_Int32
i = 0;
i < nLen;
i++ )
442 nNoOfOptionalDigitsLeft++;
453 nNoOfOptionalExponentDigits++;
456 nNoOfExponentDigits++;
465 nNoOfOptionalExponentDigits++;
466 nNoOfExponentDigits++;
486 if(
ch!=0 && (
ch==
',' ||
ch==
'.') )
488 nMultipleThousandSeparators++;
495 if( nNoOfDigitsLeft > 0 || nNoOfDigitsRight > 0 )
508 bGenerateThousandSeparator =
true;
517 std::u16string_view sFormatStrg, OUString& sReturnStrgFinal,
520 short nNoOfDigitsLeft,nNoOfDigitsRight,nNoOfOptionalDigitsLeft,
521 nNoOfExponentDigits,nNoOfOptionalExponentDigits,
522 nMultipleThousandSeparators;
523 bool bPercent,bCurrency,bScientific,bGenerateThousandSeparator;
525 OUStringBuffer sReturnStrg(32);
545 nNoOfOptionalDigitsLeft, nNoOfExponentDigits,
546 nNoOfOptionalExponentDigits,
547 bPercent, bCurrency, bScientific,
548 bGenerateThousandSeparator, nMultipleThousandSeparators );
556 if( nMultipleThousandSeparators )
562 short nState,nDigitPos,nExponentPos,nMaxDigit,nMaxExponentDigit;
563 bool bFirstDigit,bFirstExponentDigit,bFoundFirstDigit,
564 bIsNegative,bZeroSpaceOn, bSignHappend,bDigitPosNegative;
566 bSignHappend =
false;
567 bFoundFirstDigit =
false;
568 bIsNegative = dNumber < 0.0;
569 nLen = sFormatStrg.size();
572 nMaxExponentDigit = 0;
573 nMaxDigit =
static_cast<short>(dExponent);
574 bDigitPosNegative =
false;
577 dExponent = dExponent -
static_cast<double>(nNoOfDigitsLeft-1);
578 nDigitPos = nMaxDigit;
580 nExponentPos = nNoOfExponentDigits - 1 - nNoOfOptionalExponentDigits;
584 nDigitPos = nNoOfDigitsLeft - 1;
586 bDigitPosNegative = (nDigitPos < 0);
589 bFirstExponentDigit =
true;
591 bZeroSpaceOn =
false;
597 for(
i = 0;
i < nLen;
i++ )
607 c = sFormatStrg[
i ];
620 if( bIsNegative && !bCreateSign && !bSignHappend )
623 sReturnStrg.append(
'-');
627 if( nMaxDigit > nDigitPos )
629 for(
short j = nMaxDigit; j > nDigitPos; j-- )
637 if( bGenerateThousandSeparator && c==
'0' && j > 0 && (j % 3 == 0) )
645 if( nMaxDigit<nDigitPos && ( c==
'0' || bZeroSpaceOn ) )
653 if (bGenerateThousandSeparator && c ==
'0' && nDigitPos > 0 && (nDigitPos % 3 == 0))
667 if( bGenerateThousandSeparator && ( c==
'0' || nMaxDigit>=nDigitPos ) && nDigitPos>0 && (nDigitPos % 3 == 0) )
677 if( bFirstExponentDigit )
680 bFirstExponentDigit =
false;
681 if( nMaxExponentDigit > nExponentPos )
685 for(
short j = nMaxExponentDigit; j > nExponentPos; j-- )
692 if( nMaxExponentDigit < nExponentPos && c==
'0' )
704 if( bDigitPosNegative )
706 bDigitPosNegative =
false;
717 sReturnStrg.append(
'%');
731 sReturnStrg.append(c);
735 bool bOverflow =
false;
739 StrRoundDigit( sReturnStrg, sReturnStrg.getLength() - 1, bOverflow );
745 sReturnStrg[sReturnStrg.getLength() - 1] = 0;
754 sReturnStrg.append(c);
756 c = sFormatStrg[ ++
i ];
762 if( dExponent < 0.0 )
764 sReturnStrg.append(
'-');
769 if( dExponent < 0.0 )
771 sReturnStrg.append(
'-');
775 sReturnStrg.append(
'+');
790 sReturnStrg.append(c);
801 sReturnStrg.append(c);
807 c = sFormatStrg[ ++
i ];
810 sReturnStrg.append(c);
819 if( ( c>=
'a' && c<=
'z' ) ||
820 ( c>=
'A' && c<=
'Z' ) ||
821 ( c>=
'1' && c<=
'9' ) )
823 sReturnStrg.append(c);
838 if( nNoOfDigitsRight>0 )
840 ParseBack( sReturnStrg, sFormatStrg, sFormatStrg.size()-1 );
842 sReturnStrgFinal = sReturnStrg.makeStringAndClear();
847 bool bNullFormatFound;
850 if( bNullFormatFound )
852 return sNullFormatStrg;
859 bool bPosFormatFound,bNegFormatFound,b0FormatFound;
860 OUString sFormatStrg = _sFormatStrg;
906 OUString sReturnStrg;
911 sTempStrg = sFormatStrg;
914 if( s0FormatStrg.isEmpty() && bPosFormatFound )
916 sTempStrg = sPosFormatStrg;
920 sTempStrg = s0FormatStrg;
923 else if( bPosFormatFound )
925 sTempStrg = sPosFormatStrg;
933 if( bNegFormatFound )
935 if( sNegFormatStrg.isEmpty() && bPosFormatFound )
937 sTempStrg =
"-" + sPosFormatStrg;
941 sTempStrg = sNegFormatStrg;
946 sTempStrg = sFormatStrg;
955 (bPosFormatFound ? sPosFormatStrg : sFormatStrg),
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
int sprintf(char(&s)[N], char const *format, T &&... arguments)
SwNodeOffset abs(const SwNodeOffset &a)