summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Balland-Poirier <laurent.balland-poirier@laposte.net>2017-02-26 19:40:30 +0100
committerChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>2017-03-07 16:44:13 +0000
commit8eb29021352dd7d92f3fa225e18a85cd780e04db (patch)
tree0a01e43f7b57af154b4f17827869e5f05cbb1415
parent82c4fc4909e3e3e8ab2b266820843aa6c5d52050 (diff)
tdf#106190 fix left alignment of denominator
The bug was introduced with left aligment of denominator. Non feasable denominators were not tested and create infinite loop while inserting and removing the same space. This patch detects - if denominator starts just after fraction bar. Otherwise, format is faulty. - if a non digit is detected in the denominator, next part of format is treated as text This patch is changing behavior of some formats: "# ?/foo??" is treated as faulty format while it was considered as valid "# ?/??E?" is treated with 2 digits in denominator and "E?" at the end, while it was considered as faulty Change-Id: I0379a398dff79b6e21a44776c0d4356d066cdeab Reviewed-on: https://gerrit.libreoffice.org/34659 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Eike Rathke <erack@redhat.com> (cherry picked from commit b2738c6f67cb650ac32228f3cd20b9dfe4b41c9c) Reviewed-on: https://gerrit.libreoffice.org/34826 Reviewed-by: Michael Stahl <mstahl@redhat.com> Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com> Tested-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
-rw-r--r--svl/source/numbers/zformat.cxx4
-rw-r--r--svl/source/numbers/zforscan.cxx43
-rw-r--r--svl/source/numbers/zforscan.hxx1
3 files changed, 35 insertions, 13 deletions
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index ac0c6080ee4c..09e024eaccac 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -2815,9 +2815,9 @@ bool SvNumberformat::ImpGetFractionOutput(double fNumber,
sal_Int32 k; // Denominator
bRes |= ImpNumberFill(sDiv, fNumber, k, j, nIx, NF_SYMBOLTYPE_FRAC);
- if ( !bHideFraction )
+ if ( !bHideFraction && sDenominatorFormat.getLength() > 0 )
{
- while ( sDiv[0] == ' ' )
+ while ( sDiv[0] == ' ' ) // left align denominator
{
sDiv.insert( sDenominatorFormat.getLength(), " " );
sDiv.remove( 0, 1 );
diff --git a/svl/source/numbers/zforscan.cxx b/svl/source/numbers/zforscan.cxx
index 0542cf34c134..5529dcc29462 100644
--- a/svl/source/numbers/zforscan.cxx
+++ b/svl/source/numbers/zforscan.cxx
@@ -1079,6 +1079,7 @@ void ImpSvNumberformatScan::Reset()
nCntExp = 0;
bFrac = false;
bBlank = false;
+ bDenomin = false;
nNatNumModifier = 0;
}
@@ -1666,6 +1667,8 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString )
}
else if ( sStrArray[i][0] == ' ' )
nTypeArray[i] = NF_SYMBOLTYPE_FRACBLANK;
+ else if ( bFrac )
+ bDenomin = true; // following elements are no more part of denominator
}
else if (nTypeArray[i] == NF_KEY_THAI_T)
{
@@ -1673,7 +1676,7 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString )
sStrArray[i] = sKeyword[nTypeArray[i]];
}
else if (sStrArray[i][0] >= '0' &&
- sStrArray[i][0] <= '9')
+ sStrArray[i][0] <= '9' && !bDenomin) // denominator was not yet found
{
OUString sDiv;
sal_uInt16 j = i;
@@ -1702,10 +1705,14 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString )
{
nCntPre++;
}
+ if ( bFrac )
+ bDenomin = true; // next content should be treated as outside denominator
}
}
else
{
+ if ( bFrac )
+ bDenomin = true; // next content should be treated as outside denominator
nTypeArray[i] = NF_SYMBOLTYPE_STRING;
}
nPos = nPos + sStrArray[i].getLength();
@@ -1741,19 +1748,27 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString )
{
return nPos; // Error
}
- nTypeArray[i] = NF_SYMBOLTYPE_DIGIT;
- nPos = nPos + rStr.getLength();
- i++;
- nCounter++;
- while (i < nAnzStrings &&
- (sStrArray[i][0] == '#' ||
- sStrArray[i][0] == '0' ||
- sStrArray[i][0] == '?'))
+ if ( !bDenomin )
{
nTypeArray[i] = NF_SYMBOLTYPE_DIGIT;
- nPos = nPos + sStrArray[i].getLength();
- nCounter++;
+ nPos = nPos + rStr.getLength();
i++;
+ nCounter++;
+ while (i < nAnzStrings &&
+ (sStrArray[i][0] == '#' ||
+ sStrArray[i][0] == '0' ||
+ sStrArray[i][0] == '?'))
+ {
+ nTypeArray[i] = NF_SYMBOLTYPE_DIGIT;
+ nPos = nPos + sStrArray[i].getLength();
+ nCounter++;
+ i++;
+ }
+ }
+ else // after denominator, treat any character as text
+ {
+ nTypeArray[i] = NF_SYMBOLTYPE_STRING;
+ nPos = nPos + sStrArray[i].getLength();
}
break;
case '-':
@@ -1816,6 +1831,8 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString )
else
{
nTypeArray[i] = NF_SYMBOLTYPE_STRING;
+ if ( bFrac )
+ bDenomin = true; // end of denominator
}
}
else if (i > 0 && i < nAnzStrings-1 &&
@@ -1982,12 +1999,16 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString )
nCntPre = nCounter;
nCounter = 0;
}
+ if ( bFrac )
+ bDenomin = true; // next content is not part of denominator
nTypeArray[i] = NF_SYMBOLTYPE_STRING;
nPos = nPos + sStrArray[i].getLength();
}
else
{
nTypeArray[i] = NF_SYMBOLTYPE_STRING;
+ if ( bFrac )
+ bDenomin = true; // next content is not part of denominator
nPos = nPos + rStr.getLength();
i++;
while (i < nAnzStrings && StringEqualsChar( sStrArray[i], cSaved ) )
diff --git a/svl/source/numbers/zforscan.hxx b/svl/source/numbers/zforscan.hxx
index 001abe6de491..e0cec64bc859 100644
--- a/svl/source/numbers/zforscan.hxx
+++ b/svl/source/numbers/zforscan.hxx
@@ -174,6 +174,7 @@ private: // Private section
bool bExp; // Set when reading E
bool bFrac; // Set when reading /
bool bBlank; // Set when reading ' ' (Fraction)
+ bool bDenomin; // Set when reading end of denominator
bool bDecSep; // Set on first ,
mutable bool bKeywordsNeedInit; // Locale dependent keywords need to be initialized
mutable bool bCompatCurNeedInit; // Locale dependent compatibility currency need to be initialized