Kaydet (Commit) 2c1c0168 authored tarafından Matteo Casalin's avatar Matteo Casalin

Avoid getTokenCount()

Change-Id: Idb1eff48c33a8bd9c5119c1caa6ee01202d1d374
üst 41bcf613
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include <scresid.hxx> #include <scresid.hxx>
#include <strings.hrc> #include <strings.hrc>
#include <strings.hxx> #include <strings.hxx>
#include <comphelper/string.hxx>
#include <officecfg/Office/Calc.hxx> #include <officecfg/Office/Calc.hxx>
#include <osl/thread.h> #include <osl/thread.h>
#include <rtl/tencinfo.h> #include <rtl/tencinfo.h>
...@@ -36,65 +35,54 @@ class ScDelimiterTable ...@@ -36,65 +35,54 @@ class ScDelimiterTable
public: public:
explicit ScDelimiterTable( const OUString& rDelTab ) explicit ScDelimiterTable( const OUString& rDelTab )
: theDelTab ( rDelTab ), : theDelTab ( rDelTab ),
nCount ( comphelper::string::getTokenCount(rDelTab, '\t') ), nDelIdx ( 0 )
nIter ( 0 )
{} {}
sal_uInt16 GetCode( const OUString& rDelimiter ) const; sal_uInt16 GetCode( const OUString& rDelimiter ) const;
OUString GetDelimiter( sal_Unicode nCode ) const; OUString GetDelimiter( sal_Unicode nCode ) const;
OUString FirstDel() { nIter = 0; return theDelTab.getToken( nIter, cSep ); } OUString FirstDel() { nDelIdx = 0; return theDelTab.getToken( 0, cSep, nDelIdx ); }
OUString NextDel() { nIter +=2; return theDelTab.getToken( nIter, cSep ); } OUString NextDel() { return theDelTab.getToken( 1, cSep, nDelIdx ); }
private: private:
const OUString theDelTab; const OUString theDelTab;
static const sal_Unicode cSep = '\t'; static constexpr sal_Unicode cSep {'\t'};
const sal_Int32 nCount; sal_Int32 nDelIdx;
sal_Int32 nIter;
}; };
sal_uInt16 ScDelimiterTable::GetCode( const OUString& rDel ) const sal_uInt16 ScDelimiterTable::GetCode( const OUString& rDel ) const
{ {
sal_Unicode nCode = 0; if (!theDelTab.isEmpty())
if ( nCount >= 2 )
{ {
sal_Int32 i = 0; sal_Int32 nIdx {0};
while ( i<nCount )
{ // Check even tokens: start from 0 and then skip 1 token at each iteration
if ( rDel == theDelTab.getToken( i, cSep ) ) if (rDel != theDelTab.getToken( 0, cSep, nIdx ))
{ while (nIdx>0 && rDel != theDelTab.getToken( 1, cSep, nIdx ));
nCode = static_cast<sal_Unicode>(theDelTab.getToken( i+1, cSep ).toInt32());
i = nCount; if (nIdx>0)
} return static_cast<sal_Unicode>(theDelTab.getToken( 0, cSep, nIdx ).toInt32());
else
i += 2;
}
} }
return nCode; return 0;
} }
OUString ScDelimiterTable::GetDelimiter( sal_Unicode nCode ) const OUString ScDelimiterTable::GetDelimiter( sal_Unicode nCode ) const
{ {
OUString aStrDel; if (!theDelTab.isEmpty())
if ( nCount >= 2 )
{ {
sal_Int32 i = 0; sal_Int32 nIdx {0};
while ( i<nCount ) // Check odd tokens: start from 1 and then skip 1 token at each iteration
do
{ {
if ( nCode == static_cast<sal_Unicode>(theDelTab.getToken( i+1, cSep ).toInt32()) ) sal_Int32 nPrevIdx {nIdx};
{ if (nCode == static_cast<sal_Unicode>(theDelTab.getToken( 1, cSep, nIdx ).toInt32()))
aStrDel = theDelTab.getToken( i, cSep ); return theDelTab.getToken( 0, cSep, nPrevIdx );
i = nCount;
}
else
i += 2;
} }
while (nIdx>0);
} }
return aStrDel; return OUString();
} }
// ScImportOptionsDlg // ScImportOptionsDlg
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment