diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-01-02 10:55:27 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-01-05 09:18:19 +0000 |
commit | bacfd2dc4cea1a5d87658ed8592116acd931e000 (patch) | |
tree | d22172a33fdd13a440b6882a28c23ea2d639bbad /dbaccess/source/ui | |
parent | 6281eb0e0792da0194c07da18296e94dd944b8e5 (diff) |
add a comphelper::string::getTokenCount
suitable for conversion from [Byte]String::GetTokenCount
converted low-hanging variants to rtl::O[UString]::getToken loops
added unit test
Diffstat (limited to 'dbaccess/source/ui')
-rw-r--r-- | dbaccess/source/ui/dlg/DbAdminImpl.cxx | 5 | ||||
-rw-r--r-- | dbaccess/source/ui/dlg/TextConnectionHelper.cxx | 7 | ||||
-rw-r--r-- | dbaccess/source/ui/dlg/queryfilter.cxx | 7 | ||||
-rw-r--r-- | dbaccess/source/ui/misc/TokenWriter.cxx | 4 | ||||
-rw-r--r-- | dbaccess/source/ui/querydesign/QueryDesignView.cxx | 7 | ||||
-rw-r--r-- | dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx | 27 |
6 files changed, 31 insertions, 26 deletions
diff --git a/dbaccess/source/ui/dlg/DbAdminImpl.cxx b/dbaccess/source/ui/dlg/DbAdminImpl.cxx index a38c26eeeaf9..238418e5c871 100644 --- a/dbaccess/source/ui/dlg/DbAdminImpl.cxx +++ b/dbaccess/source/ui/dlg/DbAdminImpl.cxx @@ -60,10 +60,11 @@ #include <com/sun/star/ucb/AuthenticationRequest.hpp> /** === end UNO includes === **/ +#include <comphelper/guarding.hxx> #include <comphelper/interaction.hxx> #include <comphelper/property.hxx> #include <comphelper/sequence.hxx> -#include <comphelper/guarding.hxx> +#include <comphelper/string.hxx> #include <connectivity/DriversConfig.hxx> #include <connectivity/dbexception.hxx> #include <osl/file.hxx> @@ -525,7 +526,7 @@ String ODbDataSourceAdministrationHelper::getConnectionURL() const SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pHostName, SfxStringItem, DSID_CONN_HOSTNAME, sal_True); sNewUrl = lcl_createHostWithPort(pHostName,NULL); String sUrl = pCollection->cutPrefix(pUrlItem->GetValue()); - if ( sUrl.GetTokenCount(':') == 1 ) + if ( comphelper::string::getTokenCount(sUrl, ':') == 1 ) sNewUrl += String::CreateFromAscii(":"); sNewUrl += sUrl; diff --git a/dbaccess/source/ui/dlg/TextConnectionHelper.cxx b/dbaccess/source/ui/dlg/TextConnectionHelper.cxx index 91c3a364f8ca..d8ce26f8d3ef 100644 --- a/dbaccess/source/ui/dlg/TextConnectionHelper.cxx +++ b/dbaccess/source/ui/dlg/TextConnectionHelper.cxx @@ -50,6 +50,7 @@ #include <connectivity/CommonTools.hxx> #include "DriverSettings.hxx" #include "dbadmin.hxx" +#include <comphelper/string.hxx> #include <comphelper/types.hxx> #include <com/sun/star/ui/dialogs/XFolderPicker.hpp> @@ -110,13 +111,13 @@ DBG_NAME(OTextConnectionHelper) { DBG_CTOR(OTextConnectionHelper,NULL); - xub_StrLen nCnt = m_aFieldSeparatorList.GetTokenCount( '\t' ); + xub_StrLen nCnt = comphelper::string::getTokenCount(m_aFieldSeparatorList, '\t'); xub_StrLen i; for( i = 0 ; i < nCnt ; i += 2 ) m_aFieldSeparator.InsertEntry( m_aFieldSeparatorList.GetToken( i, '\t' ) ); - nCnt = m_aTextSeparatorList.GetTokenCount( '\t' ); + nCnt = comphelper::string::getTokenCount(m_aTextSeparatorList, '\t'); for( i=0 ; i<nCnt ; i+=2 ) m_aTextSeparator.InsertEntry( m_aTextSeparatorList.GetToken( i, '\t' ) ); m_aTextSeparator.InsertEntry(m_aTextNone); @@ -512,7 +513,7 @@ DBG_NAME(OTextConnectionHelper) void OTextConnectionHelper::SetSeparator( ComboBox& rBox, const String& rList, const String& rVal ) { char nTok = '\t'; - xub_StrLen nCnt(rList.GetTokenCount( nTok )); + xub_StrLen nCnt(comphelper::string::getTokenCount(rList, nTok)); xub_StrLen i; for( i=0 ; i<nCnt ; i+=2 ) diff --git a/dbaccess/source/ui/dlg/queryfilter.cxx b/dbaccess/source/ui/dlg/queryfilter.cxx index 40f3624cb88a..6b0a1bb7dda2 100644 --- a/dbaccess/source/ui/dlg/queryfilter.cxx +++ b/dbaccess/source/ui/dlg/queryfilter.cxx @@ -40,6 +40,7 @@ #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/XResultSet.hpp> #include <com/sun/star/container/XNameAccess.hpp> +#include <comphelper/string.hxx> #include <tools/diagnose_ex.h> #include <osl/diagnose.h> #include "moduledbu.hxx" @@ -225,7 +226,7 @@ DlgFilterCrit::~DlgFilterCrit() sal_Int32 DlgFilterCrit::GetOSQLPredicateType( const String& _rSelectedPredicate ) const { sal_Int32 nPredicateIndex = -1; - for ( xub_StrLen i=0; i<aSTR_COMPARE_OPERATORS.GetTokenCount(); ++i) + for ( xub_StrLen i=0; i < comphelper::string::getTokenCount(aSTR_COMPARE_OPERATORS, ';'); ++i) if ( aSTR_COMPARE_OPERATORS.GetToken(i) == _rSelectedPredicate ) { nPredicateIndex = i; @@ -733,7 +734,7 @@ IMPL_LINK( DlgFilterCrit, ListSelectHdl, ListBox *, pListBox ) if(eColumnSearch == ColumnSearch::FULL) { - for(xub_StrLen i=0;i<aSTR_COMPARE_OPERATORS.GetTokenCount();i++) + for(xub_StrLen i=0;i < comphelper::string::getTokenCount(aSTR_COMPARE_OPERATORS, ';');i++) pComp->InsertEntry(aSTR_COMPARE_OPERATORS.GetToken(i)); } else if(eColumnSearch == ColumnSearch::CHAR) @@ -746,7 +747,7 @@ IMPL_LINK( DlgFilterCrit, ListSelectHdl, ListBox *, pListBox ) xub_StrLen i; for( i = 0; i < 6; i++ ) pComp->InsertEntry(aSTR_COMPARE_OPERATORS.GetToken(i)); - for(i=8;i<aSTR_COMPARE_OPERATORS.GetTokenCount();i++) + for(i=8; i < comphelper::string::getTokenCount(aSTR_COMPARE_OPERATORS, ';'); ++i) pComp->InsertEntry(aSTR_COMPARE_OPERATORS.GetToken(i)); } else diff --git a/dbaccess/source/ui/misc/TokenWriter.cxx b/dbaccess/source/ui/misc/TokenWriter.cxx index ef1ec82a91c0..c43da50d568d 100644 --- a/dbaccess/source/ui/misc/TokenWriter.cxx +++ b/dbaccess/source/ui/misc/TokenWriter.cxx @@ -119,7 +119,7 @@ ODatabaseImportExport::ODatabaseImportExport(const ::svx::ODataAccessDescriptor& osl_incrementInterlockedCount( &m_refCount ); impl_initFromDescriptor( _aDataDescriptor, false ); - xub_StrLen nCount = rExchange.GetTokenCount(char(11)); + xub_StrLen nCount = comphelper::string::getTokenCount(rExchange, char(11)); if( nCount > SBA_FORMAT_SELECTION_COUNT && rExchange.GetToken(4).Len()) { m_pRowMarker = new sal_Int32[nCount-SBA_FORMAT_SELECTION_COUNT]; @@ -421,7 +421,7 @@ sal_Bool ORTFImportExport::Write() ByteString aFontNr; (*m_pStream) << "{\\fonttbl"; - xub_StrLen nTokenCount = aFonts.GetTokenCount(); + xub_StrLen nTokenCount = comphelper::string::getTokenCount(aFonts, ';'); for(sal_uInt32 j=0;j<nTokenCount;++j) { (*m_pStream) << "\\f"; diff --git a/dbaccess/source/ui/querydesign/QueryDesignView.cxx b/dbaccess/source/ui/querydesign/QueryDesignView.cxx index d253d134be69..16c87e4657c5 100644 --- a/dbaccess/source/ui/querydesign/QueryDesignView.cxx +++ b/dbaccess/source/ui/querydesign/QueryDesignView.cxx @@ -43,6 +43,8 @@ #include "SelectionBrowseBox.hxx" #include "dbu_qry.hrc" #include <unotools/configmgr.hxx> +#include <comphelper/extract.hxx> +#include <comphelper/string.hxx> #include <comphelper/types.hxx> #include <connectivity/dbtools.hxx> #include <connectivity/dbexception.hxx> @@ -56,7 +58,6 @@ #include "ConnectionLineData.hxx" #include "QTableConnectionData.hxx" #include "dbustrings.hrc" -#include <comphelper/extract.hxx> #include "UITools.hxx" #include "querycontainerwindow.hxx" #include "QueryTableView.hxx" @@ -966,7 +967,7 @@ namespace { const sal_Int32 nMaxOrder = xMetaData->getMaxColumnsInOrderBy(); String sToken(aWorkStr); - if ( nMaxOrder && nMaxOrder < sToken.GetTokenCount(',') ) + if ( nMaxOrder && nMaxOrder < comphelper::string::getTokenCount(sToken, ',') ) eErrorCode = eStatementTooLong; else { @@ -3056,7 +3057,7 @@ OSQLParseNode* OQueryDesignView::getPredicateTreeFromEntry(OTableFieldDescRef pE if ( !sFunction.Len() ) sFunction = pEntry->GetField(); - if(sFunction.GetTokenCount('(') > 1) + if (comphelper::string::getTokenCount(sFunction, '(') > 1) sFunction = sFunction.GetToken(0,'('); // this should be the name of the function sal_Int32 nType = ::connectivity::OSQLParser::getFunctionReturnType(sFunction,&rParser.getContext()); diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx index 8aefc3d402f8..f3140b08f1be 100644 --- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx +++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx @@ -33,6 +33,9 @@ #include "querycontroller.hxx" #include "QueryTableView.hxx" #include "browserids.hxx" +#include <comphelper/extract.hxx> +#include <comphelper/stl_types.hxx> +#include <comphelper/string.hxx> #include <comphelper/types.hxx> #include "TableFieldInfo.hxx" #include "dbu_qry.hrc" @@ -44,8 +47,6 @@ #include <vcl/msgbox.hxx> #include "QueryDesignFieldUndoAct.hxx" #include <svx/dbexch.hrc> -#include <comphelper/stl_types.hxx> -#include <comphelper/extract.hxx> #include "sqlmessage.hxx" #include "UITools.hxx" #include <osl/diagnose.h> @@ -78,7 +79,7 @@ namespace if ( !bAsterix ) { String sName = _sFieldName; - xub_StrLen nTokenCount = sName.GetTokenCount('.'); + xub_StrLen nTokenCount = comphelper::string::getTokenCount(sName, '.'); if ( (nTokenCount == 2 && sName.GetToken(1,'.').GetChar(0) == '*' ) || (nTokenCount == 3 && sName.GetToken(2,'.').GetChar(0) == '*' ) ) { @@ -150,7 +151,7 @@ OSelectionBrowseBox::OSelectionBrowseBox( Window* pParent ) SetTitleFont(aTitleFont); String aTxt(ModuleRes(STR_QUERY_SORTTEXT)); - xub_StrLen nCount = aTxt.GetTokenCount(); + xub_StrLen nCount = comphelper::string::getTokenCount(aTxt, ';'); xub_StrLen nIdx = 0; for (; nIdx < nCount; nIdx++) m_pOrderCell->InsertEntry(aTxt.GetToken(nIdx)); @@ -198,7 +199,7 @@ void OSelectionBrowseBox::initialize() ,IParseContext::KEY_INTERSECTION }; - String sGroup = m_aFunctionStrings.GetToken(m_aFunctionStrings.GetTokenCount() - 1); + String sGroup = m_aFunctionStrings.GetToken(comphelper::string::getTokenCount(m_aFunctionStrings, ';') - 1); m_aFunctionStrings = m_aFunctionStrings.GetToken(0); for (size_t i = 0; i < SAL_N_ELEMENTS(eFunctions); ++i) @@ -213,7 +214,7 @@ void OSelectionBrowseBox::initialize() // Diese Funktionen stehen nur unter CORE zur Verf�gung if ( lcl_SupportsCoreSQLGrammar(xConnection) ) { - xub_StrLen nCount = m_aFunctionStrings.GetTokenCount(); + xub_StrLen nCount = comphelper::string::getTokenCount(m_aFunctionStrings, ';'); for (xub_StrLen nIdx = 0; nIdx < nCount; nIdx++) m_pFunctionCell->InsertEntry(m_aFunctionStrings.GetToken(nIdx)); } @@ -829,7 +830,7 @@ sal_Bool OSelectionBrowseBox::saveField(const String& _sFieldName,OTableFieldDes aSelEntry->SetField(sParameters); if ( aSelEntry->IsGroupBy() ) { - sOldLocalizedFunctionName = m_aFunctionStrings.GetToken(m_aFunctionStrings.GetTokenCount()-1); + sOldLocalizedFunctionName = m_aFunctionStrings.GetToken(comphelper::string::getTokenCount(m_aFunctionStrings, ';')-1); aSelEntry->SetGroupBy(sal_False); } @@ -957,7 +958,7 @@ sal_Bool OSelectionBrowseBox::SaveModified() sal_uInt16 nPos = m_pFieldCell->GetEntryPos(aFieldName); String aAliasName = pEntry->GetAlias(); - if ( nPos != COMBOBOX_ENTRY_NOTFOUND && !aAliasName.Len() && aFieldName.GetTokenCount('.') > 1 ) + if ( nPos != COMBOBOX_ENTRY_NOTFOUND && !aAliasName.Len() && comphelper::string::getTokenCount(aFieldName, '.') > 1 ) { // special case, we have a table field so we must cut the table name String sTableAlias = aFieldName.GetToken(0,'.'); pEntry->SetAlias(sTableAlias); @@ -1051,7 +1052,7 @@ sal_Bool OSelectionBrowseBox::SaveModified() sal_uInt16 nPos = m_pFunctionCell->GetSelectEntryPos(); // Diese Funktionen stehen nur unter CORE zur Verf�gung String sFunctionName = m_pFunctionCell->GetEntry(nPos); - String sGroupFunctionName = m_aFunctionStrings.GetToken(m_aFunctionStrings.GetTokenCount()-1); + String sGroupFunctionName = m_aFunctionStrings.GetToken(comphelper::string::getTokenCount(m_aFunctionStrings, ';')-1); sal_Bool bGroupBy = sal_False; if ( sGroupFunctionName.Equals(sFunctionName) ) // check if the function name is GROUP { @@ -2229,7 +2230,7 @@ String OSelectionBrowseBox::GetCellText(long nRow, sal_uInt16 nColId) const case BROW_FUNCTION_ROW: // we always show the group function at first if ( pEntry->IsGroupBy() ) - aText = m_aFunctionStrings.GetToken(m_aFunctionStrings.GetTokenCount()-1); + aText = m_aFunctionStrings.GetToken(comphelper::string::getTokenCount(m_aFunctionStrings, ';')-1); else if ( pEntry->isNumericOrAggreateFunction() ) aText = pEntry->GetFunction(); break; @@ -2293,7 +2294,7 @@ sal_Bool OSelectionBrowseBox::GetFunctionName(sal_uInt32 _nFunctionTokenId,Strin break; default: { - xub_StrLen nCount = m_aFunctionStrings.GetTokenCount(); + xub_StrLen nCount = comphelper::string::getTokenCount(m_aFunctionStrings, ';'); xub_StrLen i; for ( i = 0; i < nCount-1; i++) // Gruppierung wird nicht mit gez"ahlt { @@ -2372,7 +2373,7 @@ void OSelectionBrowseBox::SetCellContents(sal_Int32 nRow, sal_uInt16 nColId, con case BROW_FUNCTION_ROW: { String sOldFunctionName = pEntry->GetFunction(); - String sGroupFunctionName = m_aFunctionStrings.GetToken(m_aFunctionStrings.GetTokenCount()-1); + String sGroupFunctionName = m_aFunctionStrings.GetToken(comphelper::string::getTokenCount(m_aFunctionStrings, ';')-1); pEntry->SetFunction(strNewText); // first reset this two member sal_Int32 nFunctionType = pEntry->GetFunctionType(); @@ -2745,7 +2746,7 @@ void OSelectionBrowseBox::setFunctionCell(OTableFieldDescRef& _pEntry) m_pFunctionCell->InsertEntry(m_aFunctionStrings.GetToken(2)); // 2 -> COUNT else { - xub_StrLen nCount = m_aFunctionStrings.GetTokenCount(); + xub_StrLen nCount = comphelper::string::getTokenCount(m_aFunctionStrings, ';'); if ( _pEntry->isNumeric() ) --nCount; for (xub_StrLen nIdx = 1; nIdx < nCount; nIdx++) |