fpicker/source/office/iodlg.cxx | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
New commits: commit 5788bb027b1e63e5c133e0e47d63e02021f3aee0 Author: Matteo Casalin <matteo.casa...@yahoo.com> AuthorDate: Mon Mar 4 17:51:08 2019 +0100 Commit: Matteo Casalin <matteo.casa...@yahoo.com> CommitDate: Wed Mar 20 07:49:28 2019 +0100 Clarify flow, reduce scope Change-Id: I99dbde5d2b25a8cbffc027e136d29cf911d5337b Reviewed-on: https://gerrit.libreoffice.org/69243 Tested-by: Jenkins Reviewed-by: Matteo Casalin <matteo.casa...@yahoo.com> 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 _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits