Kaydet (Commit) 67db35da authored tarafından Matteo Casalin's avatar Matteo Casalin Kaydeden (comit) Caolán McNamara

DoubleToString: do not modify a reference argument, just return the result

Change-Id: I490aa61f8d9b47a6ead234afd51e2f5324530cb4
Reviewed-on: https://gerrit.libreoffice.org/4923Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 5bd6a511
...@@ -385,8 +385,8 @@ public: ...@@ -385,8 +385,8 @@ public:
inline void EnableFormat(sal_Bool bFormat = sal_True) { bUseFormat = bFormat; } inline void EnableFormat(sal_Bool bFormat = sal_True) { bUseFormat = bFormat; }
String ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const; String ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const;
void DoubleToString(String &rValue, const double &rVal, LanguageType eLng) const; String DoubleToString(const double &rVal, LanguageType eLng) const;
void DoubleToString(String &rValue, const double &rVal, sal_uInt32 nFmt) const; String DoubleToString(const double &rVal, sal_uInt32 nFmt) const;
}; };
class SW_DLLPUBLIC SwValueField : public SwField class SW_DLLPUBLIC SwValueField : public SwField
......
...@@ -467,9 +467,7 @@ String SwValueFieldType::ExpandValue( const double& rVal, ...@@ -467,9 +467,7 @@ String SwValueFieldType::ExpandValue( const double& rVal,
if( pFormatter->IsTextFormat( nFmt ) ) if( pFormatter->IsTextFormat( nFmt ) )
{ {
String sValue; OUString sTempIn(DoubleToString(rVal, nFmtLng));
DoubleToString(sValue, rVal, nFmtLng);
OUString sTempIn(sValue);
pFormatter->GetOutputString(sTempIn, nFmt, sExpand, &pCol); pFormatter->GetOutputString(sTempIn, nFmt, sExpand, &pCol);
} }
else else
...@@ -479,17 +477,19 @@ String SwValueFieldType::ExpandValue( const double& rVal, ...@@ -479,17 +477,19 @@ String SwValueFieldType::ExpandValue( const double& rVal,
return sExpand; return sExpand;
} }
void SwValueFieldType::DoubleToString( String &rValue, const double &rVal, String SwValueFieldType::DoubleToString(const double &rVal,
sal_uInt32 nFmt) const sal_uInt32 nFmt) const
{ {
SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter(); SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
const SvNumberformat* pEntry = pFormatter->GetEntry(nFmt); const SvNumberformat* pEntry = pFormatter->GetEntry(nFmt);
if (pEntry) if (!pEntry)
DoubleToString(rValue, rVal, pEntry->GetLanguage()); return String();
return DoubleToString(rVal, pEntry->GetLanguage());
} }
void SwValueFieldType::DoubleToString( String &rValue, const double &rVal, String SwValueFieldType::DoubleToString( const double &rVal,
sal_uInt16 nLng ) const sal_uInt16 nLng ) const
{ {
SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter(); SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
...@@ -499,7 +499,7 @@ void SwValueFieldType::DoubleToString( String &rValue, const double &rVal, ...@@ -499,7 +499,7 @@ void SwValueFieldType::DoubleToString( String &rValue, const double &rVal,
nLng = LANGUAGE_SYSTEM; nLng = LANGUAGE_SYSTEM;
pFormatter->ChangeIntl( nLng ); // get separator in the correct language pFormatter->ChangeIntl( nLng ); // get separator in the correct language
rValue = ::rtl::math::doubleToUString( rVal, rtl_math_StringFormat_F, 12, return ::rtl::math::doubleToUString( rVal, rtl_math_StringFormat_F, 12,
pFormatter->GetDecSep(), true ); pFormatter->GetDecSep(), true );
} }
...@@ -672,9 +672,8 @@ void SwFormulaField::SetExpandedFormula( const String& rStr ) ...@@ -672,9 +672,8 @@ void SwFormulaField::SetExpandedFormula( const String& rStr )
if (pFormatter->IsNumberFormat(rStr, nFmt, fTmpValue)) if (pFormatter->IsNumberFormat(rStr, nFmt, fTmpValue))
{ {
SwValueField::SetValue(fTmpValue); SwValueField::SetValue(fTmpValue);
sFormula.Erase();
((SwValueFieldType *)GetTyp())->DoubleToString(sFormula, fTmpValue, nFmt); sFormula = ((SwValueFieldType *)GetTyp())->DoubleToString(fTmpValue, nFmt);
return; return;
} }
} }
...@@ -694,10 +693,10 @@ String SwFormulaField::GetExpandedFormula() const ...@@ -694,10 +693,10 @@ String SwFormulaField::GetExpandedFormula() const
if (pFormatter->IsTextFormat(nFmt)) if (pFormatter->IsTextFormat(nFmt))
{ {
String sValue; OUString sTempIn(((SwValueFieldType *)GetTyp())->DoubleToString(GetValue(), nFmt));
((SwValueFieldType *)GetTyp())->DoubleToString(sValue, GetValue(), nFmt); OUString sTempOut(sFormattedValue);
OUString sTempIn(sValue); pFormatter->GetOutputString(sTempIn, nFmt, sTempOut, &pCol);
pFormatter->GetOutputString(sTempIn, nFmt, sFormattedValue, &pCol); sFormattedValue = sTempOut;
} }
else else
{ {
......
...@@ -264,8 +264,7 @@ void SwUserFieldType::SetContent( const String& rStr, sal_uInt32 nFmt ) ...@@ -264,8 +264,7 @@ void SwUserFieldType::SetContent( const String& rStr, sal_uInt32 nFmt )
if (pFormatter->IsNumberFormat(rStr, nFmt, fValue)) if (pFormatter->IsNumberFormat(rStr, nFmt, fValue))
{ {
SetValue(fValue); SetValue(fValue);
aContent.Erase(); aContent = DoubleToString(fValue, nFmt);
DoubleToString(aContent, fValue, nFmt);
} }
} }
...@@ -313,7 +312,7 @@ bool SwUserFieldType::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) ...@@ -313,7 +312,7 @@ bool SwUserFieldType::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
// The following line is in fact wrong, since the language is unknown (is part of the // The following line is in fact wrong, since the language is unknown (is part of the
// field) and, thus, aContent should also belong to the field. Each field can have a // field) and, thus, aContent should also belong to the field. Each field can have a
// differnt language, but the same content with just different formatting. // differnt language, but the same content with just different formatting.
DoubleToString(aContent, nValue, (sal_uInt16)LANGUAGE_SYSTEM); aContent = DoubleToString(nValue, static_cast<sal_uInt32>(LANGUAGE_SYSTEM));
} }
break; break;
case FIELD_PROP_PAR2: case FIELD_PROP_PAR2:
......
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