PutEntry familly of functions use consistent pairing OUString/sal_Int32

Change-Id: I23ae9d3e8bf71ef9ece75ea013d18c36ab2e69d4
This commit is contained in:
Norbert Thiebaud 2012-11-18 14:01:16 -06:00
parent 82a134c156
commit cc63555fd0
9 changed files with 86 additions and 46 deletions

View File

@ -373,7 +373,7 @@ void SbiInstance::PrepareNumberFormatter( SvNumberFormatter*& rpNumberFormatter,
rpNumberFormatter = new SvNumberFormatter( xFactory, eLangType ); rpNumberFormatter = new SvNumberFormatter( xFactory, eLangType );
sal_uInt16 nCheckPos = 0; short nType; sal_Int32 nCheckPos = 0; short nType;
rnStdTimeIdx = rpNumberFormatter->GetStandardFormat( NUMBERFORMAT_TIME, eLangType ); rnStdTimeIdx = rpNumberFormatter->GetStandardFormat( NUMBERFORMAT_TIME, eLangType );
// the formatter's standard templates have only got a two-digit date // the formatter's standard templates have only got a two-digit date
@ -393,7 +393,7 @@ void SbiInstance::PrepareNumberFormatter( SvNumberFormatter*& rpNumberFormatter,
default: aDateStr = "MM.TT.JJJJ"; break; default: aDateStr = "MM.TT.JJJJ"; break;
} }
rpNumberFormatter->PutandConvertEntry( aDateStr, nCheckPos, nType, rpNumberFormatter->PutandConvertEntry( aDateStr, nCheckPos, nType,
rnStdDateIdx, LANGUAGE_GERMAN, eLangType ); rnStdDateIdx, LANGUAGE_GERMAN, eLangType );
nCheckPos = 0; nCheckPos = 0;
OUString aStrHHMMSS(" HH:MM:SS"); OUString aStrHHMMSS(" HH:MM:SS");
aDateStr += aStrHHMMSS; aDateStr += aStrHHMMSS;

View File

@ -104,7 +104,7 @@ double ImpGetDate( const SbxValues* p )
pFormatter = new SvNumberFormatter( xFactory, eLangType ); pFormatter = new SvNumberFormatter( xFactory, eLangType );
sal_uInt32 nIndex; sal_uInt32 nIndex;
sal_uInt16 nCheckPos = 0; sal_Int32 nCheckPos = 0;
short nType = 127; short nType = 127;
// Default templates of the formatter have only two-digit // Default templates of the formatter have only two-digit
@ -277,7 +277,7 @@ start:
pFormatter = new SvNumberFormatter( xFactory, eLangType ); pFormatter = new SvNumberFormatter( xFactory, eLangType );
sal_uInt32 nIndex; sal_uInt32 nIndex;
sal_uInt16 nCheckPos = 0; sal_Int32 nCheckPos = 0;
short nType; short nType;
SvtSysLocale aSysLocale; SvtSysLocale aSysLocale;

View File

