Kaydet (Commit) 32b2e810 authored tarafından Caolán McNamara's avatar Caolán McNamara

use read_uInt8s_AsOString and comphelper::string::padToLength

which allows us to simplify the read in DTable.cxx quite a bit
üst 76092149
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <comphelper/string.hxx>
#include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp>
...@@ -659,14 +660,8 @@ SbError SbiStream::Read( ByteString& rBuf, sal_uInt16 n, bool bForceReadingPerBy ...@@ -659,14 +660,8 @@ SbError SbiStream::Read( ByteString& rBuf, sal_uInt16 n, bool bForceReadingPerBy
return nError = SbERR_BAD_RECORD_LENGTH; return nError = SbERR_BAD_RECORD_LENGTH;
rtl::OStringBuffer aBuffer(read_uInt8s_AsOString(*pStrm, n)); rtl::OStringBuffer aBuffer(read_uInt8s_AsOString(*pStrm, n));
//Pad it out with ' ' to the requested length on short read //Pad it out with ' ' to the requested length on short read
sal_Int32 nRead = aBuffer.getLength();
sal_Int32 nRequested = sal::static_int_cast<sal_Int32>(n); sal_Int32 nRequested = sal::static_int_cast<sal_Int32>(n);
if (nRead < nRequested) comphelper::string::padToLength(aBuffer, nRequested, ' ');
{
aBuffer.setLength(nRequested);
for (sal_Int32 i = nRead; i < nRequested; ++i)
aBuffer.setCharAt(i, ' ');
}
rBuf = aBuffer.makeStringAndClear(); rBuf = aBuffer.makeStringAndClear();
} }
MapError(); MapError();
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include <connectivity/dbconversion.hxx> #include <connectivity/dbconversion.hxx>
#include <com/sun/star/lang/DisposedException.hpp> #include <com/sun/star/lang/DisposedException.hpp>
#include <comphelper/property.hxx> #include <comphelper/property.hxx>
#include <comphelper/string.hxx>
#include <unotools/tempfile.hxx> #include <unotools/tempfile.hxx>
#include <unotools/ucbhelper.hxx> #include <unotools/ucbhelper.hxx>
#include <comphelper/types.hxx> #include <comphelper/types.hxx>
...@@ -61,6 +62,7 @@ ...@@ -61,6 +62,7 @@
#include "connectivity/dbconversion.hxx" #include "connectivity/dbconversion.hxx"
#include "resource/dbase_res.hrc" #include "resource/dbase_res.hrc"
#include <rtl/logfile.hxx> #include <rtl/logfile.hxx>
#include <rtl/strbuf.hxx>
#include <algorithm> #include <algorithm>
...@@ -1951,12 +1953,14 @@ sal_Bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, OValueRefRow pOrgRow,c ...@@ -1951,12 +1953,14 @@ sal_Bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, OValueRefRow pOrgRow,c
if (!m_pMemoStream || !WriteMemo(rRow.get()[nPos]->get(), nBlockNo)) if (!m_pMemoStream || !WriteMemo(rRow.get()[nPos]->get(), nBlockNo))
break; break;
ByteString aStr; rtl::OString aBlock(rtl::OString::valueOf(static_cast<sal_Int32>(nBlockNo)));
ByteString aBlock(rtl::OString::valueOf(static_cast<sal_Int32>(nBlockNo))); //align aBlock at the right of a nLen sequence, fill to the left with '0'
aStr.Expand(static_cast<sal_uInt16>(nLen - aBlock.Len()), '0' ); rtl::OStringBuffer aStr;
aStr += aBlock; comphelper::string::padToLength(aStr, nLen - aBlock.getLength(), '0');
aStr.append(aBlock);
// Copy characters: // Copy characters:
memcpy(pData, aStr.GetBuffer(), nLen); memcpy(pData, aStr.getStr(), nLen);
} break; } break;
default: default:
{ {
...@@ -2726,24 +2730,11 @@ sal_Bool ODbaseTable::ReadMemo(sal_uIntPtr nBlockNo, ORowSetValue& aVariable) ...@@ -2726,24 +2730,11 @@ sal_Bool ODbaseTable::ReadMemo(sal_uIntPtr nBlockNo, ORowSetValue& aVariable)
{ {
if ( bIsText ) if ( bIsText )
{ {
::rtl::OUStringBuffer aStr; rtl::OStringBuffer aBuffer(read_uInt8s_AsOString(*m_pMemoStream, nLength));
while ( nLength > STRING_MAXLEN ) //pad it out with ' ' to expected length on short read
{ sal_Int32 nRequested = sal::static_int_cast<sal_Int32>(nLength);
ByteString aBStr; comphelper::string::padToLength(aBuffer, nRequested, ' ');
aBStr.Expand(STRING_MAXLEN); aVariable = rtl::OStringToOUString(aBuffer.makeStringAndClear(), m_eEncoding);
m_pMemoStream->Read(aBStr.AllocBuffer(STRING_MAXLEN),STRING_MAXLEN);
aStr.append(::rtl::OUString(aBStr.GetBuffer(),aBStr.Len(), m_eEncoding));
nLength -= STRING_MAXLEN;
}
if ( nLength > 0 )
{
ByteString aBStr;
aBStr.Expand(static_cast<xub_StrLen>(nLength));
m_pMemoStream->Read(aBStr.AllocBuffer(static_cast<xub_StrLen>(nLength)),nLength);
aStr.append(::rtl::OUString(aBStr.GetBuffer(),aBStr.Len(), m_eEncoding));
}
if ( aStr.getLength() )
aVariable = aStr.makeStringAndClear();
} // if ( bIsText ) } // if ( bIsText )
else else
{ {
......
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