summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-01-16 15:05:25 +0000
committerCaolán McNamara <caolanm@redhat.com>2012-01-16 15:40:53 +0000
commit94a8737a54c9e2c320e0be0286a5ecc0d354b8cc (patch)
tree6500174f26d289dac6f30d60a9b73ac03ddf679c /tools
parente770d5300054d56545bba3c16635a14e92fde807 (diff)
drop strange embedded null handling behaviour
Diffstat (limited to 'tools')
-rw-r--r--tools/qa/cppunit/test_stream.cxx10
-rw-r--r--tools/source/stream/stream.cxx24
2 files changed, 13 insertions, 21 deletions
diff --git a/tools/qa/cppunit/test_stream.cxx b/tools/qa/cppunit/test_stream.cxx
index 107d1c1047c4..16293d0eafad 100644
--- a/tools/qa/cppunit/test_stream.cxx
+++ b/tools/qa/cppunit/test_stream.cxx
@@ -264,16 +264,14 @@ namespace
aMemStream.Seek(0);
bRet = aMemStream.ReadLine(aFoo);
CPPUNIT_ASSERT(bRet);
- //This is the weird current behavior where an embedded null is read but
- //discarded
- CPPUNIT_ASSERT(aFoo.equalsL(RTL_CONSTASCII_STRINGPARAM("foobar"))); //<--diff A
+ CPPUNIT_ASSERT(aFoo.getLength() == 7 && aFoo[3] == 0);
CPPUNIT_ASSERT(aMemStream.good());
std::string sStr(RTL_CONSTASCII_STRINGPARAM(foo));
std::istringstream iss(sStr, std::istringstream::in);
std::getline(iss, sStr, '\n');
//embedded null read as expected
- CPPUNIT_ASSERT(sStr.size() == 7 && sStr[3] == 0); //<--diff A
+ CPPUNIT_ASSERT(sStr.size() == 7 && sStr[3] == 0);
CPPUNIT_ASSERT(iss.good());
bRet = aMemStream.ReadLine(aFoo);
@@ -299,12 +297,12 @@ namespace
bRet = aMemStreamB.ReadLine(aFoo);
CPPUNIT_ASSERT(bRet);
CPPUNIT_ASSERT(aFoo.equalsL(RTL_CONSTASCII_STRINGPARAM("foo")));
- CPPUNIT_ASSERT(!aMemStreamB.eof()); //<-- diff B
+ CPPUNIT_ASSERT(!aMemStreamB.eof()); //<-- diff A
std::istringstream issB(bar, std::istringstream::in);
std::getline(issB, sStr, '\n');
CPPUNIT_ASSERT(sStr == "foo");
- CPPUNIT_ASSERT(issB.eof()); //<-- diff B
+ CPPUNIT_ASSERT(issB.eof()); //<-- diff A
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index 08559ad1c874..7a9bf0df18a3 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -643,7 +643,7 @@ sal_Bool SvStream::ReadLine( ByteString& rStr )
sal_Char c = 0;
sal_Size nTotalLen = 0;
- rStr.Erase();
+ rtl::OStringBuffer aBuf;
while( !bEnd && !GetError() ) // !!! nicht auf EOF testen,
// !!! weil wir blockweise
// !!! lesen
@@ -651,10 +651,11 @@ sal_Bool SvStream::ReadLine( ByteString& rStr )
sal_uInt16 nLen = (sal_uInt16)Read( buf, sizeof(buf)-1 );
if ( !nLen )
{
- if ( rStr.Len() == 0 )
+ if ( aBuf.getLength() == 0 )
{
// der allererste Blockread hat fehlgeschlagen -> Abflug
bIsEof = sal_True;
+ rStr = rtl::OString();
return sal_False;
}
else
@@ -670,23 +671,15 @@ sal_Bool SvStream::ReadLine( ByteString& rStr )
bEnd = sal_True;
break;
}
- // erAck 26.02.01: Old behavior was no special treatment of '\0'
- // character here, but a following rStr+=c did ignore it. Is this
- // really intended? Or should a '\0' better terminate a line?
- // The nOldFilePos stuff wasn't correct then anyways.
- if ( c )
- {
- if ( n < j )
- buf[n] = c;
- ++n;
- }
+ if ( n < j )
+ buf[n] = c;
+ ++n;
}
- if ( n )
- rStr.Append( buf, n );
+ aBuf.append(buf, n);
nTotalLen += j;
}
- if ( !bEnd && !GetError() && rStr.Len() )
+ if ( !bEnd && !GetError() && aBuf.getLength() )
bEnd = sal_True;
nOldFilePos += nTotalLen;
@@ -706,6 +699,7 @@ sal_Bool SvStream::ReadLine( ByteString& rStr )
if ( bEnd )
bIsEof = sal_False;
+ rStr = aBuf.makeStringAndClear();
return bEnd;
}