summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-08-07 09:13:47 +0100
committerCaolán McNamara <caolanm@redhat.com>2012-08-07 16:14:45 +0100
commitaac04652fda01b0299e17087b151f07d6115e894 (patch)
tree26a71ba651eb138d81f538b0d43b66f8da8e305d /tools
parentdb95e0b75903a34a1b88a3701334e154f32eeceb (diff)
String::AllocBuffer replacements
Change-Id: I278cd66fb4819721bb473796c28598aaf04eb123
Diffstat (limited to 'tools')
-rw-r--r--tools/inc/tools/stream.hxx7
-rw-r--r--tools/source/stream/stream.cxx55
2 files changed, 7 insertions, 55 deletions
diff --git a/tools/inc/tools/stream.hxx b/tools/inc/tools/stream.hxx
index a955e7d081f0..a72f2037fe3f 100644
--- a/tools/inc/tools/stream.hxx
+++ b/tools/inc/tools/stream.hxx
@@ -576,12 +576,11 @@ namespace streamdetail
template<typename prefix, typename S, sal_Size (*writeOper)(SvStream&, const S&, sal_Size)>
sal_Size write_lenPrefixed_seq_From_str(SvStream& rStrm, const S &rStr)
{
- SAL_WARN_IF(rStr.getLength() > std::numeric_limits<prefix>::max(),
- "tools.stream",
- "string too long for prefix count to fit in output type");
-
sal_Size nWritten = 0;
prefix nUnits = std::min<sal_Size>(rStr.getLength(), std::numeric_limits<prefix>::max());
+ SAL_WARN_IF(static_cast<sal_Size>(nUnits) != static_cast<sal_Size>(rStr.getLength()),
+ "tools.stream",
+ "string too long for prefix count to fit in output type");
rStrm << nUnits;
if (rStrm.good())
{
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index b188cabdc0af..0f3e9b53b139 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -1399,32 +1399,7 @@ rtl::OUString SvStream::ReadUniOrByteString( rtl_TextEncoding eSrcCharSet )
{
// read UTF-16 string directly from stream ?
if (eSrcCharSet == RTL_TEXTENCODING_UNICODE)
- {
- String aStr;
- sal_uInt32 nLen(0);
- operator>> (nLen);
- if (nLen)
- {
- if (nLen > STRING_MAXLEN)
- {
- SetError(SVSTREAM_GENERALERROR);
- return aStr;
- }
- sal_Unicode *pStr = aStr.AllocBuffer(
- static_cast< xub_StrLen >(nLen));
- BOOST_STATIC_ASSERT(STRING_MAXLEN <= SAL_MAX_SIZE / 2);
- Read( pStr, nLen << 1 );
-
- if (bSwap)
- {
- for (sal_Unicode *pEnd = pStr + nLen; pStr < pEnd; pStr++)
- SwapUShort(*pStr);
- }
- }
-
- return aStr;
- }
-
+ return read_lenPrefixed_uInt16s_ToOUString<sal_uInt32>(*this);
return read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(*this, eSrcCharSet);
}
@@ -1434,31 +1409,9 @@ SvStream& SvStream::WriteUniOrByteString( const rtl::OUString& rStr, rtl_TextEnc
{
// write UTF-16 string directly into stream ?
if (eDestCharSet == RTL_TEXTENCODING_UNICODE)
- {
- sal_Int32 nLen = rStr.getLength();
- operator<< (nLen);
- if (nLen)
- {
- if (bSwap)
- {
- const sal_Unicode *pStr = rStr.getStr();
- const sal_Unicode *pEnd = pStr + nLen;
-
- for (; pStr < pEnd; pStr++)
- {
- sal_Unicode c = *pStr;
- SwapUShort(c);
- WRITENUMBER_WITHOUT_SWAP(sal_uInt16,c)
- }
- }
- else
- Write( rStr.getStr(), nLen << 1 );
- }
-
- return *this;
- }
-
- write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(*this, rStr, eDestCharSet);
+ write_lenPrefixed_uInt16s_FromOUString<sal_uInt32>(*this, rStr);
+ else
+ write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(*this, rStr, eDestCharSet);
return *this;
}