Update to m13
[ooovba.git] / applied_patches / 0189-calc-autofill-increment-fix.diff
blob6a7dd35eff3f932c01d9d6c7e8c2f334d70d0924
1 diff --git sc/source/core/data/table4.cxx sc/source/core/data/table4.cxx
2 index 2d43cbe..9ca13d2 100644
3 --- sc/source/core/data/table4.cxx
4 +++ sc/source/core/data/table4.cxx
5 @@ -94,48 +94,74 @@ extern USHORT nScFillModeMouseModifier; // global.cxx
7 short lcl_DecompValueString( String& aValue, sal_Int32& nVal, USHORT* pMinDigits = NULL )
9 - if ( !aValue.Len() )
10 + xub_StrLen nLen = aValue.Len();
11 + if (!nLen)
13 nVal = 0;
14 return 0;
16 const sal_Unicode* p = aValue.GetBuffer();
17 - xub_StrLen nNeg = 0;
18 - xub_StrLen nNum = 0;
19 - if ( p[nNum] == '-' )
20 - nNum = nNeg = 1;
21 - while ( p[nNum] && CharClass::isAsciiNumeric( p[nNum] ) )
22 - nNum++;
23 - if ( nNum > nNeg )
24 - { // number at the beginning
25 - nVal = aValue.Copy( 0, nNum ).ToInt32();
26 - // #60893# any number with a leading zero sets the minimum number of digits
27 - if ( p[nNeg] == '0' && pMinDigits && ( nNum - nNeg > *pMinDigits ) )
28 - *pMinDigits = nNum - nNeg;
29 - aValue.Erase( 0, nNum );
30 - return -1;
31 - }
32 - else
33 - {
34 - nNeg = 0;
35 - xub_StrLen nEnd = nNum = aValue.Len() - 1;
36 - while ( nNum && CharClass::isAsciiNumeric( p[nNum] ) )
37 - nNum--;
38 - if ( p[nNum] == '-' )
39 - {
40 - nNum--;
41 - nNeg = 1;
42 - }
43 - if ( nNum < nEnd - nNeg )
44 - { // number at the end
45 - nVal = aValue.Copy( nNum + 1 ).ToInt32();
46 - // #60893# any number with a leading zero sets the minimum number of digits
47 - if ( p[nNum+1+nNeg] == '0' && pMinDigits && ( nEnd - nNum - nNeg > *pMinDigits ) )
48 - *pMinDigits = nEnd - nNum - nNeg;
49 - aValue.Erase( nNum + 1 );
50 - return 1;
51 - }
52 - }
53 + xub_StrLen nSign = (p[0] == '+' || p[0] == '-') ? 1 : 0;
54 + xub_StrLen nDot = nLen, nFirst = nLen;
55 + String aBuf;
56 + bool bLeadingNum = true;
57 + for (xub_StrLen i = nSign; i < nLen; ++i)
58 + {
59 + sal_Unicode c = p[i];
60 + if (CharClass::isAsciiNumeric(c) && c != '+' && c != '-')
61 + {
62 + aBuf.Append(c);
63 + continue;
64 + }
65 + else
66 + {
67 + if (bLeadingNum)
68 + bLeadingNum = false;
69 + else
70 + aBuf.Erase();
71 + }
73 + if (nFirst == nLen)
74 + nFirst = i;
76 + if (c == '.')
77 + {
78 + // if it's a dot, erase the buffer and keep going.
79 + aBuf.Erase();
80 + nDot = i;
81 + continue;
82 + }
83 + else if (aBuf.Len())
84 + {
85 + // leading number
86 + if (nDot < nLen)
87 + {
88 + // If a dot has been previously encountered, then use the
89 + // first numerical segment.
90 + i = nFirst;
91 + aBuf = aValue.Copy(0, nFirst);
92 + }
94 + nVal = aBuf.ToInt32();
95 + if (nSign && p[0] == '-')
96 + nVal *= -1;
97 + aValue.Erase(0, i);
98 + if (pMinDigits)
99 + *pMinDigits = i - nSign;
100 + return -1;
103 + if (aBuf.Len())
105 + // trailing number.
106 + xub_StrLen nBufLen = aBuf.Len();
107 + nVal = aBuf.ToInt32();
108 + aValue.Erase(nLen - nBufLen);
109 + if (pMinDigits)
110 + *pMinDigits = nBufLen;
111 + return 1;
114 nVal = 0;
115 return 0;