@ -739,7 +739,7 @@ void SbxValue::Format( OUString& rRes, const OUString* pFmt ) const
// number format, use SvNumberFormatter to handle it. // number format, use SvNumberFormatter to handle it.
if( bSuccess ) if( bSuccess )
{ {
sal_uInt16 nCheckPos = 0; sal_Int32 nCheckPos = 0;
short nType; short nType;
OUString aFmtStr = *pFmt; OUString aFmtStr = *pFmt;
VbaFormatInfo* pInfo = getFormatInfo( aFmtStr ); VbaFormatInfo* pInfo = getFormatInfo( aFmtStr );

View File

@ -838,39 +838,42 @@ rtl::OUString SvxExtTimeField::GetFormatted( Time& aTime, SvxTimeFormat eFormat,
{ {
case SVXTIMEFORMAT_12_HM: case SVXTIMEFORMAT_12_HM:
nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMMAMPM, eLang ); nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMMAMPM, eLang );
break; break;
case SVXTIMEFORMAT_12_HMSH: case SVXTIMEFORMAT_12_HMSH:
{ // no builtin format available, try to insert or reuse {
rtl::OUString aFormatCode( RTL_CONSTASCII_USTRINGPARAM( "HH:MM:SS.00 AM/PM" ) ); // no builtin format available, try to insert or reuse
xub_StrLen nCheckPos; OUString aFormatCode( RTL_CONSTASCII_USTRINGPARAM( "HH:MM:SS.00 AM/PM" ) );
sal_Int32 nCheckPos;
short nType; short nType;
rFormatter.PutandConvertEntry( aFormatCode, rFormatter.PutandConvertEntry( aFormatCode, nCheckPos, nType,
nCheckPos, nType, nFormatKey, LANGUAGE_ENGLISH_US, eLang ); nFormatKey, LANGUAGE_ENGLISH_US, eLang );
DBG_ASSERT( nCheckPos == 0, "SVXTIMEFORMAT_12_HMSH: could not insert format code" ); DBG_ASSERT( nCheckPos == 0, "SVXTIMEFORMAT_12_HMSH: could not insert format code" );
if ( nCheckPos ) if ( nCheckPos )
{
nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HH_MMSS00, eLang ); nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HH_MMSS00, eLang );
}
break;
} }
break;
case SVXTIMEFORMAT_24_HM: case SVXTIMEFORMAT_24_HM:
nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMM, eLang ); nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMM, eLang );
break; break;
case SVXTIMEFORMAT_24_HMSH: case SVXTIMEFORMAT_24_HMSH:
nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HH_MMSS00, eLang ); nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HH_MMSS00, eLang );
break; break;
case SVXTIMEFORMAT_12_HMS: case SVXTIMEFORMAT_12_HMS:
nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMMSSAMPM, eLang ); nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMMSSAMPM, eLang );
break; break;
case SVXTIMEFORMAT_24_HMS: case SVXTIMEFORMAT_24_HMS:
nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMMSS, eLang ); nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMMSS, eLang );
break; break;
case SVXTIMEFORMAT_STANDARD: case SVXTIMEFORMAT_STANDARD:
default: default:
nFormatKey = rFormatter.GetStandardFormat( NUMBERFORMAT_TIME, eLang ); nFormatKey = rFormatter.GetStandardFormat( NUMBERFORMAT_TIME, eLang );
} }
double fFracTime = aTime.GetTimeInDays(); double fFracTime = aTime.GetTimeInDays();
rtl::OUString aStr; OUString aStr;
Color* pColor = NULL; Color* pColor = NULL;
rFormatter.GetOutputString( fFracTime, nFormatKey, aStr, &pColor ); rFormatter.GetOutputString( fFracTime, nFormatKey, aStr, &pColor );
return aStr; return aStr;
} }

View File

