Kaydet (Commit) e59a75c9 authored tarafından Norbert Thiebaud's avatar Norbert Thiebaud

migrate ImpNumberFillWithThousand implementation to OUString[Buffer]

Change-Id: Ife0fbb28ba2686a9a251757e109f2ac451296192
üst 61c7f9b6
...@@ -607,12 +607,12 @@ private: ...@@ -607,12 +607,12 @@ private:
// Helper function to fill in the group (AKA thousand) separators // Helper function to fill in the group (AKA thousand) separators
// or to skip additional digits // or to skip additional digits
SVL_DLLPRIVATE void ImpDigitFill( String& sStr, SVL_DLLPRIVATE void ImpDigitFill( OUStringBuffer& sStr,
xub_StrLen nStart, sal_Int32 nStart,
xub_StrLen& k, sal_Int32& k,
sal_uInt16 nIx, sal_uInt16 nIx,
xub_StrLen & nDigitCount, sal_Int32 & nDigitCount,
utl::DigitGroupingIterator & ); utl::DigitGroupingIterator & );
SVL_DLLPRIVATE bool ImpGetFractionOutput(double fNumber, SVL_DLLPRIVATE bool ImpGetFractionOutput(double fNumber,
sal_uInt16 nIx, sal_uInt16 nIx,
......
...@@ -4388,19 +4388,22 @@ bool SvNumberformat::ImpGetNumberOutput(double fNumber, ...@@ -4388,19 +4388,22 @@ bool SvNumberformat::ImpGetNumberOutput(double fNumber,
bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number string bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number string
double& rNumber, // number double& rNumber, // number
xub_StrLen k, // position within string xub_StrLen kin, // position within string
sal_uInt16 j, // symbol index within format code sal_uInt16 j, // symbol index within format code
sal_uInt16 nIx, // subformat index sal_uInt16 nIx, // subformat index
sal_uInt16 nDigCnt) // count of integer digits in format sal_uInt16 nDigCnt) // count of integer digits in format
{ {
bool bRes = false; bool bRes = false;
xub_StrLen nLeadingStringChars = 0; // inserted StringChars before number sal_Int32 k = (sal_Int32)kin;
xub_StrLen nDigitCount = 0; // count of integer digits from the right OUStringBuffer sBuff(sStr);
sal_Int32 nLeadingStringChars = 0; // inserted StringChars before number
sal_Int32 nDigitCount = 0; // count of integer digits from the right
bool bStop = false; bool bStop = false;
const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info(); const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info();
// no normal thousands separators if number divided by thousands // no normal thousands separators if number divided by thousands
bool bDoThousands = (rInfo.nThousand == 0); bool bDoThousands = (rInfo.nThousand == 0);
utl::DigitGroupingIterator aGrouping( GetFormatter().GetLocaleData()->getDigitGrouping()); utl::DigitGroupingIterator aGrouping( GetFormatter().GetLocaleData()->getDigitGrouping());
while (!bStop) // backwards while (!bStop) // backwards
{ {
if (j == 0) if (j == 0)
...@@ -4415,7 +4418,7 @@ bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number s ...@@ -4415,7 +4418,7 @@ bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number s
case NF_SYMBOLTYPE_STRING: case NF_SYMBOLTYPE_STRING:
case NF_SYMBOLTYPE_CURRENCY: case NF_SYMBOLTYPE_CURRENCY:
case NF_SYMBOLTYPE_PERCENT: case NF_SYMBOLTYPE_PERCENT:
sStr.Insert(rInfo.sStrArray[j],k); sBuff.insert(k, rInfo.sStrArray[j]);
if ( k == 0 ) if ( k == 0 )
{ {
nLeadingStringChars = nLeadingStringChars + rInfo.sStrArray[j].getLength(); nLeadingStringChars = nLeadingStringChars + rInfo.sStrArray[j].getLength();
...@@ -4424,13 +4427,13 @@ bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number s ...@@ -4424,13 +4427,13 @@ bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number s
case NF_SYMBOLTYPE_STAR: case NF_SYMBOLTYPE_STAR:
if( bStarFlag ) if( bStarFlag )
{ {
sStr.Insert(rInfo.sStrArray[j][1], k); sBuff.insert(k, rInfo.sStrArray[j][1]);
sStr.Insert( (sal_Unicode) 0x1B, k ); sBuff.insert(k, (sal_Unicode) 0x1B);
bRes = true; bRes = true;
} }
break; break;
case NF_SYMBOLTYPE_BLANK: case NF_SYMBOLTYPE_BLANK:
/*k = */ InsertBlanks( sStr,k,rInfo.sStrArray[j][1] ); /*k = */ InsertBlanks(sBuff, k, rInfo.sStrArray[j][1] );
break; break;
case NF_SYMBOLTYPE_THSEP: case NF_SYMBOLTYPE_THSEP:
// #i7284# #102685# Insert separator also if number is divided // #i7284# #102685# Insert separator also if number is divided
...@@ -4453,7 +4456,7 @@ bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number s ...@@ -4453,7 +4456,7 @@ bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number s
{ {
if (k > 0) if (k > 0)
{ {
sStr.Insert(rInfo.sStrArray[j],k); sBuff.insert(k, rInfo.sStrArray[j]);
} }
else if (nDigitCount < nDigCnt) else if (nDigitCount < nDigCnt)
{ {
...@@ -4465,11 +4468,11 @@ bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number s ...@@ -4465,11 +4468,11 @@ bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number s
sal_Unicode cLeader = 0; sal_Unicode cLeader = 0;
if (j > 0 && rInfo.nTypeArray[j-1] == NF_SYMBOLTYPE_DIGIT) if (j > 0 && rInfo.nTypeArray[j-1] == NF_SYMBOLTYPE_DIGIT)
{ {
const String& rStr = rInfo.sStrArray[j-1]; const OUString& rStr = rInfo.sStrArray[j-1];
xub_StrLen nLen = rStr.Len(); sal_Int32 nLen = rStr.getLength();
if (nLen) if (nLen)
{ {
cLeader = rStr.GetChar(nLen-1); cLeader = rStr[ nLen - 1 ];
} }
} }
switch (cLeader) switch (cLeader)
...@@ -4485,10 +4488,10 @@ bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number s ...@@ -4485,10 +4488,10 @@ bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number s
// a literal ',' character instead that is // a literal ',' character instead that is
// inserted unconditionally. Should be changed // inserted unconditionally. Should be changed
// on some occasion. // on some occasion.
sStr.Insert(' ',k); sBuff.insert(k, (sal_Unicode)' ');
break; break;
default: default:
sStr.Insert(rInfo.sStrArray[j],k); sBuff.insert(k, rInfo.sStrArray[j]);
} }
} }
aGrouping.advance(); aGrouping.advance();
...@@ -4496,9 +4499,9 @@ bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number s ...@@ -4496,9 +4499,9 @@ bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number s
break; break;
case NF_SYMBOLTYPE_DIGIT: case NF_SYMBOLTYPE_DIGIT:
{ {
const String& rStr = rInfo.sStrArray[j]; const OUString& rStr = rInfo.sStrArray[j];
const sal_Unicode* p1 = rStr.GetBuffer(); const sal_Unicode* p1 = rStr.getStr();
register const sal_Unicode* p = p1 + rStr.Len(); register const sal_Unicode* p = p1 + rStr.getLength();
while ( p1 < p-- ) while ( p1 < p-- )
{ {
nDigitCount++; nDigitCount++;
...@@ -4511,29 +4514,30 @@ bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number s ...@@ -4511,29 +4514,30 @@ bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number s
switch (*p) switch (*p)
{ {
case '0': case '0':
sStr.Insert('0',0); sBuff.insert(0, (sal_Unicode)'0');
break; break;
case '?': case '?':
sStr.Insert(' ',0); sBuff.insert(0, (sal_Unicode)' ');
break; break;
} }
} }
if (nDigitCount == nDigCnt && k > 0) if (nDigitCount == nDigCnt && k > 0)
{ // more digits than specified {
ImpDigitFill(sStr, 0, k, nIx, nDigitCount, aGrouping); // more digits than specified
ImpDigitFill(sBuff, 0, k, nIx, nDigitCount, aGrouping);
} }
} }
break; break;
} }
case NF_KEY_CCC: // CCC currency case NF_KEY_CCC: // CCC currency
sStr.Insert(rScan.GetCurAbbrev(), k); sBuff.insert(k, rScan.GetCurAbbrev());
break; break;
case NF_KEY_GENERAL: // "General" in string case NF_KEY_GENERAL: // "General" in string
{ {
String sNum; String sNum;
ImpGetOutputStandard(rNumber, sNum); ImpGetOutputStandard(rNumber, sNum);
sNum = comphelper::string::stripStart(sNum, '-'); sNum = comphelper::string::stripStart(sNum, '-');
sStr.Insert(sNum, k); sBuff.insert(k, OUString(sNum));
break; break;
} }
default: default:
...@@ -4545,26 +4549,27 @@ bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number s ...@@ -4545,26 +4549,27 @@ bool SvNumberformat::ImpNumberFillWithThousands( String& sStr, // number s
k = k + nLeadingStringChars; // MSC converts += to int and then warns, so ... k = k + nLeadingStringChars; // MSC converts += to int and then warns, so ...
if (k > nLeadingStringChars) if (k > nLeadingStringChars)
{ {
ImpDigitFill(sStr, nLeadingStringChars, k, nIx, nDigitCount, aGrouping); ImpDigitFill(sBuff, nLeadingStringChars, k, nIx, nDigitCount, aGrouping);
} }
sStr = sBuff.makeStringAndClear();
return bRes; return bRes;
} }
void SvNumberformat::ImpDigitFill(String& sStr, // number string void SvNumberformat::ImpDigitFill(OUStringBuffer& sStr, // number string
xub_StrLen nStart, // start of digits sal_Int32 nStart, // start of digits
xub_StrLen& k, // position within string sal_Int32 & k, // position within string
sal_uInt16 nIx, // subformat index sal_uInt16 nIx, // subformat index
xub_StrLen & nDigitCount, // count of integer digits from the right so far sal_Int32 & nDigitCount, // count of integer digits from the right so far
utl::DigitGroupingIterator & rGrouping ) // current grouping utl::DigitGroupingIterator & rGrouping ) // current grouping
{ {
if (NumFor[nIx].Info().bThousand) // only if grouping if (NumFor[nIx].Info().bThousand) // only if grouping
{ // fill in separators { // fill in separators
const String& rThousandSep = GetFormatter().GetNumThousandSep(); const OUString& rThousandSep = GetFormatter().GetNumThousandSep();
while (k > nStart) while (k > nStart)
{ {
if (nDigitCount == rGrouping.getPos()) if (nDigitCount == rGrouping.getPos())
{ {
sStr.Insert( rThousandSep, k ); sStr.insert( k, rThousandSep );
rGrouping.advance(); rGrouping.advance();
} }
nDigitCount++; nDigitCount++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment