diff options
author | Norbert Thiebaud <nthiebaud@gmail.com> | 2013-06-29 23:57:38 -0500 |
---|---|---|
committer | Norbert Thiebaud <nthiebaud@gmail.com> | 2013-06-30 04:58:49 +0000 |
commit | 710f41b7aec8e7d35a0da8be332aa289f98942af (patch) | |
tree | b894ef2d3f06a63a85f423b2713a654ea57f9c69 /connectivity | |
parent | 1ca3beae12a7f222c987481e07a544845fc9fd46 (diff) |
Clean String and sal_Bool in tools
Change-Id: I6a92196f33d7a5278c7dcc426112e9c56d582655
Reviewed-on: https://gerrit.libreoffice.org/4627
Reviewed-by: Norbert Thiebaud <nthiebaud@gmail.com>
Tested-by: Norbert Thiebaud <nthiebaud@gmail.com>
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/source/drivers/file/quotedstring.cxx | 59 | ||||
-rw-r--r-- | connectivity/source/drivers/flat/ETable.cxx | 27 | ||||
-rw-r--r-- | connectivity/source/inc/file/quotedstring.hxx | 15 | ||||
-rw-r--r-- | connectivity/source/inc/flat/ETable.hxx | 6 |
4 files changed, 55 insertions, 52 deletions
diff --git a/connectivity/source/drivers/file/quotedstring.cxx b/connectivity/source/drivers/file/quotedstring.cxx index 316ad2fdc0e7..f69230dce008 100644 --- a/connectivity/source/drivers/file/quotedstring.cxx +++ b/connectivity/source/drivers/file/quotedstring.cxx @@ -18,6 +18,7 @@ */ #include "file/quotedstring.hxx" +#include <rtl/ustrbuf.hxx> namespace connectivity { @@ -25,28 +26,28 @@ namespace connectivity //= QuotedTokenizedString //================================================================== //------------------------------------------------------------------ - xub_StrLen QuotedTokenizedString::GetTokenCount( sal_Unicode cTok, sal_Unicode cStrDel ) const + sal_Int32 QuotedTokenizedString::GetTokenCount( sal_Unicode cTok, sal_Unicode cStrDel ) const { SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com QuotedTokenizedString::GetTokenCount" ); - const xub_StrLen nLen = m_sString.Len(); + const sal_Int32 nLen = m_sString.getLength(); if ( !nLen ) return 0; - xub_StrLen nTokCount = 1; - sal_Bool bStart = sal_True; // Are we on the first character in the Token? - sal_Bool bInString = sal_False; // Are we WITHIN a (cStrDel delimited) String? + sal_Int32 nTokCount = 1; + bool bStart = true; // Are we on the first character in the Token? + bool bInString = false; // Are we WITHIN a (cStrDel delimited) String? // Search for String-end after the first not matching character - for( xub_StrLen i = 0; i < nLen; ++i ) + for( sal_Int32 i = 0; i < nLen; ++i ) { - const sal_Unicode cChar = m_sString.GetChar(i); + const sal_Unicode cChar = m_sString[i]; if (bStart) { - bStart = sal_False; + bStart = false; // First character a String-Delimiter? if ( cChar == cStrDel ) { - bInString = sal_True; // then we are now WITHIN the string! + bInString = true; // then we are now WITHIN the string! continue; // skip this character! } } @@ -56,7 +57,7 @@ namespace connectivity // when now the String-Delimiter-character occurs ... if ( cChar == cStrDel ) { - if ((i+1 < nLen) && (m_sString.GetChar(i+1) == cStrDel)) + if ((i+1 < nLen) && (m_sString[i+1] == cStrDel)) { // double String-Delimter-character: ++i; // no string-end, skip next character. @@ -64,7 +65,7 @@ namespace connectivity else { // String-End - bInString = sal_False; + bInString = false; } } } // if (bInString) @@ -74,7 +75,7 @@ namespace connectivity if ( cChar == cTok ) { ++nTokCount; - bStart = sal_True; + bStart = true; } } } @@ -84,51 +85,48 @@ namespace connectivity } //------------------------------------------------------------------ - String QuotedTokenizedString::GetTokenSpecial(xub_StrLen& nStartPos, sal_Unicode cTok, sal_Unicode cStrDel) const + OUString QuotedTokenizedString::GetTokenSpecial(sal_Int32& nStartPos, sal_Unicode cTok, sal_Unicode cStrDel) const { SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com QuotedTokenizedString::GetTokenCount" ); - String aStr; - const xub_StrLen nLen = m_sString.Len(); + const sal_Int32 nLen = m_sString.getLength(); if ( nLen ) { - sal_Bool bInString = (nStartPos < nLen) && (m_sString.GetChar(nStartPos) == cStrDel); // are we WITHIN a (cStrDel delimited) String? + bool bInString = (nStartPos < nLen) && (m_sString[nStartPos] == cStrDel); // are we WITHIN a (cStrDel delimited) String? // First character a String-Delimiter? if (bInString ) ++nStartPos; // skip this character! if ( nStartPos >= nLen ) - return aStr; + return OUString(); + + OUStringBuffer sBuff( nLen - nStartPos + 1 ); - sal_Unicode* pData = aStr.AllocBuffer( nLen - nStartPos + 1 ); - const sal_Unicode* pStart = pData; // Search until end of string for the first not matching character - for( xub_StrLen i = nStartPos; i < nLen; ++i ) + for( sal_Int32 i = nStartPos; i < nLen; ++i ) { - const sal_Unicode cChar = m_sString.GetChar(i); + const sal_Unicode cChar = m_sString[i]; if (bInString) { // when now the String-Delimiter-character occurs ... if ( cChar == cStrDel ) { - if ((i+1 < nLen) && (m_sString.GetChar(i+1) == cStrDel)) + if ((i+1 < nLen) && (m_sString[i+1] == cStrDel)) { // double String Delimiter-character // no end of string, skip next character. ++i; - *pData++ = m_sString.GetChar(i); // character belongs to Result-String + sBuff.append(m_sString[i]); // character belongs to Result-String } else { //end of String - bInString = sal_False; - *pData = 0; + bInString = false; } } else { - *pData++ = cChar; // character belongs to Result-String + sBuff.append(cChar); } - } else { @@ -141,14 +139,13 @@ namespace connectivity } else { - *pData++ = cChar; // character belongs to Result-String + sBuff.append(cChar); } } } // for( xub_StrLen i = nStartPos; i < nLen; ++i ) - *pData = 0; - aStr.ReleaseBufferAccess(xub_StrLen(pData - pStart)); + return sBuff.makeStringAndClear(); } - return aStr; + return OUString(); } } diff --git a/connectivity/source/drivers/flat/ETable.cxx b/connectivity/source/drivers/flat/ETable.cxx index b2788e6107c1..8f4e2c365e6d 100644 --- a/connectivity/source/drivers/flat/ETable.cxx +++ b/connectivity/source/drivers/flat/ETable.cxx @@ -137,9 +137,9 @@ void OFlatTable::fillColumns(const ::com::sun::star::lang::Locale& _aLocale) do { - xub_StrLen nStartPosHeaderLine = 0; // use for efficient way to get the tokens - xub_StrLen nStartPosFirstLine = 0; // use for efficient way to get the tokens - xub_StrLen nStartPosFirstLine2 = 0; + sal_Int32 nStartPosHeaderLine = 0; // use for efficient way to get the tokens + sal_Int32 nStartPosFirstLine = 0; // use for efficient way to get the tokens + sal_Int32 nStartPosFirstLine2 = 0; for (xub_StrLen i = 0; i < nFieldCount; i++) { if ( nRowCount == 0) @@ -160,7 +160,11 @@ void OFlatTable::fillColumns(const ::com::sun::star::lang::Locale& _aLocale) aColumnNames.push_back(aColumnName); } if(bRead) - impl_fillColumnInfo_nothrow(m_aCurrentLine,nStartPosFirstLine,nStartPosFirstLine2,m_aTypes[i],m_aPrecisions[i],m_aScales[i],m_aTypeNames[i],cDecimalDelimiter,cThousandDelimiter,aCharClass); + { + impl_fillColumnInfo_nothrow(m_aCurrentLine, nStartPosFirstLine, nStartPosFirstLine2, + m_aTypes[i], m_aPrecisions[i], m_aScales[i], m_aTypeNames[i], + cDecimalDelimiter, cThousandDelimiter, aCharClass); + } } ++nRowCount; bRead = readLine(&rowPos.second, &rowPos.first, false); @@ -197,9 +201,10 @@ void OFlatTable::fillColumns(const ::com::sun::star::lang::Locale& _aLocale) m_pFileStream->Seek(m_aRowPosToFilePos[0].second); } -void OFlatTable::impl_fillColumnInfo_nothrow(QuotedTokenizedString& aFirstLine,xub_StrLen& nStartPosFirstLine,xub_StrLen& nStartPosFirstLine2 - ,sal_Int32& io_nType,sal_Int32& io_nPrecisions,sal_Int32& io_nScales,String& o_sTypeName - ,const sal_Unicode cDecimalDelimiter,const sal_Unicode cThousandDelimiter,const CharClass& aCharClass) + +void OFlatTable::impl_fillColumnInfo_nothrow(QuotedTokenizedString& aFirstLine, sal_Int32& nStartPosFirstLine, sal_Int32& nStartPosFirstLine2, + sal_Int32& io_nType, sal_Int32& io_nPrecisions, sal_Int32& io_nScales, String& o_sTypeName, + const sal_Unicode cDecimalDelimiter, const sal_Unicode cThousandDelimiter, const CharClass& aCharClass) { if ( io_nType != DataType::VARCHAR ) { @@ -630,7 +635,7 @@ sal_Bool OFlatTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, s const sal_Unicode cDecimalDelimiter = pConnection->getDecimalDelimiter(); const sal_Unicode cThousandDelimiter = pConnection->getThousandDelimiter(); // Fields: - xub_StrLen nStartPos = 0; + sal_Int32 nStartPos = 0; OSQLColumns::Vector::const_iterator aIter = _rCols.get().begin(); OSQLColumns::Vector::const_iterator aEnd = _rCols.get().end(); const OValueRefVector::Vector::size_type nCount = _rRow->get().size(); @@ -935,7 +940,7 @@ bool OFlatTable::readLine(sal_Int32 * const pEndPos, sal_Int32 * const pStartPos { if (pStartPos) *pStartPos = m_pFileStream->Tell(); - m_pFileStream->ReadByteStringLine(m_aCurrentLine,nEncoding); + m_pFileStream->ReadByteStringLine(m_aCurrentLine, nEncoding); if (m_pFileStream->IsEof()) return false; @@ -945,8 +950,8 @@ bool OFlatTable::readLine(sal_Int32 * const pEndPos, sal_Int32 * const pStartPos m_pFileStream->ReadByteStringLine(sLine,nEncoding); if ( !m_pFileStream->IsEof() ) { - m_aCurrentLine.GetString().Append('\n'); - m_aCurrentLine.GetString() += sLine.GetString(); + OUString aStr = m_aCurrentLine.GetString() + "\n" + sLine.GetString(); + m_aCurrentLine.SetString(aStr); sLine = m_aCurrentLine; } else diff --git a/connectivity/source/inc/file/quotedstring.hxx b/connectivity/source/inc/file/quotedstring.hxx index b7b13d7d8bcc..6c39e7cdda9b 100644 --- a/connectivity/source/inc/file/quotedstring.hxx +++ b/connectivity/source/inc/file/quotedstring.hxx @@ -31,16 +31,17 @@ namespace connectivity //================================================================== class OOO_DLLPUBLIC_FILE QuotedTokenizedString { - String m_sString; + OUString m_sString; public: QuotedTokenizedString() {} - QuotedTokenizedString(const String& _sString) : m_sString(_sString){} + QuotedTokenizedString(const OUString& _sString) : m_sString(_sString){} - xub_StrLen GetTokenCount( sal_Unicode cTok , sal_Unicode cStrDel ) const; - String GetTokenSpecial(xub_StrLen& nStartPos, sal_Unicode cTok = ';', sal_Unicode cStrDel = '\0') const; - inline String& GetString() { return m_sString; } - inline xub_StrLen Len() const { return m_sString.Len(); } - inline operator String&() { return m_sString; } + sal_Int32 GetTokenCount( sal_Unicode cTok , sal_Unicode cStrDel ) const; + OUString GetTokenSpecial(sal_Int32& nStartPos, sal_Unicode cTok = ';', sal_Unicode cStrDel = '\0') const; + inline OUString& GetString() { return m_sString; } + inline void SetString(OUString aStr) { m_sString = aStr;} + inline sal_Int32 Len() const { return m_sString.getLength(); } + inline operator OUString&() { return m_sString; } }; } diff --git a/connectivity/source/inc/flat/ETable.hxx b/connectivity/source/inc/flat/ETable.hxx index c5b3608597e2..f283647d909c 100644 --- a/connectivity/source/inc/flat/ETable.hxx +++ b/connectivity/source/inc/flat/ETable.hxx @@ -60,9 +60,9 @@ namespace connectivity sal_Bool CreateFile(const INetURLObject& aFile, sal_Bool& bCreateMemo); bool readLine(sal_Int32 *pEndPos = NULL, sal_Int32 *pStartPos = NULL, bool nonEmpty = false); void setRowPos(::std::vector<TRowPositionInFile>::size_type rowNum, const TRowPositionInFile &rowPos); - void impl_fillColumnInfo_nothrow(QuotedTokenizedString& aFirstLine,xub_StrLen& nStartPosFirstLine,xub_StrLen& nStartPosFirstLine2 - ,sal_Int32& io_nType,sal_Int32& io_nPrecisions,sal_Int32& io_nScales,String& o_sTypeName - ,const sal_Unicode cDecimalDelimiter,const sal_Unicode cThousandDelimiter,const CharClass& aCharClass); + void impl_fillColumnInfo_nothrow(QuotedTokenizedString& aFirstLine, sal_Int32& nStartPosFirstLine, sal_Int32& nStartPosFirstLine2, + sal_Int32& io_nType, sal_Int32& io_nPrecisions, sal_Int32& io_nScales, String& o_sTypeName, + const sal_Unicode cDecimalDelimiter, const sal_Unicode cThousandDelimiter, const CharClass& aCharClass); OFlatConnection* getFlatConnection() { #if OSL_DEBUG_LEVEL>1 |