diff options
author | Matteo Casalin <matteo.casalin@yahoo.com> | 2019-03-04 17:51:08 +0100 |
---|---|---|
committer | Matteo Casalin <matteo.casalin@yahoo.com> | 2019-03-20 07:49:28 +0100 |
commit | 5788bb027b1e63e5c133e0e47d63e02021f3aee0 (patch) | |
tree | 441a64811ab28b90c958358b3e2678dec60befc2 /fpicker | |
parent | 1d86bad16d8d517845828932115f75dd13c24940 (diff) |
Clarify flow, reduce scope
Change-Id: I99dbde5d2b25a8cbffc027e136d29cf911d5337b
Reviewed-on: https://gerrit.libreoffice.org/69243
Tested-by: Jenkins
Reviewed-by: Matteo Casalin <matteo.casalin@yahoo.com>
Diffstat (limited to 'fpicker')
-rw-r--r-- | fpicker/source/office/iodlg.cxx | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/fpicker/source/office/iodlg.cxx b/fpicker/source/office/iodlg.cxx index b3e5ace8c95d..7f561b56059f 100644 --- a/fpicker/source/office/iodlg.cxx +++ b/fpicker/source/office/iodlg.cxx @@ -168,17 +168,18 @@ namespace void SetFsysExtension_Impl( OUString& rFile, const OUString& rExtension ) { - const sal_Unicode* p0 = rFile.getStr(); - const sal_Unicode* p1 = p0 + rFile.getLength() - 1; - while ( p1 >= p0 && *p1 != '.' ) - p1--; - if ( p1 >= p0 ) - // remove old extension - rFile = rFile.copy( 0, p1 - p0 + 1 - ( rExtension.getLength() > 0 ? 0 : 1 ) ); - else if ( !rExtension.isEmpty() ) - // no old extension - rFile += "."; - rFile += rExtension; + const sal_Int32 nDotPos{ rFile.lastIndexOf('.') }; + if (nDotPos>=0) + { + if (!rExtension.isEmpty()) + rFile = rFile.copy(0, nDotPos) + rExtension; // replace old extension with new (not empty) one + else if (nDotPos) + rFile = rFile.copy(0, nDotPos-1); // truncate extension (new one is empty) + else + rFile.clear(); // Filename was just an extension + } + else if (!rExtension.isEmpty()) + rFile += "." + rExtension; // no extension was present, append new one if not empty } void lcl_autoUpdateFileExtension( SvtFileDialog* _pDialog, const OUString& _rLastFilterExt ) @@ -1309,14 +1310,13 @@ SvtFileDialogFilter_Impl* SvtFileDialog::FindFilter_Impl { SvtFileDialogFilter_Impl* pFilter = rList[ nFilter ].get(); const OUString& rType = pFilter->GetType(); - OUString aSingleType = rType; if ( _bMultiExt ) { sal_Int32 nIdx = 0; while ( !pFoundFilter && nIdx != -1 ) { - aSingleType = rType.getToken( 0, FILEDIALOG_DEF_EXTSEP, nIdx ); + const OUString aSingleType = rType.getToken( 0, FILEDIALOG_DEF_EXTSEP, nIdx ); #ifdef UNX if ( aSingleType == _rFilter ) #else |