From 32b2e810ad2a6084d8a0e027aea414b65e2e8c4f Mon Sep 17 00:00:00 2001
From: Caolán McNamara <caolanm@redhat.com>
Date: Sat, 17 Sep 2011 00:15:49 +0100
Subject: use read_uInt8s_AsOString and comphelper::string::padToLength

which allows us to simplify the read in DTable.cxx quite a bit
---
 basic/source/runtime/iosys.cxx               |  9 ++-----
 connectivity/source/drivers/dbase/DTable.cxx | 37 +++++++++++-----------------
 2 files changed, 16 insertions(+), 30 deletions(-)

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