@ -2251,7 +2251,7 @@ void ScHTMLTable::DataOn( const ImportInfo& rInfo )
nNumberFormat = GetFormatTable()->GetEntryKey(aNumFmt); nNumberFormat = GetFormatTable()->GetEntryKey(aNumFmt);
if (nNumberFormat == NUMBERFORMAT_ENTRY_NOT_FOUND) if (nNumberFormat == NUMBERFORMAT_ENTRY_NOT_FOUND)
{ {
xub_StrLen nErrPos = 0; sal_Int32 nErrPos = 0;
short nDummy; short nDummy;
bool bValidFmt = GetFormatTable()->PutEntry(aNumFmt, nErrPos, nDummy, nNumberFormat); bool bValidFmt = GetFormatTable()->PutEntry(aNumFmt, nErrPos, nDummy, nNumberFormat);
if (!bValidFmt) if (!bValidFmt)

View File

@ -1898,12 +1898,11 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm )
aCode = aCode.replaceAll(";;", ";"); aCode = aCode.replaceAll(";;", ";");
// get rid of Xcl escape characters // get rid of Xcl escape characters
aCode = aCode.replaceAll(rtl::OUString(static_cast<sal_Unicode>(0x1b)), rtl::OUString()); aCode = aCode.replaceAll(rtl::OUString(static_cast<sal_Unicode>(0x1b)), rtl::OUString());
xub_StrLen nCheckPos; sal_Int32 nCheckPos;
short nType; short nType;
sal_uInt32 nKey; sal_uInt32 nKey;
pDoc->GetFormatTable()->PutandConvertEntry( pDoc->GetFormatTable()->PutandConvertEntry( aCode, nCheckPos, nType, nKey,
aCode, nCheckPos, nType, nKey, LANGUAGE_ENGLISH_US, LANGUAGE_ENGLISH_US, ScGlobal::eLnge );
ScGlobal::eLnge );
if ( nCheckPos ) if ( nCheckPos )
nKey = 0; nKey = 0;
aFormats.push_back( nKey ); aFormats.push_back( nKey );

View File

@ -395,7 +395,7 @@ public:
bool PutEntry( String& rString, xub_StrLen& nCheckPos, short& nType, sal_uInt32& nKey, bool PutEntry( String& rString, xub_StrLen& nCheckPos, short& nType, sal_uInt32& nKey,
LanguageType eLnge = LANGUAGE_DONTKNOW ); LanguageType eLnge = LANGUAGE_DONTKNOW );
bool PutEntry( OUString& rString, xub_StrLen& nCheckPos, short& nType, sal_uInt32& nKey, bool PutEntry( OUString& rString, sal_Int32& nCheckPos, short& nType, sal_uInt32& nKey,
LanguageType eLnge = LANGUAGE_DONTKNOW ); LanguageType eLnge = LANGUAGE_DONTKNOW );
/** Same as <method>PutEntry</method> but the format code string is /** Same as <method>PutEntry</method> but the format code string is
@ -405,7 +405,7 @@ public:
short& nType, sal_uInt32& nKey, short& nType, sal_uInt32& nKey,
LanguageType eLnge, LanguageType eNewLnge ); LanguageType eLnge, LanguageType eNewLnge );
bool PutandConvertEntry( OUString& rString, xub_StrLen& nCheckPos, bool PutandConvertEntry( OUString& rString, sal_Int32& nCheckPos,
short& nType, sal_uInt32& nKey, short& nType, sal_uInt32& nKey,
LanguageType eLnge, LanguageType eNewLnge ); LanguageType eLnge, LanguageType eNewLnge );
@ -413,6 +413,10 @@ public:
is considered to be of the System language/country eLnge and is is considered to be of the System language/country eLnge and is
converted to another System language/country eNewLnge. In this case converted to another System language/country eNewLnge. In this case
the automatic currency is converted too. */ the automatic currency is converted too. */
bool PutandConvertEntrySystem( OUString& rString, sal_Int32& nCheckPos,
short& nType, sal_uInt32& nKey,
LanguageType eLnge, LanguageType eNewLnge );
bool PutandConvertEntrySystem( String& rString, xub_StrLen& nCheckPos, bool PutandConvertEntrySystem( String& rString, xub_StrLen& nCheckPos,
short& nType, sal_uInt32& nKey, short& nType, sal_uInt32& nKey,
LanguageType eLnge, LanguageType eNewLnge ); LanguageType eLnge, LanguageType eNewLnge );

View File

@ -416,29 +416,39 @@ void SvNumberFormatter::ReplaceSystemCL( LanguageType eOldLanguage )
SvNumberformat* pOldEntry = aOldTable.begin()->second; SvNumberformat* pOldEntry = aOldTable.begin()->second;
aOldTable.erase( nKey ); aOldTable.erase( nKey );
String aString( pOldEntry->GetFormatstring() ); String aString( pOldEntry->GetFormatstring() );
xub_StrLen nCheckPos = STRING_NOTFOUND;
// Same as PutEntry() but assures key position even if format code is // Same as PutEntry() but assures key position even if format code is
// a duplicate. Also won't mix up any LastInsertKey. // a duplicate. Also won't mix up any LastInsertKey.
ChangeIntl( eOldLanguage ); ChangeIntl( eOldLanguage );
LanguageType eLge = eOldLanguage; // ConvertMode changes this LanguageType eLge = eOldLanguage; // ConvertMode changes this
bool bCheck = false; bool bCheck = false;
xub_StrLen nCheckPos;
SvNumberformat* pNewEntry = new SvNumberformat( aString, pFormatScanner, SvNumberformat* pNewEntry = new SvNumberformat( aString, pFormatScanner,
pStringScanner, nCheckPos, eLge ); pStringScanner, nCheckPos, eLge );
if ( nCheckPos != 0 ) if ( nCheckPos != 0 )
{
delete pNewEntry; delete pNewEntry;
}
else else
{ {
short eCheckType = pNewEntry->GetType(); short eCheckType = pNewEntry->GetType();
if ( eCheckType != NUMBERFORMAT_UNDEFINED ) if ( eCheckType != NUMBERFORMAT_UNDEFINED )
{
pNewEntry->SetType( eCheckType | NUMBERFORMAT_DEFINED ); pNewEntry->SetType( eCheckType | NUMBERFORMAT_DEFINED );
}
else else
{
pNewEntry->SetType( NUMBERFORMAT_DEFINED ); pNewEntry->SetType( NUMBERFORMAT_DEFINED );
}
if ( !aFTable.insert( make_pair( nKey, pNewEntry) ).second ) if ( !aFTable.insert( make_pair( nKey, pNewEntry) ).second )
{
delete pNewEntry; delete pNewEntry;
}
else else
{
bCheck = true; bCheck = true;
}
} }
DBG_ASSERT( bCheck, "SvNumberFormatter::ReplaceSystemCL: couldn't convert" ); DBG_ASSERT( bCheck, "SvNumberFormatter::ReplaceSystemCL: couldn't convert" );
(void)bCheck; (void)bCheck;
@ -486,6 +496,7 @@ bool SvNumberFormatter::PutEntry(String& rString,
pStringScanner, pStringScanner,
nCheckPos, nCheckPos,
eLge); eLge);
if (nCheckPos == 0) // Format ok if (nCheckPos == 0) // Format ok
{ // Type comparison: { // Type comparison:
short eCheckType = p_Entry->GetType(); short eCheckType = p_Entry->GetType();
@ -532,14 +543,16 @@ bool SvNumberFormatter::PutEntry(String& rString,
return bCheck; return bCheck;
} }
bool SvNumberFormatter::PutEntry( bool SvNumberFormatter::PutEntry(OUString& rString, sal_Int32& nCheckPos32,
OUString& rString, xub_StrLen& nCheckPos, short& nType, sal_uInt32& nKey, short& nType, sal_uInt32& nKey,
LanguageType eLnge) LanguageType eLnge)
{ {
// Wrapper to allow OUString to be used. // Wrapper to allow OUString to be used.
String aStr(rString); String aStr(rString);
xub_StrLen nCheckPos = nCheckPos32 < 0 ? 0xFFFF : (xub_StrLen)nCheckPos32;
bool bRet = PutEntry(aStr, nCheckPos, nType, nKey, eLnge); bool bRet = PutEntry(aStr, nCheckPos, nType, nKey, eLnge);
rString = aStr; rString = aStr;
nCheckPos32 = nCheckPos == 0xFFFF ? -1 : nCheckPos;
return bRet; return bRet;
} }
@ -561,24 +574,45 @@ bool SvNumberFormatter::PutandConvertEntry(String& rString,
} }
bool SvNumberFormatter::PutandConvertEntry(OUString& rString, bool SvNumberFormatter::PutandConvertEntry(OUString& rString,
xub_StrLen& nCheckPos, sal_Int32& nCheckPos,
short& nType, short& nType,
sal_uInt32& nKey, sal_uInt32& nKey,
LanguageType eLnge, LanguageType eLnge,
LanguageType eNewLnge) LanguageType eNewLnge)
{ {
String aStr; bool bRes;
bool bRet = PutandConvertEntry(aStr, nCheckPos, nType, nKey, eLnge, eNewLnge); if (eNewLnge == LANGUAGE_DONTKNOW)
rString = aStr; eNewLnge = IniLnge;
return bRet;
pFormatScanner->SetConvertMode(eLnge, eNewLnge);
bRes = PutEntry(rString, nCheckPos, nType, nKey, eLnge);
pFormatScanner->SetConvertMode(false);
return bRes;
}
bool SvNumberFormatter::PutandConvertEntrySystem(OUString& rString,
sal_Int32& nCheckPos,
short& nType,
sal_uInt32& nKey,
LanguageType eLnge,
LanguageType eNewLnge)
{
bool bRes;
if (eNewLnge == LANGUAGE_DONTKNOW)
eNewLnge = IniLnge;
pFormatScanner->SetConvertMode(eLnge, eNewLnge, true);
bRes = PutEntry(rString, nCheckPos, nType, nKey, eLnge);
pFormatScanner->SetConvertMode(false);
return bRes;
} }
bool SvNumberFormatter::PutandConvertEntrySystem(String& rString, bool SvNumberFormatter::PutandConvertEntrySystem(String& rString,
xub_StrLen& nCheckPos, xub_StrLen& nCheckPos,
short& nType, short& nType,
sal_uInt32& nKey, sal_uInt32& nKey,
LanguageType eLnge, LanguageType eLnge,
LanguageType eNewLnge) LanguageType eNewLnge)
{ {
bool bRes; bool bRes;
if (eNewLnge == LANGUAGE_DONTKNOW) if (eNewLnge == LANGUAGE_DONTKNOW)
@ -617,7 +651,7 @@ sal_uInt32 SvNumberFormatter::GetIndexPuttingAndConverting( String & rString,
// language and wouldn't match eSysLnge anymore, do that on a copy. // language and wouldn't match eSysLnge anymore, do that on a copy.
String aTmp( rString); String aTmp( rString);
rNewInserted = PutandConvertEntrySystem( aTmp, rCheckPos, rType, rNewInserted = PutandConvertEntrySystem( aTmp, rCheckPos, rType,
nKey, eLnge, SvtSysLocale().GetLanguage()); nKey, eLnge, SvtSysLocale().GetLanguage());
if (rCheckPos > 0) if (rCheckPos > 0)
{ {
SAL_WARN( "svl.numbers", "SvNumberFormatter::GetIndexPuttingAndConverting: bad format code string for current locale"); SAL_WARN( "svl.numbers", "SvNumberFormatter::GetIndexPuttingAndConverting: bad format code string for current locale");
@ -3194,7 +3228,7 @@ sal_uInt32 SvNumberFormatter::ImpGetDefaultSystemCurrencyFormat()
{ {
if ( nDefaultSystemCurrencyFormat == NUMBERFORMAT_ENTRY_NOT_FOUND ) if ( nDefaultSystemCurrencyFormat == NUMBERFORMAT_ENTRY_NOT_FOUND )
{ {
xub_StrLen nCheck; sal_Int32 nCheck;
short nType; short nType;
NfWSStringsDtor aCurrList; NfWSStringsDtor aCurrList;
sal_uInt16 nDefault = GetCurrencyFormatStrings( aCurrList, sal_uInt16 nDefault = GetCurrencyFormatStrings( aCurrList,
@ -3237,7 +3271,7 @@ sal_uInt32 SvNumberFormatter::ImpGetDefaultCurrencyFormat()
if ( nDefaultCurrencyFormat == NUMBERFORMAT_ENTRY_NOT_FOUND ) if ( nDefaultCurrencyFormat == NUMBERFORMAT_ENTRY_NOT_FOUND )
{ // none found, create one { // none found, create one
xub_StrLen nCheck; sal_Int32 nCheck;
NfWSStringsDtor aCurrList; NfWSStringsDtor aCurrList;
sal_uInt16 nDefault = GetCurrencyFormatStrings( aCurrList, sal_uInt16 nDefault = GetCurrencyFormatStrings( aCurrList,
GetCurrencyEntry( ActLnge ), false ); GetCurrencyEntry( ActLnge ), false );

View File

@ -640,7 +640,7 @@ void FormattedField::SetFormatter(SvNumberFormatter* pFormatter, sal_Bool bReset
LanguageType aNewLang = pDefaultEntry ? pDefaultEntry->GetLanguage() : LANGUAGE_DONTKNOW; LanguageType aNewLang = pDefaultEntry ? pDefaultEntry->GetLanguage() : LANGUAGE_DONTKNOW;
// den alten Format-String in die neue Sprache konvertieren // den alten Format-String in die neue Sprache konvertieren
sal_uInt16 nCheckPos; sal_Int32 nCheckPos;
short nType; short nType;
pFormatter->PutandConvertEntry(sOldFormat, nCheckPos, nType, nDestKey, aOldLang, aNewLang); pFormatter->PutandConvertEntry(sOldFormat, nCheckPos, nType, nDestKey, aOldLang, aNewLang);
m_nFormatKey = nDestKey; m_nFormatKey = nDestKey;
@ -716,7 +716,7 @@ void FormattedField::SetThousandsSep(sal_Bool _bUseSeparator)
// generate a new format ... // generate a new format ...
OUString sFmtDescription = ImplGetFormatter()->GenerateFormat(m_nFormatKey, eLang, _bUseSeparator, IsRed, nPrecision, nAnzLeading); OUString sFmtDescription = ImplGetFormatter()->GenerateFormat(m_nFormatKey, eLang, _bUseSeparator, IsRed, nPrecision, nAnzLeading);
// ... and introduce it to the formatter // ... and introduce it to the formatter
sal_uInt16 nCheckPos; sal_Int32 nCheckPos;
sal_uInt32 nNewKey; sal_uInt32 nNewKey;
short nType; short nType;
ImplGetFormatter()->PutEntry(sFmtDescription, nCheckPos, nType, nNewKey, eLang); ImplGetFormatter()->PutEntry(sFmtDescription, nCheckPos, nType, nNewKey, eLang);
@ -759,7 +759,7 @@ void FormattedField::SetDecimalDigits(sal_uInt16 _nPrecision)
// generate a new format ... // generate a new format ...
OUString sFmtDescription = ImplGetFormatter()->GenerateFormat(m_nFormatKey, eLang, bThousand, IsRed, _nPrecision, nAnzLeading); OUString sFmtDescription = ImplGetFormatter()->GenerateFormat(m_nFormatKey, eLang, bThousand, IsRed, _nPrecision, nAnzLeading);
// ... and introduce it to the formatter // ... and introduce it to the formatter
sal_uInt16 nCheckPos; sal_Int32 nCheckPos;
sal_uInt32 nNewKey; sal_uInt32 nNewKey;
short nType; short nType;
ImplGetFormatter()->PutEntry(sFmtDescription, nCheckPos, nType, nNewKey, eLang); ImplGetFormatter()->PutEntry(sFmtDescription, nCheckPos, nType, nNewKey, eLang);