diff options
author | Daniel <danielfaleirosilva@gmail.com> | 2017-11-25 01:48:18 -0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-12-04 11:17:37 +0100 |
commit | 87efbdb1ae5a73d081667e10f1571f1e523c1b9c (patch) | |
tree | 25112ffbb2a01ee7134a06d1bba9c69e115ffdf9 | |
parent | b89834591f83058649dfa839297346ccc6ed689d (diff) |
tdf#105268 - Auto Fill: Fix The Next Value for 001-001-001
Change-Id: If1d1a23afb6209c35092d7cd95235ea1699fe7fb
Reviewed-on: https://gerrit.libreoffice.org/45262
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
(cherry picked from commit 76c1e7287e29a2a2739fce895fbded3c04764bca)
Reviewed-on: https://gerrit.libreoffice.org/45742
-rw-r--r-- | sc/source/core/data/table4.cxx | 67 |
1 files changed, 47 insertions, 20 deletions
diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx index f7bab382a76c..bd1d18d0443d 100644 --- a/sc/source/core/data/table4.cxx +++ b/sc/source/core/data/table4.cxx @@ -78,10 +78,10 @@ short lcl_DecompValueString( OUString& rValue, sal_Int32& nVal, sal_uInt16* pMin return 0; } const sal_Unicode* p = rValue.getStr(); - sal_Int32 nNeg = 0; + sal_Int32 nSign = 0; sal_Int32 nNum = 0; - if ( p[nNum] == '-' ) - nNum = nNeg = 1; + if ( p[nNum] == '-' || p[nNum] == '+' ) + nNum = nSign = 1; while ( p[nNum] && CharClass::isAsciiNumeric( OUString(p[nNum]) ) ) nNum++; @@ -91,34 +91,37 @@ short lcl_DecompValueString( OUString& rValue, sal_Int32& nVal, sal_uInt16* pMin // #i5550# If there are numbers at the beginning and the end, // prefer the one at the beginning only if it's followed by a space. // Otherwise, use the number at the end, to enable things like IP addresses. - if ( nNum > nNeg && ( cNext == 0 || cNext == ' ' || !CharClass::isAsciiNumeric(OUString(cLast)) ) ) + if ( nNum > nSign && ( cNext == 0 || cNext == ' ' || !CharClass::isAsciiNumeric(OUString(cLast)) ) ) { // number at the beginning nVal = rValue.copy( 0, nNum ).toInt32(); // any number with a leading zero sets the minimum number of digits - if ( p[nNeg] == '0' && pMinDigits && ( nNum - nNeg > *pMinDigits ) ) - *pMinDigits = nNum - nNeg; + if ( p[nSign] == '0' && pMinDigits && ( nNum - nSign > *pMinDigits ) ) + *pMinDigits = nNum - nSign; rValue = rValue.copy(nNum); return -1; } else { - nNeg = 0; + nSign = 0; sal_Int32 nEnd = nNum = rValue.getLength() - 1; while ( nNum && CharClass::isAsciiNumeric( OUString(p[nNum]) ) ) nNum--; - if ( p[nNum] == '-' ) + if ( p[nNum] == '-' || p[nNum] == '+' ) { nNum--; - nNeg = 1; + nSign = 1; } - if ( nNum < nEnd - nNeg ) + if ( nNum < nEnd - nSign ) { // number at the end nVal = rValue.copy( nNum + 1 ).toInt32(); // any number with a leading zero sets the minimum number of digits - if ( p[nNum+1+nNeg] == '0' && pMinDigits && ( nEnd - nNum - nNeg > *pMinDigits ) ) - *pMinDigits = nEnd - nNum - nNeg; + if ( p[nNum+1+nSign] == '0' && pMinDigits && ( nEnd - nNum - nSign > *pMinDigits ) ) + *pMinDigits = nEnd - nNum - nSign; rValue = rValue.copy(0, nNum + 1); - return 1; + if (nSign) // use the return value = 2 to put back the '+' + return 2; + else + return 1; } } nVal = 0; @@ -938,11 +941,19 @@ OUString ScTable::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW { if (aValue == ScGlobal::GetOrdinalSuffix( nVal)) aValue = ScGlobal::GetOrdinalSuffix( nVal + nDelta); - aValue = lcl_ValueString( nVal + nDelta, nCellDigits ) + aValue; } else if ( nFlag > 0 ) - aValue += lcl_ValueString( nVal + nDelta, nCellDigits ); + { + sal_Int32 nNextValue; + if ( nVal < 0 ) + nNextValue = nVal - nDelta; + else + nNextValue = nVal + nDelta; + if ( nFlag == 2 && nNextValue >= 0 ) // Put back the '+' + aValue += "+"; + aValue += lcl_ValueString( nNextValue, nCellDigits ); + } } } break; @@ -1044,7 +1055,11 @@ OUString ScTable::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW aValue = lcl_ValueString( (sal_Int32)nStart, nMinDigits ) + aValue; } else + { + if ( nHeadNoneTail == 2 && nStart >= 0 ) // Put back the '+' + aValue += "+"; aValue += lcl_ValueString( (sal_Int32)nStart, nMinDigits ); + } } else { @@ -1434,7 +1449,12 @@ void ScTable::FillAutoSimple( case CELLTYPE_EDIT: if ( nHeadNoneTail ) { - sal_Int32 nNextValue = nStringValue+(sal_Int32)nDelta; + sal_Int32 nNextValue; + if (nStringValue < 0) + nNextValue = nStringValue - (sal_Int32)nDelta; + else + nNextValue = nStringValue + (sal_Int32)nDelta; + if ( nHeadNoneTail < 0 ) { setSuffixCell( @@ -1444,13 +1464,17 @@ void ScTable::FillAutoSimple( } else { - OUString aStr = aValue + lcl_ValueString(nNextValue, - nCellDigits ); + OUString aStr; + if (nHeadNoneTail == 2 && nNextValue >= 0) // Put back the '+' + aStr = aValue + "+" + lcl_ValueString(nNextValue, nCellDigits); + else + aStr = aValue + lcl_ValueString(nNextValue, nCellDigits); + aCol[rCol].SetRawString(rRow, aStr); } } else - aSrcCell.commit(aCol[rCol], rRow); + aSrcCell.commit(aCol[rCol], rRow); break; case CELLTYPE_FORMULA : @@ -1885,7 +1909,10 @@ void ScTable::FillSeries( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, } else { - aStr = aValue; + if (nHeadNoneTail == 2 && nStringValue >= 0) // Put back the '+' + aStr = aValue + "+"; + else + aStr = aValue; aStr += lcl_ValueString( nStringValue, nMinDigits ); aCol[nCol].SetRawString(static_cast<SCROW>(nRow), aStr); } |