diff options
author | Matteo Casalin <matteo.casalin@yahoo.com> | 2019-01-12 17:29:06 +0100 |
---|---|---|
committer | Matteo Casalin <matteo.casalin@yahoo.com> | 2019-01-18 23:12:52 +0100 |
commit | 284e998aae8f65857a6ef8df965e03910fc4bef0 (patch) | |
tree | 1cfb46d15bece6618827b2c06d33e56f256d5c33 /vcl/unx | |
parent | 8511bc6b9bf5dcaf0ce6ecee65be54552bc73bd5 (diff) |
No need to loop twice on the same tokens
Change-Id: If1ef69d537c67bf0e6f9f5236ce97b1264e82c51
Reviewed-on: https://gerrit.libreoffice.org/66236
Tested-by: Jenkins
Reviewed-by: Matteo Casalin <matteo.casalin@yahoo.com>
Diffstat (limited to 'vcl/unx')
-rw-r--r-- | vcl/unx/generic/print/genprnpsp.cxx | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/vcl/unx/generic/print/genprnpsp.cxx b/vcl/unx/generic/print/genprnpsp.cxx index 151db7574729..baeaadc3541a 100644 --- a/vcl/unx/generic/print/genprnpsp.cxx +++ b/vcl/unx/generic/print/genprnpsp.cxx @@ -63,12 +63,8 @@ using namespace psp; using namespace com::sun::star; -/* - * static helpers - */ -static OUString getPdfDir( const PrinterInfo& rInfo ) +static bool getPdfDir( const PrinterInfo& rInfo, OUString &rDir ) { - OUString aDir; sal_Int32 nIndex = 0; while( nIndex != -1 ) { @@ -76,13 +72,13 @@ static OUString getPdfDir( const PrinterInfo& rInfo ) if( aToken.startsWith( "pdf=" ) ) { sal_Int32 nPos = 0; - aDir = aToken.getToken( 1, '=', nPos ); - if( aDir.isEmpty() && getenv( "HOME" ) ) - aDir = OUString( getenv( "HOME" ), strlen( getenv( "HOME" ) ), osl_getThreadTextEncoding() ); - break; + rDir = aToken.getToken( 1, '=', nPos ); + if( rDir.isEmpty() && getenv( "HOME" ) ) + rDir = OUString( getenv( "HOME" ), strlen( getenv( "HOME" ) ), osl_getThreadTextEncoding() ); + return true; } } - return aDir; + return false; } namespace @@ -418,16 +414,9 @@ void SalGenericInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList ) pInfo->maLocation = rInfo.m_aLocation; pInfo->maComment = rInfo.m_aComment; - sal_Int32 nIndex = 0; - while( nIndex != -1 ) - { - OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) ); - if( aToken.match( "pdf=" ) ) - { - pInfo->maLocation = getPdfDir( rInfo ); - break; - } - } + OUString sPdfDir; + if (getPdfDir(rInfo, sPdfDir)) + pInfo->maLocation = sPdfDir; pList->Add( std::move(pInfo) ); } @@ -855,21 +844,16 @@ bool PspSalPrinter::StartJob( int nMode = 0; // check whether this printer is configured as fax - sal_Int32 nIndex = 0; const PrinterInfo& rInfo( PrinterInfoManager::get().getPrinterInfo( m_aJobData.m_aPrinterName ) ); - while( nIndex != -1 ) + OUString sPdfDir; + if (getPdfDir(rInfo, sPdfDir)) { - OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) ); - if( aToken.startsWith( "pdf=" ) ) - { - m_bPdf = true; - m_aTmpFile = getTmpName(); - nMode = S_IRUSR | S_IWUSR; + m_bPdf = true; + m_aTmpFile = getTmpName(); + nMode = S_IRUSR | S_IWUSR; - if( m_aFileName.isEmpty() ) - m_aFileName = getPdfDir( rInfo ) + "/" + rJobName + ".pdf"; - break; - } + if( m_aFileName.isEmpty() ) + m_aFileName = sPdfDir + "/" + rJobName + ".pdf"; } m_aPrinterGfx.Init( m_aJobData ); |